docs(samples): add Python samples for integrating with existing OpenTelemetry#288
Merged
juliomenendez merged 10 commits intomainfrom Apr 29, 2026
Merged
Conversation
Lean greenfield CLI sample showing how to add the Agent 365 SDK to an app that already has Azure Monitor OpenTelemetry initialized. Uses the OpenAI Agents SDK with auto-instrumentation via microsoft-agents-a365-observability-extensions-openai. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Said "four numbered sections" while listing five (Step 1, 2, 2b, 3, 4). Reword to acknowledge Step 2b as a sub-step. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sample The previous wording told users to filter Transaction search by "Operation name invoke_agent" — but invoke_agent / inference / execute_tool are values of the gen_ai.operation.name *attribute*, not the App Insights operation name. Reword to point at the right field. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lean greenfield CLI sample showing how to add the Agent 365 SDK to an app that already has the OpenTelemetry SDK initialized, demonstrating manual instrumentation with InvokeAgentScope / InferenceScope / ExecuteToolScope around a raw OpenAI client (no agent framework). Defaults to ConsoleSpanExporter for zero-setup; a commented OTLPSpanExporter block shows the swap-in for real backends. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
InferenceScope uses InferenceOperationType.value (e.g. "Chat") for both the gen_ai.operation.name attribute and the span name; "inference" is not what users will actually see in their backend. Update both sample READMEs to reflect the real SDK behavior and clarify where the value comes from. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Dependency ReviewThe following issues were found:
License Issuespython/observability-with-azure-monitor/pyproject.toml
python/observability-with-langgraph/pyproject.toml
python/observability-with-otlp/pyproject.toml
OpenSSF ScorecardScorecard details
Scanned Files
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds two lean Python CLI samples under python/ demonstrating how to integrate the Microsoft Agent 365 Python SDK into applications that already have OpenTelemetry initialized, covering both Azure Monitor and vendor-neutral OTLP setups (auto vs manual instrumentation).
Changes:
- Added
observability-with-azure-monitorsample usingazure-monitor-opentelemetry+ OpenAI Agents SDK auto-instrumentation. - Added
observability-with-otlpsample using a manual OTel SDK setup + manual Agent 365 scope instrumentation. - Included per-sample
pyproject.toml, README,.env.template, and.gitignore.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| python/observability-with-otlp/pyproject.toml | Defines a minimal, installable sample with OpenAI + OTel deps. |
| python/observability-with-otlp/main.py | Manual OTel init + manual Agent 365 scopes around OpenAI tool-calling loop. |
| python/observability-with-otlp/README.md | Documents how to run locally with ConsoleSpanExporter and swap to OTLP. |
| python/observability-with-otlp/.gitignore | Ignores env/venv/build artifacts for the sample. |
| python/observability-with-otlp/.env.template | Provides environment variable template for local runs. |
| python/observability-with-azure-monitor/pyproject.toml | Defines a minimal, installable sample with Azure Monitor + OpenAI Agents deps. |
| python/observability-with-azure-monitor/main.py | Azure Monitor OTel init + Agent 365 configure + OpenAI Agents instrumentor. |
| python/observability-with-azure-monitor/README.md | Documents setup/run and what spans to look for in App Insights. |
| python/observability-with-azure-monitor/.gitignore | Ignores env/venv/build artifacts for the sample. |
| python/observability-with-azure-monitor/.env.template | Provides environment variable template for local runs. |
- Replace OPENAI_API_KEY=sk-... placeholder with a non-secret form so secret scanners don't false-positive. - Capture and check configure() return status in both samples; exit cleanly with a clear message when configuration fails. - Validate APPLICATIONINSIGHTS_CONNECTION_STRING up front in the AM sample with a friendly error pointing at .env.template. - Guard tool_calls indexing in the OTLP sample so the manual-loop doesn't crash when the model answers without calling the tool. - Add "Demonstrates" and "Troubleshooting" sections to both sample READMEs to make setup and failure-mode diagnosis easier. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The Agent 365 SDK gates span creation behind ENABLE_OBSERVABILITY (or ENABLE_A365_OBSERVABILITY) env var — without one set to a truthy value, scopes silently produce zero spans. Both .env.template files now include ENABLE_OBSERVABILITY=true, and the READMEs surface the requirement in Setup plus a Troubleshooting bullet at the top of each sample's troubleshooting list (it's the most common silent-failure mode). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Auto-instrumentation via the openai extension produces gen_ai.operation .name="chat" (lowercase) per the OTel GenAI semantic conventions, not "Chat" as previously documented. The OTLP sample's manual instrumentation correctly produces "Chat" (the InferenceOperationType.CHAT.value); the AM sample uses auto-instrumentation and emits the spec-conformant lowercase form. Fixing the AM README to reflect what users will actually see in App Insights. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirrors Google Cloud's LangGraph + OpenTelemetry reference sample, adapted for the Agent 365 SDK: existing OTel TracerProvider first, then `configure()`, then `CustomLangChainInstrumentor` for auto-instrumented LLM/tool spans, with `InvokeAgentScope` wrapping `agent.invoke(...)` for the top-level span. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fpfp100
approved these changes
Apr 29, 2026
alexlu4250
reviewed
Apr 29, 2026
alexlu4250
approved these changes
Apr 29, 2026
alexlu4250
left a comment
There was a problem hiding this comment.
Approving with one concern (see my comment)
gwharris7
approved these changes
Apr 29, 2026
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
Two new lean Python samples under
python/that show how to add the Microsoft Agent 365 SDK to an app that already has OpenTelemetry initialized — a scenario the existing samples don't cover. Each sample is a single-file CLI that runs a tool-calling agent end-to-end so users can see Agent 365 spans flowing alongside their existing telemetry.python/observability-with-azure-monitor/— pairs Azure Monitor / Application Insights (azure-monitor-opentelemetry) with the OpenAI Agents SDK and auto-instrumentation viamicrosoft-agents-a365-observability-extensions-openai.python/observability-with-otlp/— pairs a manual OpenTelemetry SDK setup (defaults toConsoleSpanExporterfor zero external setup; OTLPSpanExporter swap-in shown as a commented block) with a rawopenaiclient and manual instrumentation usingInvokeAgentScope/InferenceScope/ExecuteToolScope.The two samples deliberately cover different cells of the (backend × instrumentation-style) matrix so a customer can find their case quickly.
What's intentionally NOT in these samples
python/openai/sample-agent. These samples are laser-focused on the OTel-init + A365-configure()integration pattern._stub_token_resolverreturns a placeholder so users can run the sample with just an OpenAI key.Companion PR
A companion PR on
microsoft/Agent365-pythonadds the integration guide that both sample READMEs link to (docs/integrating-with-existing-opentelemetry.md). The samples reference the guide via amain-pointing GitHub URL; that link resolves once the docs PR merges.Test plan
main.pyparsespython -m venv .venv && pip install -e .inpython/observability-with-azure-monitor/with a real App Insights connection string + OpenAI key, runpython main.py, confirminvoke_agent,Chat <model>,execute_toolspans appear in App Insights Transaction searchpython/observability-with-otlp/with just an OpenAI key, confirm the four-span tree (invoke_agent WeatherAgent→ twoChat <model>+ oneexecute_tool get_weather) prints to stdout viaConsoleSpanExporter🤖 Generated with Claude Code