Re-exported from
fiddler_otel.client.FiddlerClient.atexit() so that pending
spans are flushed and the tracer is shut down when the process exits. For short
scripts or critical workloads, call force_flush() and shutdown() explicitly
(e.g. in a try/finally or signal handler) since atexit may not run in all
environments (e.g. SIGKILL, fork).
Asyncio: Tracing works in asyncio (context vars propagate across await). When
shutting down from async code, use aflush() and ashutdown() so the event
loop is not blocked; the sync force_flush() and shutdown() can block for
up to the flush timeout.
Context manager: Use with FiddlerClient(...) as client: to ensure
shutdown() is called on exit (flush then shutdown; atexit is unregistered).
Initialise the FiddlerClient.
Parameters
The unique identifier (UUID4) for the application.
Must be a valid UUID4 (e.g.
550e8400-e29b-41d4-a716-446655440000).
Copy this from the GenAI Applications page in the Fiddler UI.
Required in all modes — even when otlp_enabled=False — because the
S3 connector uses it to route traces to the correct application.The API key for authenticating with the Fiddler backend.
Required when
otlp_enabled=True (the default).
Not required when otlp_enabled=False (e.g. S3-routing mode) — omit or pass ''.The base URL for your Fiddler instance
(e.g.
https://your-instance.fiddler.ai).
Required when otlp_enabled=True (the default).
Not required when otlp_enabled=False — omit or pass ''.
Must use http or https scheme.Controls whether traces are exported directly to the Fiddler
OTLP endpoint. Set to
False to disable all direct export to Fiddler — useful
when traces must first be written to local files for S3 upload (offline / S3 routing
mode). When False, api_key and url are not required and not validated.
Defaults to True.Note: console_tracer, jsonl_capture_enabled, and
otlp_json_capture_enabled are all independent of this flag and can be used in
any combination.If
True, span data is also printed to the console
(stdout). This is additive — traces are still exported to Fiddler via OTLP
(unless otlp_enabled=False). Setting this to True does not suppress or
replace the OTLP export. Useful for local debugging to confirm spans are being
created.Configuration for span limits, such as the maximum number of
attributes or events. When
None (default), OpenTelemetry automatically applies
its standard defaults:-
max_attributes: 128 (orOTEL_SPAN_ATTRIBUTE_COUNT_LIMITenv var) -
max_events: 128 (orOTEL_SPAN_EVENT_COUNT_LIMITenv var) -
max_links: 128 (orOTEL_SPAN_LINK_COUNT_LIMITenv var) -
max_event_attributes: 128 (orOTEL_EVENT_ATTRIBUTE_COUNT_LIMITenv var) -
max_link_attributes: 128 (orOTEL_LINK_ATTRIBUTE_COUNT_LIMITenv var) -
max_span_attribute_length: None/unlimited (orOTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMITenv var) Override these by passing a customSpanLimitsobject or by setting the corresponding environment variables.
The sampler for deciding which spans to record. Defaults to the
parent-based always-on OpenTelemetry sampler (100% sampling).
The compression algorithm for exporting traces. Can be
Compression.Gzip, Compression.Deflate, or Compression.NoCompression.
Only used when otlp_enabled=True. Defaults to Compression.Gzip.If
True, span data is also saved to a local
JSONL file in a custom Fiddler format. This is additive — OTLP export to
Fiddler continues as normal (unless otlp_enabled=False). Setting this to
True does not suppress the OTLP export. Useful for keeping a local copy
of trace data.Note: This JSONL format is not compatible with the Fiddler S3 connector.
For S3 ingestion use otlp_json_capture_enabled=True instead.Path to the JSONL file where trace data will be saved.
Only used when
jsonl_capture_enabled=True.
Override with the FIDDLER_JSONL_FILE environment variable.If
True, traces are written to local .json
files in standard OTLP JSON format (ExportTraceServiceRequest envelope). Files
are written to otlp_json_output_dir. This format is directly compatible with
the Fiddler S3 connector — upload the generated files to S3 and the connector ingests
them without any reformatting. This is additive relative to OTLP export; combine
with otlp_enabled=False to write to files only (offline / S3 routing mode).Directory path where OTLP JSON files are written when
otlp_json_capture_enabled=True. The directory is created automatically if it
does not exist. Each batch of spans is written to a separate timestamped .json
file.If
True, large inline base64 content in span
attributes is uploaded to S3 via POST /v3/files/upload and replaced with
fiddler-file:// URIs before the span is exported. This prevents trace loss
at the 10MB Kafka span limit. Requires otlp_enabled=True (needs url and
api_key). Defaults to False.Raises
- ValueError – If
application_idis not a valid UUID4. - ValueError – If
otlp_enabled=Trueandapi_keyis empty or not provided. - ValueError – If
otlp_enabled=Trueandurlis empty, missing a scheme, or uses a scheme other thanhttp/https.
enter()
Context manager entry.Returns
FiddlerClient
exit()
Context manager exit — flushes and shuts down the tracer provider.force_flush()
Flush pending spans to the exporter.Parameters
Maximum time to wait for flush in milliseconds.
Returns
True if flush completed within the timeout, False otherwise.
async aflush()
Async version offorce_flush().
Runs the flush in a thread pool so the event loop is not blocked.
Returns
bool
shutdown()
Shut down the tracer provider after flushing pending spans. Safe to call multiple times. The atexit handler is unregistered on first call.async ashutdown()
Async version ofshutdown().
Runs flush and shutdown in a thread pool so the event loop is not blocked.
get_tracer_provider()
Return the OpenTelemetry TracerProvider, initializing it on first call.Returns
The configured TracerProvider.
Raises
RuntimeError – If initialization fails.update_resource()
Update the OTel resource with additional attributes. Must be called beforeget_tracer() is invoked.
Parameters
Key-value pairs to merge into the resource.
Raises
ValueError – If the tracer has already been initialized.get_tracer()
Return an OTel tracer for creating spans. Initializes the tracer on the first call.Returns
The OTel tracer instance.
Raises
RuntimeError – If tracer initialization fails.start_as_current_span()
Create a span using a context manager (automatic lifecycle management).Parameters
Name for the span.
Span type —
"span", "generation", "chain", or "tool".Returns
Span wrapper with context manager support.
start_span()
Create a span with manual lifecycle control. Caller must callspan.end().
Parameters
Name for the span.
Span type —
"span", "generation", "chain", or "tool".Returns
Span wrapper requiring an explicit
end() call.See the canonical reference for the full description and examples.