Skip to content
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

Merged
merged 8 commits into from
Oct 14, 2020

Conversation

mdehoog
Copy link
Contributor

@mdehoog mdehoog commented Oct 14, 2020

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.

@mdehoog mdehoog requested a review from a team October 14, 2020 03:20
@ericmustin ericmustin added this to the 0.42.0 milestone Oct 14, 2020
@ericmustin ericmustin added community Was opened by a community member integrations Involves tracing integrations labels Oct 14, 2020
@ericmustin ericmustin self-assigned this Oct 14, 2020
Copy link
Contributor

@ericmustin ericmustin left a 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.

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

lib/ddtrace/propagation/grpc_propagator.rb Outdated Show resolved Hide resolved
lib/ddtrace/propagation/grpc_propagator.rb Outdated Show resolved Hide resolved
lib/ddtrace/propagation/grpc_propagator.rb Outdated Show resolved Hide resolved
lib/ddtrace/propagation/grpc_propagator.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@ericmustin ericmustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@ericmustin ericmustin merged commit 9834c04 into DataDog:master Oct 14, 2020
@ericmustin
Copy link
Contributor

@mdehoog ty again for the contribution! will ping when this is released in the next version.

@mdehoog
Copy link
Contributor Author

mdehoog commented Oct 14, 2020

thanks for the rapid merge and review!

@mdehoog mdehoog deleted the fix-headers branch October 16, 2020 00:09
@ericmustin
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Was opened by a community member integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants