Docs

    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 traceparent to the requests it traces through requests, httpx, httpx2 and aiohttp, on a copy of the headers you pass, never your own dict. TypeScript adds it to requests sent with node:http and https, fetch and axios inside 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 traceparent and 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-id and traceparent headers, 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)  # True

    This 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 with client.start_trace("consume", join_trace_id=trace_id).
    • Read the current trace id with evalkit.current_trace_id() in Python or evalkit.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")
    PythonTypeScript
    Your provider is found whenIt 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 receiveYour OpenTelemetry spans. The spans EvalKit records itself (model calls, framework middleware, HTTP clients) go to SyntropyLabs onlyEvery span, EvalKit's included, because EvalKit records on your provider
    Samplingsample_rate decides, from 0.3.6; on 0.3.5 and earlier every span is sentYour sampler decides, then sampleRate
    With no provider of yoursinit() installs one and registers the OpenTelemetry instrumentations installed in the environment, except those EvalKit replacesinit() 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.id and gen_ai.agent.name attributes 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=1 when 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 authenticates Authorization: Bearer <key> or X-Subscription-Key.
    • Logs go to /v1/otlp/v1/logs. Metrics are accepted at /v1/otlp/v1/metrics and dropped: every figure the app shows is computed from spans.
    • service.name names the service. session.id, conversation.id or gen_ai.conversation.id puts a span in a session, user.id names the user, and the gen_ai.* model and usage attributes give a model call its model and tokens.
    • The EvalKit SDKs mask secrets and apply capture_content and 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.

    EvalKit is built by SyntropyLabs. Published on PyPI and npm.