Add opt-in telemetry auto-configuration#553
Draft
rbarbadillo wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in OpenTelemetry telemetry auto-configuration for the Python SDK.
The SDK already emits spans via the OTel API. This PR adds a
mistralai[telemetry]optional extra with the OTel SDK/exporter dependencies, plus helper/env-based configuration so users do not need to manually wire an OTLP exporter, endpoint, auth headers, span processor, and tracer provider just to get Mistral SDK traces working.Telemetry remains off by default.
Usage
Explicit opt-in can be done with:
or with:
Longer term, the target API is:
That constructor parameter is not included here because the constructor is Speakeasy-generated; this PR keeps the implementation in hand-owned code and leaves the path open for codegen support later.
Behavior
mistralai[telemetry]with:opentelemetry-sdkopentelemetry-exporter-otlp-proto-httpMISTRAL_SDK_TELEMETRY=trueorconfigure_telemetry(client, telemetry=True).MISTRAL_SDK_TELEMETRY=falseandtelemetry=Falseas opt-out.configure_telemetry(client, telemetry=True)can still attach a per-client provider even when a global provider exists.OTEL_EXPORTER_OTLP_ENDPOINT/OTEL_EXPORTER_OTLP_TRACES_ENDPOINTas exporter destination config only when telemetry is explicitly enabled.mistralai[telemetry]if optional telemetry dependencies are missing.Checks / QA
1. Default: telemetry remains off
Expected: no SDK telemetry provider is auto-configured unless the app already configured OTel globally.
2. One-flag Mistral telemetry
Expected: the SDK attaches a per-client telemetry provider and sends traces to Mistral's telemetry endpoint.
3. Explicit helper opt-in
Expected: the SDK attaches a per-client telemetry provider for this client.
4. Existing global OTel provider is respected for env auto-config
Expected: env-based SDK telemetry auto-config skips because the app already owns the global provider. Mistral SDK spans use the global provider.
5. Explicit helper can still configure one client
Expected: the global provider remains unchanged, but this Mistral client uses its own per-client telemetry provider.
6. Standard OTel endpoint env vars do not enable telemetry alone
Expected: the SDK does not auto-configure telemetry just because an OTel endpoint env var exists.
7. Standard OTel endpoint env vars are respected after opt-in
Expected: the SDK creates a per-client telemetry provider, but the OTLP exporter reads the standard OTel env config and sends traces to the configured collector instead of the Mistral telemetry endpoint.