Module: Traces::Backend::OpenTelemetry::Interface
- Defined in:
- lib/traces/backend/open_telemetry/interface.rb
Instance Method Summary collapse
- #trace(name, attributes: nil, &block) ⇒ Object
- #trace_context(span = ::OpenTelemetry::Trace.current_span) ⇒ Object
- #trace_context=(context) ⇒ Object
Instance Method Details
#trace(name, attributes: nil, &block) ⇒ Object
19 20 21 |
# File 'lib/traces/backend/open_telemetry/interface.rb', line 19 def trace(name, attributes: nil, &block) TRACER.in_span(name, attributes: attributes&.transform_keys(&:to_s), &block) end |
#trace_context(span = ::OpenTelemetry::Trace.current_span) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/traces/backend/open_telemetry/interface.rb', line 37 def trace_context(span = ::OpenTelemetry::Trace.current_span) if span_context = span.context flags = 0 if span_context.trace_flags.sampled? flags |= Context::SAMPLED end return Context.new( span_context.trace_id, span_context.span_id, flags, span_context.tracestate, remote: span_context.remote? ) end end |
#trace_context=(context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/traces/backend/open_telemetry/interface.rb', line 23 def trace_context=(context) span_context = ::OpenTelemetry::Trace::SpanContext.new( trace_id: context.trace_id, span_id: context.parent_id, trace_flags: ::OpenTelemetry::Trace::TraceFlags.from_byte(context.flags), tracestate: context.state, remote: context.remote? ) span = ::OpenTelemetry::Trace.non_recording_span(span_context) context = ::OpenTelemetry::Trace.context_with_span(span) ::OpenTelemetry::Context.attach(context) end |