OpenTelemetry tracing for AI applications: tracer setup, span helpers, exporters, and semantic conventions for Future AGI.
pip install fi-instrumentation-otel==1.2.3 Copy PIP instructions
OpenTelemetry instrumentation for AI applications. Install the core and the instrumentor for the framework you use.
All languages · Integration guides · Core API and configuration
Core tracing supports Python 3.10–3.15, with either the default HTTP exporter or the optional grpc exporter:
Use Python 3.10–3.13 for this OpenAI example.
import os from openai import OpenAI from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType from traceai_openai import OpenAIInstrumentor provider = register(project_name="traceai-quickstart", project_type=ProjectType.OBSERVE) OpenAIInstrumentor().instrument(tracer_provider=provider) try: response = OpenAI().chat.completions.create( model=os.environ["OPENAI_MODEL"], messages=[{"role": "user", "content": "Say hello in one word."}], ) print(response.choices[0].message.content) finally: provider.shutdown() # Flush pending spans before the process exits. Open the traceai-quickstart project in Observe in Future AGI. provider.shutdown() flushes pending spans before exit.
From fi-instrumentation-otel 1.2.2, register() leaves your SIGINT and SIGTERM handlers unchanged. Default SIGTERM does not run Python exit hooks, so call provider.shutdown() from your application's shutdown path to export pending spans on container stop, and allow enough termination grace time. SIGKILL cannot flush spans.
A standalone script that owns its signal policy can opt in:
import signal def stop(signum, frame): provider.shutdown() raise SystemExit(0) # Your application chooses the exit status. signal.signal(signal.SIGTERM, stop) signal.signal(signal.SIGINT, stop) In a web server, worker or async service, use the framework's shutdown hook instead of replacing its handlers: stop accepting work, finish or cancel active requests, then call provider.shutdown(). force_flush() exports ended spans without shutting down the provider; it does not replace shutdown for operations still running.
The core SDK provides fi_instrumentation.aws_lambda.LambdaTracer; no separate Lambda instrumentor package is needed. Create one instance outside your synchronous handler and share its provider with model-client instrumentors:
from fi_instrumentation import register from fi_instrumentation.aws_lambda import LambdaTracer from fi_instrumentation.fi_types import ProjectType provider = register( project_name="lambda-orders", project_type=ProjectType.OBSERVE, batch=True, schedule_delay_millis=60_000, timeout=2, verbose=False, ) tracing = LambdaTracer(provider) @tracing.wrap def lambda_handler(event, context): return {"statusCode": 200, "body": "Order accepted"} The wrapper emits one lambda.handler server span with the invocation ID, trigger and cold-start flag. It imports only W3C traceparent from API Gateway v1/v2, function URL and ALB events (including multi-value headers). Other events start fresh traces. The invocation wrapper never captures event/result content, request URLs, headers, exception messages or stacks; errors carry only their type. For HTTP triggers it reads only the integer statusCode of the returned response: the span records http.response.status_code, and a 5xx response marks it as an error with error.type set to the code, so frameworks that turn exceptions into 500 responses (Mangum, for example) still report failed requests. Child instrumentors retain their own privacy settings.
After the span ends, it waits up to two seconds for a flush, capped by the remaining invocation time minus 250 ms. Configure those limits with flush_timeout_millis and reserve_millis. A timed-out flush is not cancelled and may continue; later invocations skip flushing while it is in flight, preventing additional flush workers from accumulating. Delivery remains best effort. Use a batch processor and a finite exporter timeout; synchronous span processors can block inside span end, outside this wait budget.
Remove any copied Lambda tracing helper, manual invocation span or explicit flush when adopting the wrapper. Do not combine it with AwsLambdaInstrumentor or an auto-instrumenting Lambda layer. Do not shut down the shared provider after each invocation. The old example's LAMBDA_TRACE_CAPTURE_CONTENT switch does not apply to this metadata-only wrapper.
Use using_attributes(session_id=..., user_id=..., metadata=...) to attach application context. The core also provides using_session, using_user, using_tags, and suppress_tracing.
Content capture is on by default. Configure FI_HIDE_INPUTS, FI_HIDE_OUTPUTS, FI_HIDE_INPUT_MESSAGES, FI_HIDE_OUTPUT_MESSAGES, FI_HIDE_INPUT_TEXT, FI_HIDE_OUTPUT_TEXT, FI_HIDE_INPUT_IMAGES, and FI_HIDE_EMBEDDING_VECTORS before initialization. Set each to true to hide that content.
FI_HIDE_ERROR_DETAILS=true hides error descriptions, exception messages, and stack traces while keeping status and error types. When unset, it follows the input/output value, message, and text hide flags. Explicit false overrides the derived value. See the configuration implementation and the cross-language privacy guide.
Pass your own OpenTelemetry TracerProvider to OpenAIInstrumentor().instrument(tracer_provider=provider) to use an existing exporter. The register() helper configures Future AGI by default. On current source, register(span_exporter=...) replaces that destination; older published versions may not include this option.
Each package below links to its own installation instructions, supported SDK versions, and examples. Package availability and framework support are independent; do not assume every package supports the same upstream version.
Read the contributing guide. Licensed under Apache 2.0.
All 2 files in this release have provenance metadata.
traceai futureagi opentelemetry tracing observability llm
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
All 2 files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




