-
Notifications
You must be signed in to change notification settings - Fork 277
feat: Implement the Trace Response propagator #1397
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
Merged
robertlaurin
merged 4 commits into
open-telemetry:main
from
wperron:trace-response-propagator
Nov 8, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bd6402f
feat: Implement the Trace Response propagator
wperron 8a90751
more PR comments
wperron b8c71f7
Update sdk_experimental/lib/opentelemetry/sdk/trace/propagation/trace…
wperron 5693d56
conditionally define class unless already defined in stable
wperron 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 hidden or 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
62 changes: 62 additions & 0 deletions
62
...tal/lib/opentelemetry/sdk/trace/propagation/trace_context/response_text_map_propagator.rb
This file contains hidden or 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,62 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| unless OpenTelemetry::Trace::Propagation::TraceContext.const_defined?(:ResponseTextMapPropagator) | ||
| module OpenTelemetry | ||
| module Trace | ||
| module Propagation | ||
| module TraceContext | ||
| # Propagates trace response using the W3C Trace Context format | ||
| # https://w3c.github.io/trace-context/#traceresponse-header | ||
| class ResponseTextMapPropagator | ||
| TRACERESPONSE_KEY = 'traceresponse' | ||
| FIELDS = [TRACERESPONSE_KEY].freeze | ||
|
|
||
| private_constant :TRACERESPONSE_KEY, :FIELDS | ||
|
|
||
| # Inject trace context into the supplied carrier. | ||
| # | ||
| # @param [Carrier] carrier The mutable carrier to inject trace context into | ||
| # @param [Context] context The context to read trace context from | ||
| # @param [optional Setter] setter If the optional setter is provided, it | ||
| # will be used to write context into the carrier, otherwise the default | ||
| # text map setter will be used. | ||
| def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter) | ||
| span_context = Trace.current_span(context).context | ||
| return unless span_context.valid? | ||
|
|
||
| setter.set(carrier, TRACERESPONSE_KEY, TraceParent.from_span_context(span_context).to_s) | ||
| nil | ||
| end | ||
|
|
||
| # Extract trace context from the supplied carrier. This is a no-op for | ||
| # this propagator, and will return the provided context. | ||
| # | ||
| # @param [Carrier] carrier The carrier to get the header from | ||
| # @param [optional Context] context Context to be updated with the trace context | ||
| # extracted from the carrier. Defaults to +Context.current+. | ||
| # @param [optional Getter] getter If the optional getter is provided, it | ||
| # will be used to read the header from the carrier, otherwise the default | ||
| # text map getter will be used. | ||
| # | ||
| # @return [Context] the original context. | ||
| def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) | ||
| context | ||
| end | ||
|
|
||
| # Returns the predefined propagation fields. If your carrier is reused, you | ||
| # should delete the fields returned by this method before calling +inject+. | ||
| # | ||
| # @return [Array<String>] a list of fields that will be used by this propagator. | ||
| def fields | ||
| FIELDS | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
40 changes: 40 additions & 0 deletions
40
...st/opentelemetry/sdk/trace/propagation/trace_context/response_text_map_propagator_test.rb
This file contains hidden or 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,40 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| require 'test_helper' | ||
|
|
||
| describe OpenTelemetry::Trace::Propagation::TraceContext::ResponseTextMapPropagator do | ||
| let(:traceresponse_key) { 'traceresponse' } | ||
| let(:propagator) do | ||
| OpenTelemetry::Trace::Propagation::TraceContext::ResponseTextMapPropagator.new | ||
| end | ||
|
|
||
| let(:carrier) do | ||
| { | ||
| traceresponse_key => valid_traceresponse_header | ||
| } | ||
| end | ||
| let(:context) { OpenTelemetry::Context.empty } | ||
| let(:context_valid) do | ||
| span_context = OpenTelemetry::Trace::SpanContext.new(trace_id: ("\xff" * 16).b, span_id: ("\x11" * 8).b) | ||
| span = OpenTelemetry::Trace.non_recording_span(span_context) | ||
| OpenTelemetry::Trace.context_with_span(span) | ||
| end | ||
|
|
||
| describe '#inject' do | ||
| it 'writes traceresponse into the carrier' do | ||
| carrier = {} | ||
| propagator.inject(carrier, context: context_valid) | ||
| _(carrier[traceresponse_key]).must_equal('00-ffffffffffffffffffffffffffffffff-1111111111111111-00') | ||
| end | ||
|
|
||
| it "doesn't write if the context is not valid" do | ||
| carrier = {} | ||
| propagator.inject(carrier, context: context) | ||
| _(carrier).wont_include(traceresponse_key) | ||
| end | ||
| end | ||
| end |
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.
Uh oh!
There was an error while loading. Please reload this page.