feat(observability): add baggage attribute mapping for span customization#4705
Open
vishu-bh wants to merge 7 commits into
Open
feat(observability): add baggage attribute mapping for span customization#4705vishu-bh wants to merge 7 commits into
vishu-bh wants to merge 7 commits into
Conversation
f0531a0 to
d64eabc
Compare
Member
Minor Issues1. Missing Inline Comment
|
fc315b9 to
211f91b
Compare
…tion Implements Option A semantics for SpanAttributeCustomizer plugin: - Extract attribute_mapping from plugin config at startup - Add BaggageAttributeSpanProcessor to duplicate baggage.* attributes - Initialize telemetry after plugin manager to access config - Add comprehensive test coverage for mapping extraction and processor This allows operators to remap baggage-derived span attributes like baggage.tenant.id to custom keys like tenant.id for backend compatibility. Fixes #4700 Signed-off-by: Bob Shell <[email protected]> Signed-off-by: Vishu Bhatnagar <[email protected]>
- Add test for extract_span_attribute_mapping with None factory - Add test for BaggageAttributeSpanProcessor with empty mapping - Add test for BaggageAttributeSpanProcessor with None span - Add test for BaggageAttributeSpanProcessor skipping None values - Add test for BaggageAttributeSpanProcessor on_end returning None These tests cover lines 416, 468, 478, and 487 in observability.py, bringing coverage from 92.3% to above the 93% threshold. Relates-to: #4700 Signed-off-by: Vishu Bhatnagar <[email protected]>
- Prefix unused 'span' parameter with underscore in observability.py - Remove redundant SessionLocal import in admin.py Fixes pylint unused-argument and reimported warnings. Signed-off-by: Vishu Bhatnagar <[email protected]>
- Set OTEL_BAGGAGE_HEADER_MAPPINGS=x-tenant-id:tenant.id in Langfuse compose - Enables testing of tenant.id propagation to span attributes via baggage Signed-off-by: Vishu Bhatnagar <[email protected]>
Signed-off-by: Vishu Bhatnagar <[email protected]>
Explain why span_attribute_mapping extraction happens before telemetry initialization - it must run after plugin manager init to access plugin configuration. Addresses review comment about missing documentation for telemetry init reordering logic. Signed-off-by: Vishu Bhatnagar <[email protected]>
Signed-off-by: Vishu Bhatnagar <[email protected]>
211f91b to
d942dcc
Compare
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.
Problem
Issue #4700 requires selected tenant/user context carried through OpenTelemetry baggage to appear in exported spans without the
baggage.prefix. Clients can send values such astenant.idanduser.idas OTEL baggage, but some observability backends expect those dimensions as span attributes namedtenant.id/user.id, notbaggage.tenant.id/baggage.user.id.The gateway still needs to stay aligned with OTEL semantics: baggage remains the propagation mechanism, while span attributes are the reporting surface.
Solution
This PR replaces the earlier span-processor remapping approach with a baggage emission policy that is applied where baggage is copied onto spans.
The
SpanAttributeCustomizerplugin now supports:With that configuration:
tenant.idanduser.idtenant.id/user.idbaggage.tenant.id/baggage.user.idare not emitted for those allowlisted keysIf the new config is not provided, the gateway preserves legacy behavior and emits baggage as
baggage.<key>.Changes
mcpgateway/observability.pyBaggageSpanAttributePolicycreate_span()BaggageAttributeSpanProcessorremapping pathmcpgateway/main.pyplugins/span_attribute_customizer/config_schema.pyallowed_baggage_span_attributesemit_baggage_prefixed_attributesplugins/config.yamltenant.idanduser.idDocs
Tests
Testing
Validated locally:
Also verified focused observability coverage and diff-cover behavior locally after adding tests for the changed baggage paths.
Fixes #4700