Skip to content

docs(samples): add Python samples for integrating with existing OpenTelemetry#288

Merged
juliomenendez merged 10 commits intomainfrom
samples/observability-existing-otel
Apr 29, 2026
Merged

docs(samples): add Python samples for integrating with existing OpenTelemetry#288
juliomenendez merged 10 commits intomainfrom
samples/observability-existing-otel

Conversation

@juliomenendez
Copy link
Copy Markdown
Contributor

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 via microsoft-agents-a365-observability-extensions-openai.
  • python/observability-with-otlp/ — pairs a manual OpenTelemetry SDK setup (defaults to ConsoleSpanExporter for zero external setup; OTLPSpanExporter swap-in shown as a commented block) with a raw openai client and manual instrumentation using InvokeAgentScope / 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

  • No M365 Agents SDK host / Playground / agent registration — covered by python/openai/sample-agent. These samples are laser-focused on the OTel-init + A365-configure() integration pattern.
  • No real Azure auth / token caching — _stub_token_resolver returns a placeholder so users can run the sample with just an OpenAI key.
  • No third sample for the auto-on-OTLP or manual-on-AzureMonitor cells — the integration guide explains those axes are independent and points readers at the matrix.

Companion PR

A companion PR on microsoft/Agent365-python adds the integration guide that both sample READMEs link to (docs/integrating-with-existing-opentelemetry.md). The samples reference the guide via a main-pointing GitHub URL; that link resolves once the docs PR merges.

Test plan

  • Verify each sample's main.py parses
  • Run python -m venv .venv && pip install -e . in python/observability-with-azure-monitor/ with a real App Insights connection string + OpenAI key, run python main.py, confirm invoke_agent, Chat <model>, execute_tool spans appear in App Insights Transaction search
  • Run the same in python/observability-with-otlp/ with just an OpenAI key, confirm the four-span tree (invoke_agent WeatherAgent → two Chat <model> + one execute_tool get_weather) prints to stdout via ConsoleSpanExporter
  • Verify both READMEs render correctly on GitHub

🤖 Generated with Claude Code

juliomenendez and others added 5 commits April 28, 2026 16:44
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>
Copilot AI review requested due to automatic review settings April 28, 2026 23:41
@juliomenendez juliomenendez requested a review from a team as a code owner April 28, 2026 23:41
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 19 package(s) with unknown licenses.
See the Details below.

License Issues

python/observability-with-azure-monitor/pyproject.toml

PackageVersionLicenseIssue Type
azure-monitor-opentelemetry>= 1.6.0NullUnknown License
microsoft-agents-a365-observability-coreNullUnknown License
microsoft-agents-a365-observability-extensions-openaiNullUnknown License
openai-agents>= 0.2.6NullUnknown License
python-dotenv>= 1.0.0NullUnknown License

python/observability-with-langgraph/pyproject.toml

PackageVersionLicenseIssue Type
langchain-core>= 0.3.0NullUnknown License
langchain-openai>= 0.3.0NullUnknown License
langgraph>= 0.3.0NullUnknown License
microsoft-agents-a365-observability-coreNullUnknown License
microsoft-agents-a365-observability-extensions-langchainNullUnknown License
opentelemetry-exporter-otlp-proto-grpc>= 1.27.0NullUnknown License
opentelemetry-sdk>= 1.27.0NullUnknown License
python-dotenv>= 1.0.0NullUnknown License
wrapt< 2NullUnknown License

python/observability-with-otlp/pyproject.toml

PackageVersionLicenseIssue Type
microsoft-agents-a365-observability-coreNullUnknown License
openai>= 1.40.0NullUnknown License
opentelemetry-exporter-otlp-proto-http>= 1.27.0NullUnknown License
opentelemetry-sdk>= 1.27.0NullUnknown License
python-dotenv>= 1.0.0NullUnknown License
Denied Licenses: GPL-3.0-only, AGPL-3.0-only

OpenSSF Scorecard

Scorecard details
PackageVersionScoreDetails
pip/azure-monitor-opentelemetry >= 1.6.0 UnknownUnknown
pip/microsoft-agents-a365-observability-core UnknownUnknown
pip/microsoft-agents-a365-observability-extensions-openai UnknownUnknown
pip/openai-agents >= 0.2.6 UnknownUnknown
pip/python-dotenv >= 1.0.0 UnknownUnknown
pip/langchain-core >= 0.3.0 UnknownUnknown
pip/langchain-openai >= 0.3.0 UnknownUnknown
pip/langgraph >= 0.3.0 UnknownUnknown
pip/microsoft-agents-a365-observability-core UnknownUnknown
pip/microsoft-agents-a365-observability-extensions-langchain UnknownUnknown
pip/opentelemetry-exporter-otlp-proto-grpc >= 1.27.0 UnknownUnknown
pip/opentelemetry-sdk >= 1.27.0 UnknownUnknown
pip/python-dotenv >= 1.0.0 UnknownUnknown
pip/wrapt < 2 UnknownUnknown
pip/microsoft-agents-a365-observability-core UnknownUnknown
pip/openai >= 1.40.0 UnknownUnknown
pip/opentelemetry-exporter-otlp-proto-http >= 1.27.0 UnknownUnknown
pip/opentelemetry-sdk >= 1.27.0 UnknownUnknown
pip/python-dotenv >= 1.0.0 UnknownUnknown

Scanned Files

  • python/observability-with-azure-monitor/pyproject.toml
  • python/observability-with-langgraph/pyproject.toml
  • python/observability-with-otlp/pyproject.toml

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

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-monitor sample using azure-monitor-opentelemetry + OpenAI Agents SDK auto-instrumentation.
  • Added observability-with-otlp sample 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.

Comment thread python/observability-with-azure-monitor/main.py Outdated
Comment thread python/observability-with-azure-monitor/main.py Outdated
Comment thread python/observability-with-azure-monitor/.env.template Outdated
Comment thread python/observability-with-otlp/README.md
Comment thread python/observability-with-azure-monitor/README.md
Comment thread python/observability-with-otlp/.env.template Outdated
Comment thread python/observability-with-otlp/main.py Outdated
Comment thread python/observability-with-otlp/main.py
juliomenendez and others added 3 commits April 29, 2026 07:18
- 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>
Comment thread python/observability-with-azure-monitor/pyproject.toml
Copy link
Copy Markdown

@alexlu4250 alexlu4250 left a comment

Choose a reason for hiding this comment

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

Approving with one concern (see my comment)

@juliomenendez juliomenendez merged commit 7eee7fa into main Apr 29, 2026
34 checks passed
@juliomenendez juliomenendez deleted the samples/observability-existing-otel branch April 29, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants