Module: NewRelic::Agent::OpenTelemetry::AbstractSegmentPatch
- Defined in:
- lib/new_relic/agent/opentelemetry/abstract_segment_patch.rb
Constant Summary collapse
- MAX_SPAN_LINKS =
100- SPAN_LINKS_DROPPED_METRIC =
'Supportability/Ruby/SpanEvent/Links/Dropped'- MAX_SPAN_EVENTS =
100- SPAN_EVENTS_DROPPED_METRIC =
'Supportability/Ruby/SpanEvent/Events/Dropped'
Instance Method Summary collapse
-
#add_span_event_event(name, attributes: nil, timestamp: nil) ⇒ Object
This method adds SpanEvent events to a Span event/Segment.
- #add_span_link(link) ⇒ Object
- #force_finish ⇒ Object
-
#span_events ⇒ Object
Used to reference SpanEvent events associated with a Span/Segment.
- #span_links ⇒ Object
Instance Method Details
#add_span_event_event(name, attributes: nil, timestamp: nil) ⇒ Object
This method adds SpanEvent events to a Span event/Segment. A SpanEvent is used to denote a meaningful, singular point in a Span’s duration.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/new_relic/agent/opentelemetry/abstract_segment_patch.rb', line 30 def add_span_event_event(name, attributes: nil, timestamp: nil) @span_events ||= [] if @span_events.size >= MAX_SPAN_EVENTS NewRelic::Agent.record_metric(SPAN_EVENTS_DROPPED_METRIC, 1) return end # Normalize to Float seconds at storage time. # OTel may pass Integer nanoseconds; New Relic uses Float seconds. ts = if .nil? Process.clock_gettime(Process::CLOCK_REALTIME) elsif .is_a?(Integer) / 1_000_000_000.0 else end @span_events << {name: name, attributes: attributes, timestamp: ts} end |
#add_span_link(link) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/new_relic/agent/opentelemetry/abstract_segment_patch.rb', line 14 def add_span_link(link) @span_links ||= [] if @span_links.size >= MAX_SPAN_LINKS NewRelic::Agent.record_metric(SPAN_LINKS_DROPPED_METRIC, 1) return end @span_links << link end |
#force_finish ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/new_relic/agent/opentelemetry/abstract_segment_patch.rb', line 56 def force_finish if instance_variable_defined?(:@otel_span) otel_span = instance_variable_get(:@otel_span) if otel_span.respond_to?(:finish) && !otel_span.instance_variable_get(:@finished) begin otel_span.finish return if finished? rescue => e NewRelic::Agent.logger.debug("Error finishing OpenTelemetry span during force_finish: #{e}") end end end super end |
#span_events ⇒ Object
Used to reference SpanEvent events associated with a Span/Segment
52 53 54 |
# File 'lib/new_relic/agent/opentelemetry/abstract_segment_patch.rb', line 52 def span_events instance_variable_defined?(:@span_events) ? @span_events : NewRelic::EMPTY_ARRAY end |
#span_links ⇒ Object
23 24 25 |
# File 'lib/new_relic/agent/opentelemetry/abstract_segment_patch.rb', line 23 def span_links instance_variable_defined?(:@span_links) ? @span_links : NewRelic::EMPTY_ARRAY end |