Class: OpenTelemetry::Exporters::Datadog::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/exporters/datadog/exporter.rb,
lib/opentelemetry/exporters/datadog/exporter/span_encoder.rb

Overview

SpanExporter allows different tracing services to export recorded data for sampled spans in their own format.

To export data an exporter MUST be registered to the TracerProvider using a DatadogSpanProcessorr.

Defined Under Namespace

Classes: SpanEncoder

Constant Summary collapse

DEFAULT_AGENT_URL =
'http://localhost:8126'
DEFAULT_SERVICE_NAME =
'my_service'

Instance Method Summary collapse

Constructor Details

#initialize(service_name: nil, agent_url: nil, env: nil, version: nil, tags: nil) ⇒ Exporter

Returns a new instance of Exporter.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/opentelemetry/exporters/datadog/exporter.rb', line 28

def initialize(service_name: nil, agent_url: nil, env: nil, version: nil, tags: nil)
  @shutdown = false
  @agent_url = agent_url || ENV.fetch('DD_TRACE_AGENT_URL', DEFAULT_AGENT_URL)
  @service = service_name || ENV.fetch('DD_SERVICE', DEFAULT_SERVICE_NAME)

  @env = env || ENV.fetch('DD_ENV', nil)
  @version = version || ENV.fetch('DD_VERSION', nil)
  @tags = tags || ENV.fetch('DD_TAGS', nil)

  @agent_writer = get_writer(@agent_url)

  @span_encoder = SpanEncoder.new
end

Instance Method Details

#export(spans) ⇒ Integer

Called to export sampled Spans.

Parameters:

  • spans (Enumerable<Span>)

    the list of sampled Spans to be exported.

Returns:

  • (Integer)

    the result of the export.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/opentelemetry/exporters/datadog/exporter.rb', line 47

def export(spans)
  return FAILURE if @shutdown

  if @agent_writer
    datadog_spans = @span_encoder.translate_to_datadog(spans, @service, @env, @version, @tags)
    @agent_writer.write(datadog_spans)
    SUCCESS
  else
    OpenTelemetry.logger.debug('Agent writer not set')
    FAILURE
  end
end

#shutdown(timeout: nil) ⇒ Object

Called when TracerProvider#shutdown is called, if this exporter is registered to a TracerProvider object.



62
63
64
# File 'lib/opentelemetry/exporters/datadog/exporter.rb', line 62

def shutdown(timeout: nil)
  @shutdown = true
end