microsoft/agents/agents-sdk-python-otel
Claude Code and agent skill by microsoft/agents
- vendor
Checking that the SKILL.md file is still in the repository.
Use when adding, configuring, validating, or troubleshooting OpenTelemetry observability for a Microsoft 365 Agents SDK application in Python. Trigger when the user mentions OpenTelemetry, OTel, telemetry, traces, metrics, logs, OTLP, Aspire Dashboard, Application Insights, Azure Monitor, distributed tracing, custom tracers or meters, span sampling, or observing microsoft_agents SDK signals.
Install
npx vskill@latest install microsoft/agents/agents-sdk-python-otelSKILL.md
The same SKILL.md was published earlier as microsoft/agents/agents-sdk-python-otel.
OpenTelemetry for Agents SDK (Python)
Goal
Configure traces, metrics, and logs for a Python Agents SDK application, including the SDK's built-in telemetry and a local Aspire Dashboard. Preserve the project's dependency manager, web host, logging design, and startup lifecycle.
Non-negotiable rules
- Configure global OpenTelemetry providers before importing most
microsoft_agents SDK modules. The Python SDK resolves tracers and meters at import time. microsoft_agents.activity contains no telemetry and is safe to import before provider setup.
- Extend existing providers instead of attempting to replace already-set
global providers. OpenTelemetry Python does not permit provider replacement after initialization.
- Instrument aiohttp, requests, or other libraries after providers are
configured and before the application starts handling traffic.
- Use one stable application-specific
service.name. - Let exporters read standard OTEL environment variables. Never hardcode
collector credentials, API keys, or connection strings.
- Never add prompts, responses, message text, tokens, authorization headers,
cookies, secrets, attachment contents, user names, user IDs, conversation IDs, activity IDs, or arbitrary HTTP headers to custom telemetry by default.
- Keep custom metric attributes low-cardinality. Good dimensions include
route type, activity type, channel ID, operation, status, and error type.
- Use batch processors for normal applications. Simple processors are only
appropriate for narrow debugging or tests.
- Do not set always-on sampling as a production default. Honor the deployment
sampling policy or configure a deliberate parent-based ratio.
- Flush tracer, meter, and logger providers during graceful shutdown. Do not
silently ignore exporter or shutdown failures.
- Avoid duplicate
LoggingHandlerinstances on the root logger. - Aspire Dashboard anonymous mode is local-development only. Bind it to
loopback and never deploy that configuration.
- Telemetry must record and re-raise application exceptions.
Workflow
Complete these steps in order.
1. Inspect the application
Find:
pyproject.toml,requirements*.txt, lockfiles, Python version, virtual
environment convention, and dependency manager.
- The actual startup module and import order.
- Whether the app uses aiohttp, FastAPI, Flask, requests, httpx, or another
server/client stack.
- Existing global tracer, meter, or logger providers.
- Existing OTLP, Azure Monitor, Application Insights, or vendor-specific
exporters.
- Existing logging handlers and shutdown hooks.
- Existing custom tracers, meters, instruments, and instrumentation calls.
- OTEL settings in
.envtemplates, deployment manifests, containers, and
CI/CD configuration.
If any provider is already configured, merge the missing exporter, instrumentation, processor, or logging behavior into that setup. Do not call trace.set_tracer_provider, metrics.set_meter_provider, or set_logger_provider a second time.
Choose one provider setup:
- Use zero-code instrumentation when the user requests no OTel setup code and
the application's process can be started through opentelemetry-instrument.
- Use programmatic configuration when the application must own providers,
processors, custom exporters, shutdown behavior, or unsupported instrumentation.
- Preserve an existing provider setup instead of introducing either approach
alongside it.
2. Add only the required packages
Use the project's dependency manager and preserve its lockfile.
For zero-code instrumentation of a pip-based aiohttp application:
For programmatic instrumentation of a pip-based aiohttp application:
Install only instrumentations for libraries the application actually uses. Examples:
opentelemetry-instrumentation-fastapiopentelemetry-instrumentation-flaskopentelemetry-instrumentation-httpxopentelemetry-instrumentation-logging
Keep OpenTelemetry API, SDK, exporter, and instrumentation versions compatible. Do not add a second dependency manifest or switch package managers.
3. Configure providers
Zero-code setup
Do not add an instrumentation.py module, OTel imports, provider setup, or manual instrumentation calls to application code. Configure the distro with standard environment variables:
The process that launches opentelemetry-instrument must already contain these variables. Calling load_dotenv() in the application startup module is too late: the zero-code launcher configures providers before it imports the application. For a local .env, load it in the parent process:
This command requires python-dotenv[cli]. In deployments, configure the same variables in the process environment and use:
The launcher is part of the required startup lifecycle. Running python -m src.main directly does not enable zero-code export. Installed instrumentation packages are discovered by the distro and initialized before the application starts.
Programmatic setup
Create instrumentation.py without importing any Agents SDK telemetry module:
Exporter constructors intentionally omit endpoints and headers so they honor the standard OTEL environment variables.
If the application already configured a provider, do not use this complete template. Modify the existing provider setup instead.
4. Enforce provider-before-SDK import order
For zero-code instrumentation, opentelemetry-instrument establishes the providers before loading the startup module; do not duplicate provider setup in that module.
For programmatic instrumentation, the startup module must load environment variables, configure providers, and only then import the agent:
Do not move microsoft_agents.hosting.core, microsoft_agents.hosting.aiohttp, authentication, storage, connector, or agent-module imports above provider initialization.
5. Instrument the libraries the app uses
For zero-code instrumentation, install only the applicable instrumentation packages and let the distro discover them. Do not also call their instrument() methods in application code.
For programmatic instrumentation, configure aiohttp server/client and requests explicitly:
Call instrument_libraries() after provider setup and before creating the web application or making instrumented requests.
Do not enrich spans with complete URLs, query strings, headers, request bodies, response bodies, prompts, or agent messages. If custom hooks are required, add only reviewed, bounded attributes.
6. Integrate graceful shutdown
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 16 Sep 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingagent-plugins/agents-for-python/skills/agents-sdk-python-otel/SKILL.md
Popularity
- Repository stars
- 1,066
- Repository forks
- 340
- 7-day trend score
- 35
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/microsoft/agents/agents-sdk-python-otel)