Repository navigation
feat(python): add set_attributes and custom span/log processors - #859
Open
abelonogov-ld wants to merge 2 commits into
Open
abelonogov-ld wants to merge 2 commits into
abelonogov-ld wants to merge 2 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
This was referenced Oct 28, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Vadman97
approved these changes
Oct 29, 2026
This branch has not been deployed
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
Adds global attributes and custom span/log processors to the Python observability plugin. This is one of a set of matching PRs across RN, Android, iOS, Flutter, MAUI, Java and Python that share the same semantics.
Global attributes
observe.set_attributes(mapping)andobserve.remove_attributes(keys)maintain one in-memory, thread-safe attribute map for the whole process (lock + read-only snapshot rebuilt on change). Safe to call before init.loggingthrough the SDK handler), and every metric recorded throughobserve.record_*.Custom processors (init-time options)
ObservabilityConfig(span_processors=[...], log_processors=[...])(opentelemetry.sdk.trace.SpanProcessor,opentelemetry.sdk._logs.LogRecordProcessor).force_flush/shutdownare forwarded.Also: OTel's base
SpanProcessor.force_flushreturnsNone, whichTracerProvidertreats as a failed flush and stops before the exporting processor. The global-attributes processor returnsTrue, and the user-processor wrapper only treats an explicitFalseas failure, so explicit flushes still reach the exporter.Note: value validation reuses OTel's
opentelemetry.attributes._clean_attribute(private) so globals follow exactly the same rules as span attributes.How did you test this change?
logging, processor order with changes exported, raising processors, flush/shutdown forwarding, and the real_OTELConfigurationwiring with network mocked.make lint,make testandpoetry buildpass.Are there any deployment considerations?
None. Both features are opt-in and additive; without
set_attributesor the new options, behaviour is unchanged.Note
Overview
Adds process-wide global telemetry attributes and configurable OpenTelemetry processors to the Python observability SDK, with matching e2e coverage in the Flask sample app.
Global attributes: New
observe.set_attributes/observe.remove_attributesmaintain a thread-safe in-memory map (immutable snapshots) that can be set before plugin init. Globals are merged onto spans at start (viaGlobalAttributesSpanProcessor), log records (including stdlib logging), and allobserve.record_*metrics. Per-call attributes win over globals; globals only fill missing keys and respect OTel attribute limits.Custom processors:
ObservabilityConfignow acceptsspan_processorsandlog_processors. Wiring runs global attributes → user processors (exception-safe wrappers) → batch exporters, with fixes soforce_flushstill reaches exporters when user processors returnNone.Docs and the Flask e2e app document a UTM-style repro (
repro.py) that asserts expected attributes on manual span, log, and metric routes. A large newtest_global_attributes.pysuite covers precedence, concurrency, processor ordering, and export survival on processor errors.Reviewed by Cursor Bugbot for commit 9201b50. Bugbot is set up for automated code reviews on this repo. Configure here.