-
Notifications
You must be signed in to change notification settings - Fork 21
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
Make an opt-out path for the BINARY format #10
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import absolute_import | ||
|
||
import struct | ||
from .context import SpanContext | ||
from .propagator import Propagator | ||
# This can cause problems when old versions of protobuf are installed | ||
from .wire_pb2 import TracerState | ||
from opentracing import InvalidCarrierException | ||
|
||
_proto_size_bytes = 4 # bytes | ||
|
||
|
||
class BinaryPropagator(Propagator): | ||
"""A BasicTracer Propagator for Format.BINARY.""" | ||
|
||
def inject(self, span_context, carrier): | ||
if type(carrier) is not bytearray: | ||
raise InvalidCarrierException() | ||
state = TracerState() | ||
state.trace_id = span_context.trace_id | ||
state.span_id = span_context.span_id | ||
state.sampled = span_context.sampled | ||
if span_context.baggage is not None: | ||
for key in span_context.baggage: | ||
state.baggage_items[key] = span_context.baggage[key] | ||
|
||
# The binary format is {uint32}{protobuf} using big-endian for the uint | ||
carrier.extend(struct.pack('>I', state.ByteSize())) | ||
carrier.extend(state.SerializeToString()) | ||
|
||
def extract(self, carrier): | ||
if type(carrier) is not bytearray: | ||
raise InvalidCarrierException() | ||
state = TracerState() | ||
state.ParseFromString(str(carrier[_proto_size_bytes:])) | ||
baggage = {} | ||
for k in state.baggage_items: | ||
baggage[k] = state.baggage_items[k] | ||
|
||
return SpanContext( | ||
span_id=state.span_id, | ||
trace_id=state.trace_id, | ||
baggage=baggage, | ||
sampled=state.sampled) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import absolute_import | ||
|
||
from abc import ABCMeta, abstractmethod | ||
|
||
|
||
class Propagator(object): | ||
__metaclass__ = ABCMeta | ||
|
||
@abstractmethod | ||
def inject(self, span_context, carrier): | ||
pass | ||
|
||
@abstractmethod | ||
def extract(self, carrier): | ||
pass |
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
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
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.
the point of this change is that a BasicTracer extender may choose not to even import this BinaryPropagator file and its
.wire_pb2
dependency that breaks some builds that also involve other version of protobufs.