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 BytesMapCarrier #2245
Add BytesMapCarrier #2245
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2245 +/- ##
=====================================
Coverage 73.6% 73.6%
=====================================
Files 175 175
Lines 12409 12419 +10
=====================================
+ Hits 9134 9147 +13
+ Misses 3041 3039 -2
+ Partials 234 233 -1
|
BytesMapCarrier makes it easy for users to inject/extract propagated values from various sources. For example, if a trace context is propagated by an environment variable, users can create a new BytesMapCarrier with values from the environment and inject the trace context into a Go context.
Would it not be better if this propagator lives in OTel Go Contrib as it is not required not defined by the spec? |
I don't think the |
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.
This generally looks good to me. Please fix the flaky test and add a CHANGELOG entry.
} | ||
|
||
// Set stores the key-value pair. | ||
func (c BytesMapCarrier) Set(key string, value string) { |
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.
Why input the value as a string and store it as a []byte?
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.
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.
Why not store the value as a string, vs. storing as a []byte
?
Not blocking, just curiousity. It seems to mean that every call to Get()
copies the []byte
into a new string because the compiler can't tell that the []byte
is never modified.
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.
@rakyll would you mind following up, 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.
Just a little proposal to make it more clear that BytesMapCarrier
implements TextMapCarrier
interface.
} | ||
|
||
// Set stores the key-value pair. | ||
func (c BytesMapCarrier) Set(key string, value string) { |
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.
// BytesMapCarrier is a Carrier that stores propagated | ||
// values in a map of bytes. |
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.
// BytesMapCarrier is a Carrier that stores propagated | |
// values in a map of bytes. | |
// BytesMapCarrier adapts map of bytes to satisfy the TextMapCarrier interface. |
Is it ok for someone to take over this PR? I opened it but have no bandwidth to follow up right now. |
@rakyll We had asked you a question: #2245 (comment) |
The sort.Strings function sorts in increasing order.
Evaluate the sorted keys.
I'm happy to take this over, but I think to @jmacd's point we should probably replace this PR with a one adding a |
I've created #2334 as a replacement, please take a look. |
BytesMapCarrier makes it easy for users to inject/extract propagated values from various sources. For example, if a trace context is propagated by an environment variable, users can create a new BytesMapCarrier with values from the environment and inject the trace context into a Go context.
Fixes #2243.