Populate agent metadata in zeroed operation id#47428
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adjusts AgentServer tracing/log correlation so that Hypercorn access logs emitted after the ASGI app returns still have the expected OpenTelemetry context (avoiding “zeroed” operation_Id), and adds a log-record enrichment processor to ensure stable agent metadata is present on logs even when no active span is available.
Changes:
- Stop detaching OpenTelemetry context in
TraceContextMiddlewareto keep request context available through post-response access logging. - Add
_FoundryEnrichmentLogRecordProcessorto populate agent name/version/session dimensions on log records. - Update invocations endpoints to stop resetting per-request contextvars / baggage context and keep them available after handler returns.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
sdk/agentserver/azure-ai-agentserver-invocations/azure/ai/agentserver/invocations/_invocation.py |
Keeps invocation/session context active beyond handler return; removes reset/detach logic (with redundant finally: pass blocks to clean up). |
sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_tracing.py |
Keeps extracted OTel context attached through Hypercorn access logging; adds log-record processor to enrich Foundry agent dimensions. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit c851f3c.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reintroduce request-scoped context detach/reset in tracing middleware and invocation handlers to avoid context leakage across requests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename test session string literals from sess-* to session-* to satisfy cspell in Analyze gate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Instead of adding a new _FoundryEnrichmentLogRecordProcessor, could we reuse the existing _BaggageLogRecordProcessor? It already iterates log records and copies context — extending it to also populate static agent metadata (name, version) and a fallback session_id would avoid a second processor and keep the log enrichment logic in one place. Also, the session_id is already resolved in AgentConfig.from_environment() alongside other platform env vars. Consider passing it as a parameter to _configure_tracing() rather than reading _config._ENV_FOUNDRY_AGENT_SESSION_ID directly (which requires the protected-access pylint disable). |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: singankit <30610298+singankit@users.noreply.github.com>
Only set standardized gen_ai.* and microsoft.* prefixed attributes instead of both prefixed and simple names. Co-authored-by: singankit <30610298+singankit@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines