-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add a create_http_headers_for_my_span() zipkin_span method #142
Closed
+65
−0
Closed
Changes from all commits
Commits
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 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 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 |
---|---|---|
|
@@ -844,6 +844,48 @@ def test_override_span_name(self): | |
assert span.span_name == 'new_name' | ||
assert span.logging_context.span_name == 'new_name' | ||
|
||
def test_create_http_headers_for_my_span_no_zipkin_attrs(self): | ||
with zipkin.zipkin_client_span( | ||
service_name='test_service', | ||
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. too much indentation. Please rebase on the black branch and run |
||
span_name='test_span', | ||
transport_handler=MockTransportHandler(), | ||
sample_rate=100.0, | ||
) as span: | ||
# Not sure how this could ever happen in real life, but if it | ||
# did... | ||
span.zipkin_attrs = None | ||
assert {} == span.create_http_headers_for_my_span() | ||
|
||
def test_create_http_headers_for_my_span_is_sampled(self): | ||
with zipkin.zipkin_client_span( | ||
service_name='test_service', | ||
span_name='test_span', | ||
transport_handler=MockTransportHandler(), | ||
sample_rate=100.0, | ||
) as span: | ||
assert { | ||
'X-B3-TraceId': span.zipkin_attrs.trace_id, | ||
'X-B3-SpanId': span.zipkin_attrs.span_id, | ||
'X-B3-ParentSpanId': span.zipkin_attrs.parent_span_id, | ||
'X-B3-Flags': '0', | ||
'X-B3-Sampled': '1', | ||
} == span.create_http_headers_for_my_span() | ||
|
||
def test_create_http_headers_for_my_span_is_NOT_sampled(self): | ||
with zipkin.zipkin_client_span( | ||
service_name='test_service', | ||
span_name='test_span', | ||
transport_handler=MockTransportHandler(), | ||
sample_rate=0.0, | ||
) as span: | ||
assert { | ||
'X-B3-TraceId': span.zipkin_attrs.trace_id, | ||
'X-B3-SpanId': span.zipkin_attrs.span_id, | ||
'X-B3-ParentSpanId': span.zipkin_attrs.parent_span_id, | ||
'X-B3-Flags': '0', | ||
'X-B3-Sampled': '0', | ||
} == span.create_http_headers_for_my_span() | ||
|
||
|
||
def test_zipkin_client_span(): | ||
context = zipkin.zipkin_client_span('test_service', 'test_span') | ||
|
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.
Can you make this a regular function that receives ZipkinAttrs as argument? That way it can be reused more widely even if you don't have access to the span (e.g. you can get the zipkin_attrs from the tracer)
And if you think that having this extra method on the span context is useful you can keep it and call
create_http_headers_for_my_span(self. zipkin_attrs)
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.
@drolando So... confession time.
I also wanted access to the "current zipkin_span context object" from anywhere (remember, our use-case is eventlet which is very "this code appears to be running isolated to just handling one request" even though it may be spread out all over the place). So we have THIS hack that I haven't even bothered trying to get you to accept, haha:
I feel dirty even pasting that in here.
I'm pretty sure that's trying to leak memory and what should probably change is for the zipkin_span object's
_tracer
instance be made a weak reference.BUT, I obviously haven't really thought this through, nor tried to measure memory leakage, nor seeing if the weakref thing will break something.
So... all this is to say that I want access to the zipkin_span instance anyway, and that's why this patch looks the way it does.
Can you render an opinion on the above? Please tell me you can think of a clean way to get me what i want? 😅