Merged
Conversation
tdyas
reviewed
Feb 3, 2026
| old_value = os.environ.get(key) | ||
| try: | ||
| if value is not None: | ||
| os.environ[key] = value |
Contributor
There was a problem hiding this comment.
Should this helper do del os.environ[key] if value is None?
Contributor
There was a problem hiding this comment.
I'll make an update in a separate PR.
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.
Partially address #104
Problem
The Pants OpenTelemetry plugin did not respect the standard OpenTelemetry environment variable
OTEL_RESOURCE_ATTRIBUTES. This meant users could not add custom resource attributes (like team name, environment, user info, etc.) to their telemetry datathrough the standard OpenTelemetry configuration mechanism.
Resource attributes are key-value pairs that describe the entity producing telemetry data and are essential for filtering, grouping, and analyzing traces in observability platforms.
Solution
Modified the plugin to read and respect the
OTEL_RESOURCE_ATTRIBUTESenvironment variable:Read the environment variable: Updated
register.pyto fetchOTEL_RESOURCE_ATTRIBUTESalongsideTRACEPARENTwhen the plugin is enabled.Leverage OpenTelemetry's built-in parsing: Changed
opentelemetry_processor.pyto useResource.create()instead of manually constructing theResource. TheResource.create()method automatically parses and merges attributes from theOTEL_RESOURCE_ATTRIBUTESenvironment variable.Safe environment handling: Implemented a context manager to temporarily set the environment variable during resource creation, ensuring no side effects on the global environment.
Comprehensive testing: Added integration test
do_test_of_resource_attributes()that verifies custom resource attributes are properly included in exported telemetry spans.Example
Before (main branch):
After (this branch):
This allows teams to: