-
Notifications
You must be signed in to change notification settings - Fork 375
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
GRPCPropagator: handle metadata array values #1203
Conversation
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.
👋 Thanks for the contribution @mdehoog , much appreciated.
Overall this looks great and should help us be more robust. Left some small nit comments around simply checking for an array vs coercing things into a newly created array every invocation of the relevant trace/span/priority/origin extract methods. I think should should help performance wise as we avoid naively creating an Array every time.
Additionally if possible let's try to prevent a regression here, would you mind adding a unit test to /spec/ddtrace/propagation/grpc_propagator_spec.rb
? Feel free to add any cases you think are relevant but I think simply appending a simple additional test to the describe .extract
block would suffice.
describe '.extract' do |
feel free to use the following or amend how you see fit.
# Metadata values can also be arrays
# https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md
context 'given populated metadata in array format' do
let(:metadata) do
{ 'x-datadog-trace-id' => ['1234567890'],
'x-datadog-parent-id' => ['9876543210'],
'x-datadog-sampling-priority' => ['0'],
'x-datadog-origin' => ['synthetics'] }
end
it 'returns a populated context' do
expect(subject.trace_id).to eq 1234567890
expect(subject.span_id).to eq 9876543210
expect(subject.sampling_priority).to be_zero
expect(subject.origin).to eq 'synthetics'
end
end
Co-authored-by: Eric Mustin <mustin.eric@gmail.com>
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.
🚀
@mdehoog ty again for the contribution! will ping when this is released in the next version. |
thanks for the rapid merge and review! |
@mdehoog we've release 0.42 with this work, if you want to ugrade https://github.com/DataDog/dd-trace-rb/releases/tag/v0.42.0 |
gRPC metadata values can be arrays (see https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md). In gRPC's Ruby metadata implementation, single metadata values are a singular type, and multiple values come as an array.
This library assumes a single value each time. This PR fixes this assumption to take the first value of an array, like the Go version.
This bug surfaced a separate bug with dd-trace-go, which appends values to metadata rather than setting. If your trace looks like
Go -> Go -> Ruby
, the gRPC call to Ruby will contain the headers twice.