Skip to content

Add explicit custom baggage propagation - #264

Merged
Radhika Gupta (rads-1996) merged 19 commits into
microsoft:mainfrom
nikhilNava:copilot/custom-baggage-propagation
Sep 22, 2026
Merged

Radhika Gupta (rads-1996) merged 19 commits into
microsoft:mainfrom
nikhilNava:copilot/custom-baggage-propagation

Conversation

@nikhilNava

Copy link
Copy Markdown
Collaborator

Summary

  • add explicit custom_attribute and custom_attributes baggage APIs
  • propagate only opted-in custom baggage keys to GenAI spans
  • preserve direct span attribute precedence and existing set_pairs behavior

Python parity for the custom baggage portion of microsoft/opentelemetry-distro-dotnet#116. Existing session ID support was already present.

Validation

  • focused tests: 28 passed
  • A365 tests: 485 passed, 15 skipped
  • Black and Pylint: passed

Full mypy still reports the existing missing stubs for msal in an untouched module.

@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

Performance comparison

Threshold: regressions >15.0% on gating scenarios fail the build. Higher ops/s is better; positive Δ means the PR is slower.

Scenario Gating Baseline (ops/s) Candidate (ops/s) Δ % Status
azure_monitor_log yes 17,325.6 16,931.6 +2.33%
azure_monitor_span yes 160,230.7 162,813.4 -1.59%
otel_log no 19,926.7 17,804.5 +11.92%
otel_span no 39,035.1 37,022.0 +5.44%

nikhilc-microsoft and others added 3 commits September 11, 2026 18:01
An explicit but unrecognized gen_ai.operation.name attribute classified a span as non-GenAI before the supported instrumentation-scope signal was evaluated, so opted-in custom baggage never reached real OpenAI Agents, LangChain, Agent Framework and openai_v2 spans whose operation is chain, embeddings, text_completion, generate_content or create_agent.

The classifier now evaluates signals in order: a recognized explicit attribute yields GenAI with a known operation; an unrecognized explicit attribute stays authoritative over baggage and span-name inference but still falls through to instrumentation-scope detection; without an explicit attribute, recognized baggage, then span name, then scope apply. Scope-only recognition means GenAI with an unknown operation, so common and custom baggage may apply while invoke_agent-only attributes are withheld.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Address the two moderate baggage-builder issues involving reserved metadata and nested-scope registrations.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds explicit custom baggage APIs and propagates opted-in keys to recognized GenAI spans.

Changes:

  • Adds custom_attribute() and custom_attributes() APIs.
  • Updates propagation, tests, documentation, changelog, and samples.
File summaries
File Summary
tests/a365/test_span_processor.py Tests propagation and span classification.
tests/a365/test_baggage_builder.py Tests custom baggage behavior.
src/microsoft/opentelemetry/a365/README.md Documents updated APIs.
src/microsoft/opentelemetry/a365/core/middleware/baggage_builder.py Implements custom baggage tracking. set_pairs() can bypass opt-in, and nested scopes can lose inherited registrations.
src/microsoft/opentelemetry/a365/core/exporters/span_processor.py Classifies GenAI spans and propagates selected keys.
src/microsoft/opentelemetry/a365/core/constants.py Adds related constants.
samples/microsoft_agent_framework/sample_maf_agent.py Formatting updates.
samples/langchain/validate_traces.py Formatting updates.
CHANGELOG.md Records the feature.
A365_DOCUMENTATION.md Documents custom baggage usage.
Review details
  • Files reviewed: 9/10 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/microsoft/opentelemetry/a365/core/middleware/baggage_builder.py
Comment thread src/microsoft/opentelemetry/a365/core/middleware/baggage_builder.py
Comment thread src/microsoft/opentelemetry/a365/core/constants.py
Comment thread CHANGELOG.md Outdated
Comment thread docs/superpowers/plans/2026-09-22-genai-operation-precedence.md Outdated

@rads-1996 Radhika Gupta (rads-1996) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@rads-1996
Radhika Gupta (rads-1996) merged commit db3509f into microsoft:main Sep 22, 2026
12 checks passed
@nikhilNava
Nikhil Navakiran (nikhilNava) deleted the copilot/custom-baggage-propagation branch September 22, 2026 20:41
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