Class: Datadog::OpenTelemetry::SDK::MetricsExporter

Inherits:
OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter
  • Object
show all
Defined in:
lib/datadog/opentelemetry/sdk/metrics_exporter.rb

Constant Summary collapse

METRIC_EXPORT_ATTEMPTS =
'otel.metrics_export_attempts'
METRIC_EXPORT_SUCCESSES =
'otel.metrics_export_successes'
METRIC_EXPORT_FAILURES =
'otel.metrics_export_failures'

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, timeout:, headers:, protocol:) ⇒ MetricsExporter

Returns a new instance of MetricsExporter.



13
14
15
16
# File 'lib/datadog/opentelemetry/sdk/metrics_exporter.rb', line 13

def initialize(endpoint:, timeout:, headers:, protocol:)
  super(endpoint: endpoint, timeout: timeout, headers: headers)
  @telemetry_tags = {'protocol' => protocol, 'encoding' => 'protobuf'}
end

Instance Method Details

#export(metrics, timeout: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/datadog/opentelemetry/sdk/metrics_exporter.rb', line 18

def export(metrics, timeout: nil)
  telemetry&.inc('tracers', METRIC_EXPORT_ATTEMPTS, 1, tags: @telemetry_tags)
  result = super
  metric_name = (result == 0) ? METRIC_EXPORT_SUCCESSES : METRIC_EXPORT_FAILURES
  telemetry&.inc('tracers', metric_name, 1, tags: @telemetry_tags)
  result
rescue => e
  Datadog.logger.error("Failed to export OpenTelemetry Metrics:  #{e.class}: #{e}")
  telemetry&.inc('tracers', METRIC_EXPORT_FAILURES, 1, tags: @telemetry_tags)
  raise
end