Class: Datadog::OpenTracer::Span
- Inherits:
-
OpenTracing::Span
- Object
- OpenTracing::Span
- Datadog::OpenTracer::Span
- Defined in:
- lib/ddtrace/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.
8 9 10 11 |
# File 'lib/ddtrace/opentracer/span.rb', line 8 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.
5 6 7 |
# File 'lib/ddtrace/opentracer/span.rb', line 5 def datadog_span @datadog_span end |
Instance Method Details
#context ⇒ SpanContext
Span Context
23 24 25 |
# File 'lib/ddtrace/opentracer/span.rb', line 23 def context @span_context end |
#finish(end_time: Time.now) ⇒ Object
Finish the Datadog::OpenTracer::Span
93 94 95 |
# File 'lib/ddtrace/opentracer/span.rb', line 93 def finish(end_time: Time.now) datadog_span.finish(end_time) end |
#get_baggage_item(key) ⇒ String
Get a baggage item
60 61 62 |
# File 'lib/ddtrace/opentracer/span.rb', line 60 def get_baggage_item(key) context.baggage[key] end |
#log(event: nil, timestamp: Time.now, **fields) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/ddtrace/opentracer/span.rb', line 72 def log(event: nil, timestamp: Time.now, **fields) super # Log deprecation warning # If the fields specify an error if fields.key?(:'error.object') datadog_span.set_error(fields[:'error.object']) end end |
#log_kv(timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span
84 85 86 87 88 89 |
# File 'lib/ddtrace/opentracer/span.rb', line 84 def log_kv(timestamp: Time.now, **fields) # If the fields specify an error if fields.key?(:'error.object') datadog_span.set_error(fields[:'error.object']) end end |
#operation_name=(name) ⇒ Object
Set the name of the operation
16 17 18 |
# File 'lib/ddtrace/opentracer/span.rb', line 16 def operation_name=(name) datadog_span.name = name end |
#set_baggage_item(key, value) ⇒ Object
Set a baggage item on the span
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ddtrace/opentracer/span.rb', line 46 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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ddtrace/opentracer/span.rb', line 31 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::Ext::Errors::STATUS : 0 end tap { datadog_span.set_tag(key, value) } end |