-
Notifications
You must be signed in to change notification settings - Fork 757
Feature: Include trace flags in spans exported by the OTLPSpanExporter #4761
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
Open
nikhilmantri0902
wants to merge
18
commits into
open-telemetry:main
Choose a base branch
from
nikhilmantri0902:feat/otlpspanexporter_traceflags_bits07
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−6
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a1d43e8
chore: added full trace flags implementation and tests
nikhilmantri0902 acc6f2e
chore: added changelog entry
nikhilmantri0902 27a12dc
chore: removed getattr method and unnecessay int typecasts
nikhilmantri0902 f6e8ef1
Merge branch 'main' into feat/otlpspanexporter_traceflags_bits07
nikhilmantri0902 858e16b
chore: minor updates as per review
nikhilmantri0902 92a8960
Merge branch 'main' into feat/otlpspanexporter_traceflags_bits07
xrmx 142ba3a
fix: tox lint errors
nikhilmantri0902 37312bf
fix: pylint error
nikhilmantri0902 55e7a3a
fix: added fixes for the failing test cases
nikhilmantri0902 ec02a22
fix:merged main
nikhilmantri0902 fb5aec8
fix: precommit formatting
nikhilmantri0902 0696540
Merge branch 'main' into feat/otlpspanexporter_traceflags_bits07
xrmx 3be6a7b
Update CHANGELOG.md
xrmx 9e581fb
Merge branch 'main' into feat/otlpspanexporter_traceflags_bits07
xrmx 04be919
Merge branch 'main' into feat/otlpspanexporter_traceflags_bits07
xrmx c7a1222
fix: PR comments
nikhilmantri0902 01afe45
fix: failing workflow
nikhilmantri0902 f5eb8de
Merge branch 'main' into feat/otlpspanexporter_traceflags_bits07
xrmx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| ) | ||
| from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import ( | ||
| _SPAN_KIND_MAP, | ||
| _encode_links, | ||
| _encode_span, | ||
| _encode_status, | ||
| ) | ||
| from opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans | ||
|
|
@@ -42,6 +44,7 @@ | |
| ) | ||
| from opentelemetry.proto.trace.v1.trace_pb2 import ScopeSpans as PB2ScopeSpans | ||
| from opentelemetry.proto.trace.v1.trace_pb2 import Span as PB2SPan | ||
| from opentelemetry.proto.trace.v1.trace_pb2 import SpanFlags as PB2SpanFlags | ||
| from opentelemetry.proto.trace.v1.trace_pb2 import Status as PB2Status | ||
| from opentelemetry.sdk.trace import Event as SDKEvent | ||
| from opentelemetry.sdk.trace import Resource as SDKResource | ||
|
|
@@ -56,6 +59,13 @@ | |
| from opentelemetry.trace.status import Status as SDKStatus | ||
| from opentelemetry.trace.status import StatusCode as SDKStatusCode | ||
|
|
||
| # Mask for all currently-defined span flag bits (0-9): lower 8 trace flags + has/is remote bits | ||
| ALL_SPAN_FLAGS_MASK = ( # pylint: disable=no-member | ||
| PB2SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK | ||
| | PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | ||
| | PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK | ||
| ) | ||
|
|
||
|
|
||
| class TestOTLPTraceEncoder(unittest.TestCase): | ||
| def test_encode_spans(self): | ||
|
|
@@ -298,7 +308,7 @@ def get_exhaustive_test_spans( | |
| code=SDKStatusCode.ERROR.value, | ||
| message="Example description", | ||
| ), | ||
| flags=0x300, | ||
| flags=0x301, | ||
| ) | ||
| ], | ||
| ), | ||
|
|
@@ -501,3 +511,78 @@ def test_encode_status_code_translations(self): | |
| code=SDKStatusCode.ERROR.value, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| class TestSpanFlagsEncoding(unittest.TestCase): | ||
| def test_span_flags_root_unsampled(self): | ||
| span_context = SDKSpanContext( | ||
| 0x1, 0x2, is_remote=False, trace_flags=0x00 | ||
| ) | ||
| span = SDKSpan(name="root", context=span_context, parent=None) | ||
| pb = _encode_span(span) | ||
| assert (pb.flags & PB2SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK) == 0x00 # pylint: disable=no-member | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this per testcase instead so we can have this only once, i.e. put this comment in first line of this class? |
||
| assert ( | ||
| pb.flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) != 0 | ||
| assert (pb.flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) == 0 # pylint: disable=no-member | ||
| assert (pb.flags & ~ALL_SPAN_FLAGS_MASK) == 0 | ||
|
|
||
| def test_span_flags_root_sampled(self): | ||
| span_context = SDKSpanContext( | ||
| 0x1, 0x2, is_remote=False, trace_flags=0x01 | ||
| ) | ||
| span = SDKSpan(name="root", context=span_context, parent=None) | ||
| pb = _encode_span(span) | ||
| assert (pb.flags & PB2SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK) == 0x01 # pylint: disable=no-member | ||
| assert ( | ||
| pb.flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) != 0 | ||
| assert (pb.flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) == 0 # pylint: disable=no-member | ||
| assert (pb.flags & ~ALL_SPAN_FLAGS_MASK) == 0 | ||
|
|
||
| def test_span_flags_remote_parent_sampled(self): | ||
| parent = SDKSpanContext(0x1, 0x9, is_remote=True) | ||
| span_context = SDKSpanContext( | ||
| 0x1, 0x2, is_remote=False, trace_flags=0x01 | ||
| ) | ||
| span = SDKSpan(name="child", context=span_context, parent=parent) | ||
| pb = _encode_span(span) | ||
| assert (pb.flags & PB2SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK) == 0x01 # pylint: disable=no-member | ||
| assert ( | ||
| pb.flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) != 0 | ||
| assert (pb.flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0 # pylint: disable=no-member | ||
| assert (pb.flags & ~ALL_SPAN_FLAGS_MASK) == 0 | ||
|
|
||
| def test_link_flags_local_and_remote(self): | ||
| # local sampled link | ||
| l1 = SDKLink( | ||
| SDKSpanContext(0x1, 0x2, is_remote=False, trace_flags=0x01) | ||
| ) | ||
| # remote sampled link | ||
| l2 = SDKLink( | ||
| SDKSpanContext(0x1, 0x3, is_remote=True, trace_flags=0x01) | ||
| ) | ||
| pb_links = _encode_links([l1, l2]) | ||
| assert ( | ||
| pb_links[0].flags & PB2SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK # pylint: disable=no-member | ||
| ) == 0x01 | ||
| assert ( | ||
| pb_links[0].flags | ||
| & PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) != 0 | ||
| assert ( | ||
| pb_links[0].flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) == 0 | ||
| assert (pb_links[0].flags & ~ALL_SPAN_FLAGS_MASK) == 0 | ||
| assert ( | ||
| pb_links[1].flags & PB2SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK # pylint: disable=no-member | ||
| ) == 0x01 | ||
| assert ( | ||
| pb_links[1].flags | ||
| & PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) != 0 | ||
| assert ( | ||
| pb_links[1].flags & PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK # pylint: disable=no-member | ||
| ) != 0 | ||
| assert (pb_links[1].flags & ~ALL_SPAN_FLAGS_MASK) == 0 | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again the code should not be aware of the mocks in tests, what tests are failing? Can we update the mocks to be
speced against the class we need?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for otlp-http-exporter the fix is small, need to add trace_flags to the mocked span context, here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for otlp-grpc-exporter will have to fix the same, but in more places here