SDK reference
OpenTelemetry and distributed tracing
Follow one request across your services with W3C traceparent, run EvalKit beside an OpenTelemetry setup you already have, and send OTLP straight to the trace receiver.
A trace can span several services: each SDK sends the W3C traceparent header on the HTTP requests it makes and continues the trace a request arrives with. This page covers that, how EvalKit runs inside an OpenTelemetry setup you already have, and how to send OpenTelemetry spans to the receiver with no EvalKit SDK at all.
One trace across your services
- Outgoing: Python adds
traceparentto the requests it traces throughrequests,httpx,httpx2andaiohttp, on a copy of the headers you pass, never your own dict. TypeScript adds it to requests sent withnode:httpandhttps,fetchandaxiosinside a traced span. Neither changes anything else in the request. - Incoming: the Python framework middleware (FastAPI and Starlette, Flask, Django, Litestar) and the TypeScript server instrumentation read
traceparentand make the request span a child of the caller's span, in the caller's trace. - Every response a traced server sends carries
x-trace-idandtraceparentheaders, added on purpose, so a caller, or your support team, can find the trace of any request. - Each span keeps the service name of the process that recorded it, so the trace shows which service did what.
import os
import evalkit
evalkit.init(subscription_key=os.environ["EVALKIT_SUBSCRIPTION_KEY"], service_name="checkout")
import httpx # noqa: E402
trace_id, end, ctx = evalkit.start_trace("checkout") # the root of the whole chain
with evalkit.with_trace(ctx):
# The SDK adds traceparent, so the support service records its work in this trace.
reply = httpx.post("http://support-api:3000/chat", json={"message": "Where is my order?", "session_id": "conv_1"})
end()
print(reply.headers["x-trace-id"] == trace_id) # TrueThis chain was run with a Python caller and a TypeScript service, the Express tutorial. The callee needs nothing beyond its usual setup.
- A hop that is not HTTP, such as a queue or a message bus, does not carry the trace. In Python, the client
init()returns can join a trace on purpose: send the trace id with the message, then open the consumer's root span withclient.start_trace("consume", join_trace_id=trace_id). - Read the current trace id with
evalkit.current_trace_id()in Python orevalkit.currentTraceId()in TypeScript, for a log line or an error report.
Beside an OpenTelemetry setup you already have
If your process already runs the OpenTelemetry SDK, EvalKit does not replace it. Start your tracer provider first, then call init(): EvalKit adds one span processor to your provider, your exporters keep receiving your spans, and SyntropyLabs receives them as well.
import os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
provider = TracerProvider() # your provider, with your exporters and resource
trace.set_tracer_provider(provider)
import evalkit # noqa: E402
# Finds the provider above and adds EvalKit's processor to it.
evalkit.init(subscription_key=os.environ["EVALKIT_SUBSCRIPTION_KEY"], service_name="billing")| Python | TypeScript | |
|---|---|---|
| Your provider is found when | It is an opentelemetry-sdk TracerProvider set as the global provider before init() | It is registered before init(), or passed as tracerProvider; client.tracingMode is then "attached" |
| Your exporters receive | Your OpenTelemetry spans. The spans EvalKit records itself (model calls, framework middleware, HTTP clients) go to SyntropyLabs only | Every span, EvalKit's included, because EvalKit records on your provider |
| Sampling | sample_rate decides, from 0.3.6; on 0.3.5 and earlier every span is sent | Your sampler decides, then sampleRate |
| With no provider of yours | init() installs one and registers the OpenTelemetry instrumentations installed in the environment, except those EvalKit replaces | init() installs one, owned by EvalKit, and follows OTEL_TRACES_SAMPLER |
- Start your OpenTelemetry SDK before
init(). When EvalKit installed its provider first, OpenTelemetry refuses a second global provider, and the one registered later receives nothing. - Do not add an OTLP exporter pointed at SyntropyLabs to the same provider as well: each span would then arrive twice.
- Spans from other OpenTelemetry instrumentation keep their kind, events and token counts, and their
session.id,user.idandgen_ai.agent.nameattributes group them into sessions, users and agents. - An agent framework that records spans on the OpenTelemetry GenAI conventions, such as Strands, is typed by
gen_ai.operation.name: agents, tools and model calls. See Strands Agents. - A model-call span from another instrumentation is stored without its tokens, as a copy of a call EvalKit already records, so it is not counted twice. Set
EVALKIT_COUNT_FOREIGN_LLM=1when that instrumentation is the only one that sees the call.
OTLP straight to the receiver
Any OpenTelemetry exporter can send to SyntropyLabs without an EvalKit SDK, for a language EvalKit has no SDK for or a service you do not want to change. Point the OTLP/HTTP trace exporter at the path /v1/otlp/v1/traces of https://api.syntropylabs.ai, and authenticate with the environment key.
import os
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider(resource=Resource.create({"service.name": "billing-worker"}))
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(
endpoint="https://api.syntropylabs.ai/v1/otlp/v1/traces",
headers={"Authorization": f"Bearer {os.environ['EVALKIT_SUBSCRIPTION_KEY']}"},
)))
trace.set_tracer_provider(provider)- The receiver takes OTLP/JSON and protobuf, gzip-compressed or not, up to 8 MiB a request; a larger request is refused with
413. It authenticatesAuthorization: Bearer <key>orX-Subscription-Key. - Logs go to
/v1/otlp/v1/logs. Metrics are accepted at/v1/otlp/v1/metricsand dropped: every figure the app shows is computed from spans. service.namenames the service.session.id,conversation.idorgen_ai.conversation.idputs a span in a session,user.idnames the user, and thegen_ai.*model and usage attributes give a model call its model and tokens.- The EvalKit SDKs mask secrets and apply
capture_contentand mask hooks inside your process. Spans sent over OTLP arrive as your exporter sent them, so leave credentials and content you must not store out of their attributes.
Where the web and agent frameworks start their traces is in Supported frameworks. What each SDK records, and the switches that narrow it, are in Configuration and privacy.