Module: Yes::Core::OpenTelemetry::Trackable::ClassMethods
- Defined in:
- lib/yes/core/open_telemetry/trackable.rb
Instance Method Summary collapse
-
#current_context ⇒ OpenTelemetry::Context?
The current context or nil if no tracer.
-
#current_span ⇒ OpenTelemetry::Trace::Span?
The current span or nil if no tracer.
-
#extract_current_context(carrier) ⇒ OpenTelemetry::Context?
Extracts context from a carrier hash.
-
#otl_tracer ⇒ Object?
The configured OpenTelemetry tracer or nil.
-
#otl_trackable(method_name, otl_data = OtlSpan::OtlData.new(span_name: nil)) ⇒ Symbol
Decorates a method with OpenTelemetry tracing.
-
#propagate_context(ctx_carrier = {}, service_name: false) ⇒ HashWithIndifferentAccess
Propagates the current context to a carrier hash.
-
#with_otl_span(name) { ... } ⇒ Object
Executes a block within a new span.
Instance Method Details
#current_context ⇒ OpenTelemetry::Context?
Returns the current context or nil if no tracer.
59 60 61 62 63 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 59 def current_context return nil unless otl_tracer ::OpenTelemetry::Context.current end |
#current_span ⇒ OpenTelemetry::Trace::Span?
Returns the current span or nil if no tracer.
52 53 54 55 56 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 52 def current_span return nil unless otl_tracer ::OpenTelemetry::Trace.current_span end |
#extract_current_context(carrier) ⇒ OpenTelemetry::Context?
Extracts context from a carrier hash.
92 93 94 95 96 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 92 def extract_current_context(carrier) return nil unless carrier&.key?('traceparent') ::OpenTelemetry.propagation.extract(carrier) end |
#otl_tracer ⇒ Object?
Returns the configured OpenTelemetry tracer or nil.
47 48 49 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 47 def otl_tracer Yes::Core.configuration.otl_tracer end |
#otl_trackable(method_name, otl_data = OtlSpan::OtlData.new(span_name: nil)) ⇒ Symbol
Decorates a method with OpenTelemetry tracing.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 29 def otl_trackable(method_name, otl_data = OtlSpan::OtlData.new(span_name: nil)) otl_data.span_name ||= name instance_module = Module.new do define_method(method_name) do |*args, **kwargs, &blk| return super(*args, **kwargs, &blk) unless singleton_class.otl_tracer OtlSpan.new(otl_data:, otl_tracer: singleton_class.otl_tracer).otl_span(*args, **kwargs) do super(*args, **kwargs, &blk) end end end prepend instance_module method_name end |
#propagate_context(ctx_carrier = {}, service_name: false) ⇒ HashWithIndifferentAccess
Propagates the current context to a carrier hash.
81 82 83 84 85 86 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 81 def propagate_context(ctx_carrier = {}, service_name: false) ctx_carrier.tap do |carrier| ::OpenTelemetry.propagation.inject(carrier) ctx_carrier[:service] = Rails.application.class.module_parent.name if service_name end.with_indifferent_access end |
#with_otl_span(name) { ... } ⇒ Object
Executes a block within a new span.
70 71 72 73 74 |
# File 'lib/yes/core/open_telemetry/trackable.rb', line 70 def with_otl_span(name, &) return yield unless otl_tracer otl_tracer.in_span(name, &) end |