Skip to content

Migrate agentserver tracing from azure-monitor-opentelemetry-exporter…#46561

Merged
singankit merged 13 commits intomainfrom
users/singankit/ms_distro_tracing
Apr 29, 2026
Merged

Migrate agentserver tracing from azure-monitor-opentelemetry-exporter…#46561
singankit merged 13 commits intomainfrom
users/singankit/ms_distro_tracing

Conversation

@singankit
Copy link
Copy Markdown
Contributor

@singankit singankit commented Apr 27, 2026

… to microsoft-opentelemetry

Replace manual Azure Monitor and OTLP exporter wiring (~100 lines) with a single use_microsoft_opentelemetry() call via the new microsoft-opentelemetry distro. The distro auto-detects exporters from environment variables.

Changes:

  • core pyproject.toml: swap azure-monitor-opentelemetry-exporter + otlp-grpc for microsoft-opentelemetry>=0.5.0
  • core _tracing.py: refactor _configure_tracing() to delegate to new _setup_distro_export() wrapper; remove 4 setup* functions and guard flags
  • Update all test mocks in core and invocations to patch the single _setup_distro_export target instead of multiple setup* functions
  • Remove azure-monitor-opentelemetry-exporter from dev_requirements.txt in both core and invocations packages

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:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

… to microsoft-opentelemetry

Replace manual Azure Monitor and OTLP exporter wiring (~100 lines) with a
single use_microsoft_opentelemetry() call via the new microsoft-opentelemetry
distro. The distro auto-detects exporters from environment variables.

Changes:
- core pyproject.toml: swap azure-monitor-opentelemetry-exporter + otlp-grpc
  for microsoft-opentelemetry>=0.5.0
- core _tracing.py: refactor _configure_tracing() to delegate to new
  _setup_distro_export() wrapper; remove 4 _setup_* functions and guard flags
- Update all test mocks in core and invocations to patch the single
  _setup_distro_export target instead of multiple _setup_* functions
- Remove azure-monitor-opentelemetry-exporter from dev_requirements.txt
  in both core and invocations packages

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 27, 2026 20:44
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label Apr 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates AgentServer observability export wiring from manual Azure Monitor + OTLP exporter setup to the microsoft-opentelemetry distro, centralizing configuration behind a single _setup_distro_export() wrapper and updating tests/dev dependencies accordingly.

Changes:

  • Replace azure-monitor-opentelemetry-exporter + OTLP gRPC exporter dependencies with microsoft-opentelemetry>=0.5.0.
  • Refactor azure-ai-agentserver-core tracing setup to delegate exporter configuration to the distro (and simplify/remove legacy setup functions/flags).
  • Update tests to patch _setup_distro_export and remove dev requirement references to azure-monitor-opentelemetry-exporter.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_tracing.py Refactors tracing/export configuration to use the microsoft-opentelemetry distro and removes legacy exporter setup logic.
sdk/agentserver/azure-ai-agentserver-core/pyproject.toml Swaps exporter dependencies to microsoft-opentelemetry and removes local uv source for the old exporter.
sdk/agentserver/azure-ai-agentserver-core/dev_requirements.txt Drops local editable install of azure-monitor-opentelemetry-exporter.
sdk/agentserver/azure-ai-agentserver-core/tests/test_tracing.py Updates mocks/assertions to patch the single distro setup function rather than multiple exporter setup functions.
sdk/agentserver/azure-ai-agentserver-invocations/tests/test_tracing.py Updates test patch points to _setup_distro_export.
sdk/agentserver/azure-ai-agentserver-invocations/tests/test_span_parenting.py Updates test patch points to _setup_distro_export.
sdk/agentserver/azure-ai-agentserver-invocations/pyproject.toml Removes azure-monitor-opentelemetry-exporter from dev dependencies and uv sources.
sdk/agentserver/azure-ai-agentserver-invocations/dev_requirements.txt Removes local reference to azure-monitor-opentelemetry-exporter.

Comment thread sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_tracing.py Outdated
Comment thread sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_tracing.py Outdated
Comment thread sdk/agentserver/azure-ai-agentserver-core/tests/test_tracing.py Outdated
Comment thread sdk/agentserver/azure-ai-agentserver-core/pyproject.toml
singankit and others added 9 commits April 27, 2026 17:17
Log a warning in _configure_tracing() when _create_resource() returns None,
making it clear that tracing will not be configured.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix docstring and inline comment to accurately describe logger suppression
  (only Azure Core HTTP logging policy, not generic OTel exporters)
- Make _ensure_trace_provider idempotent via _agentserver_processors_added
  guard to prevent duplicate processors on repeated calls
- Rename TestSetupAzureMonitor -> TestSetupDistroExport to match new impl

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The invocations min-dependency CI installs the published core package
from PyPI, which does not yet have _setup_distro_export. Adding
create=True allows the mock to succeed regardless of the installed
core version.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The microsoft-opentelemetry distro validates that the instrumentation
key is a proper UUID. Replace 'InstrumentationKey=test' with
'InstrumentationKey=00000000-0000-0000-0000-000000000000' in all
test files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous requirement >=0.5.0 doesn't exist on PyPI. The latest
available release is 0.1.0b1 (just published).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous code logged INFO for each exporter configured (e.g.
'Application Insights trace exporter configured.'). This preserves
that pattern with a single INFO message when the distro setup succeeds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The microsoft-opentelemetry distro has Azure Monitor disabled by
default. Pass enable_azure_monitor=True and the connection string
via azure_monitor_connection_string when a connection string is
provided.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds test_span_parenting_in_appinsights which verifies that a child span
created inside request_span is correctly parented in App Insights:
- Captures child span ID locally during handler execution
- Queries dependencies table by child span ID
- Follows operation_ParentId to find the parent invoke_agent span in requests table

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move module-level set_tracer_provider() calls in invocations unit tests
into autouse fixtures. When pytest collects tests it imports ALL modules,
even deselected ones. Module-level calls consumed the OTel Once guard
before the e2e test could configure the microsoft-opentelemetry distro,
causing spans to never reach App Insights.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
singankit and others added 3 commits April 28, 2026 18:34
The dependency analyzer requires all package dependencies to be listed
in shared_requirements.txt.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add :keyword: docstring entries for _setup_distro_export (C4758)
- Use dict literal instead of dict() call (R1735)
- Add :param: docstring entries for _ensure_trace_provider (C4739)
- Suppress protected-access warning on idempotency guard (W0212)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@singankit
Copy link
Copy Markdown
Contributor Author

@singankit singankit enabled auto-merge (squash) April 29, 2026 04:43
@singankit singankit merged commit ca36cd4 into main Apr 29, 2026
25 checks passed
@singankit singankit deleted the users/singankit/ms_distro_tracing branch April 29, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants