Skip to content

Commit a50eef2

Browse files
authored
Update _responses_instrumentor.py
This script fails to run, and this PR is the fix. import os import logging # 1) MUST be set before Azure SDK imports/client construction os.environ.setdefault("AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING", "true") # Tracing setup (required order) from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.sampling import ALWAYS_OFF from azure.core.settings import settings from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan from azure.ai.projects.telemetry import AIProjectInstrumentor from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential def main() -> None: logging.basicConfig(level=logging.DEBUG) logging.getLogger("azure").setLevel(logging.DEBUG) logging.getLogger("openai").setLevel(logging.DEBUG) endpoint = os.environ.get("FOUNDRY_PROJECT_ENDPOINT") model = os.environ.get("FOUNDRY_MODEL_NAME") if not endpoint: raise RuntimeError("FOUNDRY_PROJECT_ENDPOINT is not set") if not model: raise RuntimeError("FOUNDRY_MODEL_NAME is not set") # 2) Global tracer provider with ALWAYS_OFF -> NonRecordingSpan trace.set_tracer_provider(TracerProvider(sampler=ALWAYS_OFF)) # 3) Use OpenTelemetry span implementation for azure-core tracing settings.tracing_implementation = OpenTelemetrySpan # 4) Explicitly activate AI Projects instrumentor exactly once AIProjectInstrumentor().instrument() credential = DefaultAzureCredential() client = AIProjectClient(endpoint=endpoint, credential=credential) # 5) Responses API call through OpenAI client openai_client = client.get_openai_client() response = openai_client.responses.create( model=model, input=[{"role": "user", "content": "hello from repro for #46544"}], ) output_text = getattr(response, "output_text", None) or "" print(f"response_id={response.id}") print(f"output_text={output_text}") if __name__ == "__main__": main()
1 parent 5505e1d commit a50eef2

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_responses_instrumentor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ def _append_to_message_attribute(
557557
new_messages: List[Dict[str, Any]],
558558
) -> None:
559559
"""Helper to append messages to an existing attribute, combining with previous messages."""
560+
561+
if not span.span_instance.is_recording():
562+
return
563+
560564
# Get existing attribute value
561565
existing_value = span.span_instance.attributes.get(attribute_name) if span.span_instance.attributes else None
562566

0 commit comments

Comments
 (0)