AIProjectInstrumentor Class
A class for managing the trace instrumentation of the AIProjectClient.
This class allows enabling or disabling tracing for AI Projects and provides functionality to check whether instrumentation is active.
Warning
GenAI tracing is an experimental preview feature. To use this feature, you must set the
environment variable AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING=true (case insensitive)
before calling the instrument() method. Spans, attributes, and events may be modified
in future versions.
Constructor
AIProjectInstrumentor()
Methods
| instrument |
Enable trace instrumentation for AIProjectClient. Warning GenAI tracing is an experimental preview feature. To use this feature, you must set the environment variable AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING=true (case insensitive). If this environment variable is not set or set to any value other than "true", instrumentation will not be enabled and this method will return immediately without effect. Spans, attributes, and events may be modified in future versions. |
| is_content_recording_enabled |
This function gets the content recording value. |
| is_instrumented |
Check if trace instrumentation for AIProjectClient is currently enabled. |
| uninstrument |
Remove trace instrumentation for AIProjectClient. This method removes any active instrumentation, stopping the tracing of AIProjectClient methods. |
instrument
Enable trace instrumentation for AIProjectClient.
Warning
GenAI tracing is an experimental preview feature. To use this feature, you must set the
environment variable AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING=true (case insensitive).
If this environment variable is not set or set to any value other than "true",
instrumentation will not be enabled and this method will return immediately without effect.
Spans, attributes, and events may be modified in future versions.
instrument(enable_content_recording: bool | None = None, enable_trace_context_propagation: bool | None = None, enable_baggage_propagation: bool | None = None) -> None
Parameters
| Name | Description |
|---|---|
|
enable_content_recording
|
bool, <xref:optional>
Whether content recording is enabled as part of the traces or not. Content in this context refers to chat message content and function call tool related function names, function parameter names and values. True will enable content recording, False will disable it. If no value is provided, then the value read from environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT is used. If the environment variable is not found, then the value will default to False. Please note that successive calls to instrument will always apply the content recording value provided with the most recent call to instrument (including applying the environment variable if no value is provided and defaulting to False if the environment variable is not found), even if instrument was already previously called without uninstrument being called in between the instrument calls. Default value: None
|
|
enable_trace_context_propagation
|
bool, <xref:optional>
Whether to enable automatic trace context propagation to OpenAI SDK HTTP requests. When enabled, traceparent and tracestate headers will be injected into requests made by OpenAI clients obtained via get_openai_client(), allowing server-side spans to be correlated with client-side spans. True will enable it, False will disable it. If no value is provided, then the value read from environment variable AZURE_TRACING_GEN_AI_ENABLE_TRACE_CONTEXT_PROPAGATION is used. If the environment variable is not found, then the value will default to False. Default value: None
|
|
enable_baggage_propagation
|
bool, <xref:optional>
Whether to include baggage headers in trace context propagation. Only applies when enable_trace_context_propagation is True. True will enable baggage propagation, False will disable it. If no value is provided, then the value read from environment variable AZURE_TRACING_GEN_AI_TRACE_CONTEXT_PROPAGATION_INCLUDE_BAGGAGE is used. If the environment variable is not found, then the value will default to False. Note: Baggage may contain sensitive application data. Default value: None
|
is_content_recording_enabled
This function gets the content recording value.
is_content_recording_enabled() -> bool
Returns
| Type | Description |
|---|---|
|
A bool value indicating whether content recording is enabled. |
is_instrumented
Check if trace instrumentation for AIProjectClient is currently enabled.
is_instrumented() -> bool
Returns
| Type | Description |
|---|---|
|
True if instrumentation is active, False otherwise. |
uninstrument
Remove trace instrumentation for AIProjectClient.
This method removes any active instrumentation, stopping the tracing of AIProjectClient methods.
uninstrument() -> None