Class: Datadog::OpenTracer::Span
- Inherits:
-
OpenTracing::Span
- Object
- OpenTracing::Span
- Datadog::OpenTracer::Span
- Defined in:
- lib/datadog/opentracer/span.rb
Overview
OpenTracing adapter for Datadog::Span
Instance Attribute Summary collapse
-
#datadog_span ⇒ Object
readonly
Returns the value of attribute datadog_span.
Instance Method Summary collapse
-
#context ⇒ SpanContext
Span Context.
-
#finish(end_time: Time.now) ⇒ Object
Finish the Span.
-
#get_baggage_item(key) ⇒ String
Get a baggage item.
-
#initialize(datadog_span:, span_context:) ⇒ Span
constructor
A new instance of Span.
-
#log(event: nil, timestamp: Time.now, **fields) ⇒ Object
deprecated
Deprecated.
Use #log_kv instead.
-
#log_kv(timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span.
-
#operation_name=(name) ⇒ Object
Set the name of the operation.
-
#set_baggage_item(key, value) ⇒ Object
Set a baggage item on the span.
-
#set_tag(key, value) ⇒ Object
Set a tag value on this span a String, Numeric, or Boolean it will be encoded with to_s.
Constructor Details
#initialize(datadog_span:, span_context:) ⇒ Span
Returns a new instance of Span.
13 14 15 16 |
# File 'lib/datadog/opentracer/span.rb', line 13 def initialize(datadog_span:, span_context:) @datadog_span = datadog_span @span_context = span_context end |
Instance Attribute Details
#datadog_span ⇒ Object (readonly)
Returns the value of attribute datadog_span.
10 11 12 |
# File 'lib/datadog/opentracer/span.rb', line 10 def datadog_span @datadog_span end |
Instance Method Details
#context ⇒ SpanContext
Span Context
28 29 30 |
# File 'lib/datadog/opentracer/span.rb', line 28 def context @span_context end |
#finish(end_time: Time.now) ⇒ Object
Finish the Datadog::OpenTracer::Span
94 95 96 |
# File 'lib/datadog/opentracer/span.rb', line 94 def finish(end_time: Time.now) datadog_span.finish(end_time) end |
#get_baggage_item(key) ⇒ String
Get a baggage item
65 66 67 |
# File 'lib/datadog/opentracer/span.rb', line 65 def get_baggage_item(key) context.baggage[key] end |
#log(event: nil, timestamp: Time.now, **fields) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/datadog/opentracer/span.rb', line 77 def log(event: nil, timestamp: Time.now, **fields) super # Log deprecation warning # If the fields specify an error datadog_span.set_error(fields[:'error.object']) if fields.key?(:'error.object') end |
#log_kv(timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span
87 88 89 90 |
# File 'lib/datadog/opentracer/span.rb', line 87 def log_kv(timestamp: Time.now, **fields) # If the fields specify an error datadog_span.set_error(fields[:'error.object']) if fields.key?(:'error.object') end |
#operation_name=(name) ⇒ Object
Set the name of the operation
21 22 23 |
# File 'lib/datadog/opentracer/span.rb', line 21 def operation_name=(name) datadog_span.name = name end |
#set_baggage_item(key, value) ⇒ Object
Set a baggage item on the span
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/datadog/opentracer/span.rb', line 51 def set_baggage_item(key, value) tap do # SpanContext is immutable, so to make changes # build a new span context. @span_context = SpanContextFactory.clone( span_context: context, baggage: { key => value } ) end end |
#set_tag(key, value) ⇒ Object
Set a tag value on this span a String, Numeric, or Boolean it will be encoded with to_s
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/datadog/opentracer/span.rb', line 36 def set_tag(key, value) # Special cases to convert opentracing tags to datadog tags case key when 'error' # Opentracing supports and `error: <bool>` tag, we need to convert to span status # DEV: Do not return, we want to still set the `error` tag as they requested datadog_span.status = value ? Datadog::Tracing::Metadata::Ext::Errors::STATUS : 0 end tap { datadog_span.set_tag(key, value) } end |