Skip to main content
This recipe sends your agent’s spans to Kubit with the stock OpenTelemetry SDK and OTLP/HTTP exporter, in Python or Node, with no Kubit package. At the end, your app’s traces show in Agent > Activity. It takes about 15 minutes. Use it when you already run an OpenTelemetry pipeline, can’t add a dependency, or work in a language Kubit has no SDK for. The Kubit SDK for Python and Kubit SDK for Node do the same with less code, and filter out spans that aren’t LLM-related before they leave your process.

Before you start

  • A Kubit Agent workspace and its API key in KUBIT_API_KEY
  • For Python: Python 3.9 or later
  • For Node: Node.js 18 or later and OpenTelemetry JS SDK v2
Kubit authenticates spans with an ingestion API key, read from the KUBIT_API_KEY environment variable. Each key belongs to one workspace. The app shows a new key only once: This is the only time we'll show you this key. Copy it now. Copy it, or click Download for a .env file, then click I’ve Saved It. The downloaded file names the key KUBIT_OTEL_API_KEY, so rename it to KUBIT_API_KEY. Availability: API Keys shows only to the Owner and Admin roles, and only in Agent and User workspaces.
Keep the key out of source control. Put it in .env or your secrets manager, and check that .env is in .gitignore.

Prompt for your coding agent

Steps for Python

1

Install the SDK and exporter

Install the OpenTelemetry SDK and the OTLP/HTTP exporter:
2

Point the exporter at Kubit

Every exporter that sends to Kubit uses these settings:Set service.name, service.version and deployment.environment on the resource. Kubit maps service.version to Client: Version and deployment.environment to Client: Environment.Create kubit_tracing.py and import it first in your entrypoint, before any LLM client is created:
kubit_tracing.py
main.py
If your app already registers a TracerProvider, add a second BatchSpanProcessor with the Kubit exporter to it instead, after your app calls trace.set_tracer_provider(). Don’t create a second provider. OpenTelemetry keeps the first global provider and ignores the second.
tracing.py
Pass the endpoint and header in code, as above. The OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS environment variables apply to every OpenTelemetry exporter in the process. If another backend shares the process, setting them for Kubit sends that backend’s spans to Kubit too.
3

Trace LLM calls

Add the OpenTelemetry GenAI instrumentor for your LLM client, and turn on message content so Polaris has text to label:
Add these lines at the end of kubit_tracing.py, after trace.set_tracer_provider(provider):
kubit_tracing.py
4

Add user and session IDs

Set user.id and session.id on the root span of each request, so Kubit can group traces into sessions and join them to users:
handler.py
5

Send a test span

force_flush() sends the span before the process exits. Without it, the span can wait in the batch and be lost.

Steps for Node

1

Install the SDK and exporter

Install the OpenTelemetry JS SDK v2 packages and the OTLP/HTTP protobuf exporter:
2

Point the exporter at Kubit

Use the settings in Point the exporter at Kubit. Create kubit-tracing.ts and import it first in your entrypoint, before any LLM client is created:
kubit-tracing.ts
index.ts
If your app already creates a tracer provider or NodeSDK, add the Kubit processor to its spanProcessors list instead. OpenTelemetry JS SDK v2 takes span processors only when the provider is created.
instrumentation.ts
3

Add user and session IDs

Set user.id and session.id on the root span of each request:
handler.ts
4

Send a test span

send-test-span.ts

Verify

Open Agent > Activity in the Kubit app, set Time Range to Last 1 day and click Execute. The chat.completion trace from your test span is in the list. Validate in Activity shows what to check in the trace.

Check the Connection with curl

If the test span doesn’t show, send one span as OTLP/JSON with curl. It works from any machine, so it separates a key or network problem from a problem in your app:
The last line of the output is HTTP 200 when Kubit accepted the span. Run it again with a different traceId to send a second test trace.

If it fails

More checks are in Is my data flowing?.

Next Steps