Class: Datadog::OpenTelemetry::SDK::SpanProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/opentelemetry/sdk/span_processor.rb

Overview

Keeps OpenTelemetry spans in sync with the Datadog execution context. Also responsible for flushing spans when their are finished.

Instance Method Summary collapse

Instance Method Details

#force_flush(timeout: nil) ⇒ Integer

Export all ended spans to the configured ‘Exporter` that have not yet been exported.

This method should only be called in cases where it is absolutely necessary, such as when using some FaaS providers that may suspend the process after an invocation, but before the ‘Processor` exports the completed spans.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.

Returns:

  • (Integer)

    Export::SUCCESS if no error occurred, Export::FAILURE if a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.



58
59
60
61
# File 'lib/datadog/opentelemetry/sdk/span_processor.rb', line 58

def force_flush(timeout: nil)
  writer.force_flush(timeout: timeout) if writer.respond_to? :force_flush
  Export::SUCCESS
end

#on_finish(span) ⇒ Object

Called when a Span is ended, if the Span#recording? returns true.

This method is called synchronously on the execution thread, should not throw or block the execution thread.

Parameters:

  • span (Span)

    the Span that just ended.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/datadog/opentelemetry/sdk/span_processor.rb', line 34

def on_finish(span)
  unless span.events.nil?
    span.datadog_span.span_events = span.events.map do |event|
      Datadog::Tracing::SpanEvent.new(
        event.name,
        attributes: event.attributes,
        time_unix_nano: event.timestamp
      )
    end
  end
  span.datadog_span.finish(ns_to_time(span.end_timestamp))
end

#on_start(span, parent_context) ⇒ Object

Called when a Span is started, if the Span#recording? returns true.

This method is called synchronously on the execution thread, should not throw or block the execution thread.

Parameters:

  • span (Span)

    the Span that just started.

  • parent_context (Context)

    the parent Context of the newly started span.



23
24
25
# File 'lib/datadog/opentelemetry/sdk/span_processor.rb', line 23

def on_start(span, parent_context)
  create_matching_datadog_span(span, parent_context)
end

#shutdown(timeout: nil) ⇒ Integer

Called when TracerProvider#shutdown is called.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.

Returns:

  • (Integer)

    Export::SUCCESS if no error occurred, Export::FAILURE if a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.



68
69
70
71
# File 'lib/datadog/opentelemetry/sdk/span_processor.rb', line 68

def shutdown(timeout: nil)
  writer.stop
  Export::SUCCESS
end