-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Update backend to use Traces 0.14.1 #2
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ module OpenTelemetry | |
TRACER = ::OpenTelemetry.tracer_provider.tracer(Traces::Backend::OpenTelemetry.name, Traces::Backend::OpenTelemetry::VERSION) | ||
|
||
module Interface | ||
def trace(name, attributes: nil, &block) | ||
def trace(name, attributes: {}, &block) | ||
span = TRACER.start_span(name, attributes: attributes.transform_keys(&:to_s)) | ||
|
||
begin | ||
|
@@ -27,35 +27,41 @@ def trace(name, attributes: nil, &block) | |
end | ||
rescue Exception => error | ||
span&.record_exception(error) | ||
span&.status = ::OpenTelemetry::Traces::Status.error("Unhandled exception of type: #{error.class}") | ||
span&.status = ::OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{error.class}") | ||
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. appears to be a namespace change within OpenTelemetry |
||
raise | ||
ensure | ||
span&.finish | ||
end | ||
end | ||
|
||
def trace_context=(context) | ||
span_context = ::OpenTelemetry::Traces::SpanContext.new( | ||
span_context = ::OpenTelemetry::Trace::SpanContext.new( | ||
trace_id: context.trace_id, | ||
span_id: context.parent_id, | ||
trace_flags: ::OpenTelemetry::Traces::TracesFlags.from_byte(context.flags), | ||
trace_flags: ::OpenTelemetry::Trace::TraceFlags.from_byte(context.flags), | ||
tracestate: context.state, | ||
remote: context.remote? | ||
) | ||
|
||
span = ::OpenTelemetry::Trace.non_recording_span(span_context) | ||
|
||
# the span seems to be updated correctly, and evaluating line 49 seems to propagate the trace/span ids | ||
# but its not updated in my span | ||
return ::OpenTelemetry::Trace.context_with_span(span) | ||
end | ||
|
||
def trace_context(span = ::OpenTelemetry::Trace.current_span) | ||
# state = baggage.values(context: span.context) | ||
if span_context = span.context | ||
state = baggage.values(context: span.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.
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 don't think it's important. The goal is to create a context which can be sent over the wire, e.g. over an HTTP request or encoded into a database query comment etc. |
||
flags = 0 | ||
|
||
if span_context.trace_flags.sampled? | ||
flags |= Context::SAMPLED | ||
end | ||
Comment on lines
+55
to
+59
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 pulled this from the Datadog Backend. as it was implemented, the trace flags were expected to be provided as an integer, not an object. |
||
|
||
return Context.new( | ||
span_context.trace_id, | ||
span_context.span_id, | ||
span_context.trace_flags, | ||
flags, | ||
span_context.tracestate, | ||
remote: span_context.remote? | ||
) | ||
|
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.
attributes
callstransform_keys
below, whichnil
will not respond to.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.
Yes, that makes sense, alternatively we could write
attributes&.transform_keys
. Not sure what makes more sense.