-
Notifications
You must be signed in to change notification settings - Fork 247
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
fix!: rename SpanContext to SpanReference #440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,19 +33,19 @@ def initialize(traceparent_key: 'traceparent', | |
# carrier, header key, header value to the setter. | ||
# @return [Object] the carrier with context injected | ||
def inject(carrier, context, &setter) | ||
return carrier unless (span_context = span_context_from(context)) | ||
return carrier unless (span_reference = span_reference_from(context)).valid? | ||
|
||
setter ||= DEFAULT_SETTER | ||
setter.call(carrier, @traceparent_key, TraceParent.from_context(span_context).to_s) | ||
setter.call(carrier, @tracestate_key, span_context.tracestate) unless span_context.tracestate.nil? | ||
setter.call(carrier, @traceparent_key, TraceParent.from_span_reference(span_reference).to_s) | ||
setter.call(carrier, @tracestate_key, span_reference.tracestate) unless span_reference.tracestate.nil? | ||
|
||
carrier | ||
end | ||
|
||
private | ||
|
||
def span_context_from(context) | ||
OpenTelemetry::Trace.current_span(context)&.context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we can get rid of the lonely operator here. |
||
def span_reference_from(context) | ||
OpenTelemetry::Trace.current_span(context).reference | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ module Propagation | |
module TraceContext | ||
# A TraceParent is an implementation of the W3C trace context specification | ||
# https://www.w3.org/TR/trace-context/ | ||
# {Trace::SpanContext} | ||
# {Trace::SpanReference} | ||
class TraceParent | ||
InvalidFormatError = Class.new(Error) | ||
InvalidVersionError = Class.new(Error) | ||
|
@@ -25,16 +25,16 @@ class TraceParent | |
REGEXP = /^(?<version>[A-Fa-f0-9]{2})-(?<trace_id>[A-Fa-f0-9]{32})-(?<span_id>[A-Fa-f0-9]{16})-(?<flags>[A-Fa-f0-9]{2})(?<ignored>-.*)?$/.freeze | ||
private_constant :REGEXP | ||
|
||
INVALID_TRACE_ID = OpenTelemetry::Trace::SpanContext::INVALID.hex_trace_id | ||
INVALID_SPAN_ID = OpenTelemetry::Trace::SpanContext::INVALID.hex_span_id | ||
INVALID_TRACE_ID = OpenTelemetry::Trace::SpanReference::INVALID.hex_trace_id | ||
INVALID_SPAN_ID = OpenTelemetry::Trace::SpanReference::INVALID.hex_span_id | ||
private_constant :INVALID_TRACE_ID, :INVALID_SPAN_ID | ||
|
||
class << self | ||
# Creates a new {TraceParent} from a supplied {Trace::SpanContext} | ||
# @param [SpanContext] ctx The context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should read |
||
# Creates a new {TraceParent} from a supplied {Trace::SpanReference} | ||
# @param [SpanReference] reference The span reference | ||
# @return [TraceParent] a trace parent | ||
def from_context(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps rename this |
||
new(trace_id: ctx.trace_id, span_id: ctx.span_id, flags: ctx.trace_flags) | ||
def from_span_reference(reference) | ||
new(trace_id: reference.trace_id, span_id: reference.span_id, flags: reference.trace_flags) | ||
end | ||
|
||
# Deserializes the {TraceParent} from the string representation | ||
|
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.
I feel like this should be
span_context
, although we avoid that name inSpan
due to stuttering (but perhaps we shouldn't?).