Class: NewRelic::Agent::OpenTelemetry::Trace::Tracer
- Inherits:
-
OpenTelemetry::Trace::Tracer
- Object
- OpenTelemetry::Trace::Tracer
- NewRelic::Agent::OpenTelemetry::Trace::Tracer
- Defined in:
- lib/new_relic/agent/opentelemetry/trace/tracer.rb
Constant Summary collapse
- VALID_KINDS =
[:server, :client, :consumer, :producer, :internal, nil].freeze
- KINDS_THAT_START_TRANSACTIONS =
%i[server consumer].freeze
- KINDS_THAT_DO_NOT_START_TXNS_WITHOUT_REMOTE_PARENT =
[:client, :producer, :internal, nil].freeze
Instance Method Summary collapse
- #in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil) ⇒ Object
-
#initialize(name = nil, version = nil) ⇒ Tracer
constructor
A new instance of Tracer.
- #start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil) ⇒ Object
Methods included from Segments::Server
#create_server_transaction_name, #update_request_attributes
Methods included from Segments::Datastore
Methods included from Segments::HttpExternal
Constructor Details
#initialize(name = nil, version = nil) ⇒ Tracer
Returns a new instance of Tracer.
22 23 24 25 |
# File 'lib/new_relic/agent/opentelemetry/trace/tracer.rb', line 22 def initialize(name = nil, version = nil) @name = name || '' @version = version || '' end |
Instance Method Details
#in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/new_relic/agent/opentelemetry/trace/tracer.rb', line 48 def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil) span = nil span = start_span(name, attributes: attributes, links: links, start_timestamp: , kind: kind) ::OpenTelemetry::Trace.with_span(span) { |s, c| yield(s, c) } rescue => e # TODO: Update for segment errors if finishable is a segment NewRelic::Agent.notice_error(e) raise ensure span&.finish end |
#start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/new_relic/agent/opentelemetry/trace/tracer.rb', line 27 def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil) parent_otel_context = ::OpenTelemetry::Trace.current_span(with_parent).context return ::OpenTelemetry::Trace::Span::INVALID if should_not_create_telemetry?(parent_otel_context, kind) finishable = if can_start_transaction?(parent_otel_context, kind) start_transaction_from_otel(name, parent_otel_context, kind, attributes: attributes) else start_segment_from_otel(name: name, attributes: attributes, start_timestamp: , kind: kind) end otel_span = get_otel_span_from_finishable(finishable) otel_span.finishable = finishable otel_span.status = ::OpenTelemetry::Trace::Status.unset add_remote_context_to_otel_span(otel_span, parent_otel_context) otel_span.add_instrumentation_scope(@name, @version) otel_span.add_attributes(attributes) if attributes otel_span end |