Class: Labkit::Tracing::Adapters::OpentelemetryTracer Private
- Inherits:
-
BaseTracer
- Object
- BaseTracer
- Labkit::Tracing::Adapters::OpentelemetryTracer
- Defined in:
- lib/labkit/tracing/adapters/opentelemetry_tracer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: OpenTelemetryScope
Instance Attribute Summary
Attributes inherited from BaseTracer
Instance Method Summary collapse
- #active_span ⇒ Object private
-
#extract_context(carrier, format: nil) ⇒ Object
private
rubocop:disable Lint/UnusedMethodArgument.
- #in_span(operation_name, child_of: nil, tags: {}) ⇒ Object private
-
#inject_context(span_wrapper, carrier, format: nil) ⇒ Object
private
rubocop:disable Lint/UnusedMethodArgument.
- #start_active_span(operation_name, tags: nil) ⇒ Object private
- #start_span(operation_name, child_of: nil, tags: {}, start_time: nil) ⇒ Object private
Methods inherited from BaseTracer
Constructor Details
This class inherits a constructor from Labkit::Tracing::Adapters::BaseTracer
Instance Method Details
#active_span ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/labkit/tracing/adapters/opentelemetry_tracer.rb', line 72 def active_span OpenTelemetry::Trace.current_span end |
#extract_context(carrier, format: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Lint/UnusedMethodArgument
53 54 55 56 57 58 |
# File 'lib/labkit/tracing/adapters/opentelemetry_tracer.rb', line 53 def extract_context(carrier, format: nil) # rubocop:disable Lint/UnusedMethodArgument # Format parameter is ignored for OpenTelemetry - propagation format is configured # globally via OTEL_PROPAGATORS environment variable, not per-call like OpenTracing. # The parameter exists only for BaseTracer API compatibility. OpenTelemetry.propagation.extract(carrier) end |
#in_span(operation_name, child_of: nil, tags: {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/labkit/tracing/adapters/opentelemetry_tracer.rb', line 30 def in_span(operation_name, child_of: nil, tags: {}) attributes = || {} if child_of span = tracer.start_span(operation_name, with_parent: child_of, attributes: attributes) ctx = OpenTelemetry::Trace.context_with_span(span) result = nil OpenTelemetry::Context.with_current(ctx) do adapter = OpentelemetrySpan.new(span) result = yield(adapter) end span.finish result else tracer.in_span(operation_name, attributes: attributes) do |span| adapter = OpentelemetrySpan.new(span) yield(adapter) end end end |
#inject_context(span_wrapper, carrier, format: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Lint/UnusedMethodArgument
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/labkit/tracing/adapters/opentelemetry_tracer.rb', line 60 def inject_context(span_wrapper, carrier, format: nil) # rubocop:disable Lint/UnusedMethodArgument # Format parameter is ignored for OpenTelemetry - propagation format is configured # globally via OTEL_PROPAGATORS environment variable, not per-call like OpenTracing. # The parameter exists only for BaseTracer API compatibility. # # span_wrapper is expected to be a BaseSpan (e.g., OpentelemetrySpan) that wraps # the actual OpenTelemetry span. We unwrap it to get the OTel span object. span = span_wrapper.respond_to?(:span) ? span_wrapper.span : span_wrapper context = OpenTelemetry::Trace.context_with_span(span) OpenTelemetry.propagation.inject(carrier, context: context) end |
#start_active_span(operation_name, tags: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 79 80 81 82 83 |
# File 'lib/labkit/tracing/adapters/opentelemetry_tracer.rb', line 76 def start_active_span(operation_name, tags: nil) attributes = || {} raw_span = tracer.start_span(operation_name, attributes: attributes) ctx = OpenTelemetry::Trace.context_with_span(raw_span) token = OpenTelemetry::Context.attach(ctx) OpenTelemetryScope.new(raw_span, token) end |
#start_span(operation_name, child_of: nil, tags: {}, start_time: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 27 28 |
# File 'lib/labkit/tracing/adapters/opentelemetry_tracer.rb', line 20 def start_span(operation_name, child_of: nil, tags: {}, start_time: nil) attributes = || {} opts = { attributes: attributes } opts[:with_parent] = child_of if child_of opts[:start_timestamp] = start_time if start_time span = tracer.start_span(operation_name, **opts) OpentelemetrySpan.new(span) end |