Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle none value for OTEL_PROPAGATORS #4236

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions opentelemetry-api/src/opentelemetry/propagate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def inject(
"tracecontext,baggage",
)

if environ_propagators.lower() == "none":
propagators = []
Annosha marked this conversation as resolved.
Show resolved Hide resolved
else:
propagators = environ_propagators.split(",")

for propagator in environ_propagators.split(","):
Annosha marked this conversation as resolved.
Show resolved Hide resolved
propagator = propagator.strip()
Expand Down
12 changes: 12 additions & 0 deletions opentelemetry-api/tests/propagators/test_propagators.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def test_propagators(propagators):

reload(opentelemetry.propagate)

@patch.dict(environ, {OTEL_PROPAGATORS: "none"})
@patch("opentelemetry.propagators.composite.CompositePropagator")
def test_no_propagators_loaded(self, mock_compositehttppropagator):
Copy link
Member

@emdneto emdneto Oct 24, 2024

Choose a reason for hiding this comment

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

I ran this test locally, and it doesn't fail against the main branch

Copy link
Author

Choose a reason for hiding this comment

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

@emdneto I apologize for the confusion. Could you clarify what you would like me to address?

Copy link
Contributor

@xrmx xrmx Oct 25, 2024

Choose a reason for hiding this comment

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

@Annosha The test should fail on main and raise and exception (as reported in the issue). If it doesn't fail with the current code it means it's not a good test to evaluate if the fix is working.

Copy link
Author

Choose a reason for hiding this comment

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

@xrmx and @emdneto The test is failing after fixes in testing logic. This failure confirms that the test accurately detects the issue. Here is the test log on my machine:
test-fail-for-PR-OTEL-Propagators-NONE-vlaue
Could you please review this on your end and advise on any further improvements needed?

Copy link
Member

Choose a reason for hiding this comment

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

I was expecting something like that: this should fail when running against main with the ValueError present on the issue

        global_textmap = propagate.get_global_textmap()
        self.assertIsInstance(global_textmap, composite.CompositePropagator)
        self.assertEqual(len(global_textmap._propagators), 0)

def test_propagators(propagators):
self.assertEqual(
propagators, []
) # Expecting an empty list of propagators

mock_compositehttppropagator.configure_mock(
**{"side_effect": test_propagators}
)

@patch.dict(environ, {OTEL_PROPAGATORS: "a, b, c "})
@patch("opentelemetry.propagators.composite.CompositePropagator")
@patch("opentelemetry.util._importlib_metadata.entry_points")
Expand Down
Loading