> ## Documentation Index
> Fetch the complete documentation index at: https://docs.struct.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Instrument with Struct

> Connect your application through a Struct SDK or OpenTelemetry.

Capture the requests, dependencies, logs and AI calls that explain how your application behaves. Struct accepts OpenTelemetry traces, logs and metrics over HTTP.

## Choose the instrumentation path

Inspect the application's language, startup command and existing OpenTelemetry providers before adding instrumentation. Create or select the workspace through [Quickstart](https://docs.struct.ai/quickstart.md).

| Application | Guide | Coverage |
| - | - | - |
| Python 3.10+ | [Python SDK](https://docs.struct.ai/observability/instrumentation/python.md) | Full application instrumentation plus supported AI libraries |
| Node.js 18.19+ or 20.6+ | [TypeScript SDK](https://docs.struct.ai/observability/instrumentation/typescript.md) | Supported AI calls; add OpenTelemetry for other signals |
| Existing telemetry, another language or collector | [OpenTelemetry](https://docs.struct.ai/observability/instrumentation/opentelemetry.md) | The signals your SDK or collector emits |

## Create an ingest key

An ingest key starts with `pk-`. It sends telemetry, and it also reads the configuration Struct keeps for your services, so treat it as a secret: store it in your application's secret configuration; do not commit it, put it in frontend code or paste it into chat.

For a claimed workspace, an admin authorizes key management first:

```bash theme={null}
struct login --admin
struct whoami --json
```

If you created an active, activated workspace with `struct init --no-wait`, use its saved temporary login instead; you can create the ingest key before a person claims ownership. A member in an existing workspace can ask an admin for a key.

Create a key and capture its one-time value without printing it to the transcript:

```bash theme={null}
STRUCT_INGEST_KEY="$(struct keys ingest create --name checkout-api)"
```

Continue only if the command succeeds. Export `STRUCT_INGEST_KEY` for a local process, or save it in the secret manager referenced by your deployment template. Key lists return metadata, not the secret. Use one key per service so you can revoke it independently with `struct keys ingest revoke <id>`.

**Deployment reality:**

* Inspect deployment templates / IaC before editing a live service: manual changes to a running cloud app (such as Azure Container Apps or Kubernetes) get overwritten on the next deploy unless they are also saved in the template.
* Updating a secret or environment variable does not take effect until the service restarts or rolls out a new revision.
* Always set a clear `service_name` (`OTEL_SERVICE_NAME`) and `environment` (`deployment.environment.name`, e.g. `production` or `staging`; the Python SDK defaults to `development`).
* If you export to a custom ingest endpoint (`STRUCT_INGEST_URL` other than `https://ingest.struct.ai`), also set `STRUCT_API_URL` on the service process when using Observations.

## Verify instrumentation

Start the service with the configured environment and exercise a real request or operation. Allow for the SDK or collector to flush its batch, then run:

```bash theme={null}
struct telemetry services --since 1h --json
```

Find the expected `serviceName`. Each signal has a count and `lastSeenAt`, or is `null` when absent. Check the signals your setup emits; the Node SDK's AI spans alone do not prove that application logs or metrics arrive. The time window uses the records' timestamps, so check the service clock if recent activity is missing.

With CLI 5.0.0 or newer, inspect a small trace sample:

```bash theme={null}
struct telemetry query --json --document '{"kind": "query", "range": {"last": "1h"}, "result": "raw", "queries": [{"name": "spans", "signal": "traces", "filter": "service.name = '"'"'checkout-api'"'"'", "select": ["timestamp", "span.name", "trace_id", "span_id"], "limit": 10}]}'
```

Replace `checkout-api` with your service name. This verifies traces only; use the service summary for logs and metrics. `202` from ingest means the batch was accepted, while observing the records confirms they can be queried. Once base telemetry is visible, add targeted [Observations](https://docs.struct.ai/observability/observations/overview.md) for Python services and [create telemetry monitors](https://docs.struct.ai/observability/monitors/create.md).

An unclaimed workspace that pauses retains configuration and firing history, but queries, previews and setup changes wait for [ownership claim](https://docs.struct.ai/reference/cli-auth.md#claim-and-resume).

## If data does not arrive

Failed-export logs show the status code Struct answered with. The Python SDK keeps them quiet by default: enable DEBUG logging for the `struct_sdk` logger, with a handler attached, to see them. The Node SDK sets no OpenTelemetry diagnostic logger, so export errors are silent unless your app sets one, for example `diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR)` from `@opentelemetry/api`.

| Status | Meaning | Fix |
| - | - | - |
| `202` | Batch accepted | Verify the expected service and signals with `struct telemetry services` |
| `401` | The ingest key is missing, wrong, revoked, or expired | Check `STRUCT_INGEST_KEY` and the header name `x-struct-ingest-key` |
| `413` | The batch is over 2 MiB | Send smaller batches |
| `415` | The content type is not protobuf or JSON | Use `http/protobuf` or `http/json` |
| `502` or `503` | Struct could not take the batch right now | Exporters retry this on their own |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.