Class: Datadog::Tracing::Transport::Telemetry

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/transport/telemetry.rb

Direct Known Subclasses

HTTP::Telemetry, Native::Telemetry

Constant Summary collapse

COUNTS =

Observation schema: Symbol keys with non-negative Integer values. COUNTS maps per-send count deltas to [metric name, additional tags]. :bytes_sent is one successful payload's byte-size distribution sample; record each payload separately rather than summing its samples. :responses_count requires :status_code; omit both when the code is unknown. Missing and zero measurements emit nothing. All metrics use namespace "tracers" and common: true; trace_* metrics gain src_library:, while span metrics keep their source-free tags.

{
  requests_count: ["trace_api.requests", []],
  errors_network: ["trace_api.errors", ["type:network"]],
  errors_timeout: ["trace_api.errors", ["type:timeout"]],
  errors_status_code: ["trace_api.errors", ["type:status_code"]],
  chunks_sent: ["trace_chunks_sent", []],
  chunks_dropped_serialization_error: ["trace_chunks_dropped", ["reason:serialization_error"]],
  chunks_dropped_send_failure: ["trace_chunks_dropped", ["reason:send_failure"]],
  chunks_dropped_payload_too_large: ["trace_chunks_dropped", ["reason:payload_too_large"]],
  chunks_dropped_cancelled: ["trace_chunks_dropped", ["reason:cancelled"]],
  spans_enqueued_for_serialization: ["spans_enqueued_for_serialization", []],
  spans_dropped_serialization_error: ["spans_dropped", ["reason:serialization_error"]],
  spans_dropped_api_error: ["spans_dropped", ["reason:api_error"]],
  spans_dropped_payload_too_large: ["spans_dropped", ["reason:payload_too_large"]],
  spans_dropped_cancelled: ["spans_dropped", ["reason:cancelled"]],
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, source:) ⇒ Telemetry

Returns a new instance of Telemetry.



34
35
36
37
38
39
40
# File 'lib/datadog/tracing/transport/telemetry.rb', line 34

def initialize(client, source:)
  @client = client
  @source_tags = ["src_library:#{source}"]
  @counts = COUNTS.map do |key, (name, tags)|
    [key, name, name.start_with?("trace_") ? @source_tags + tags : tags]
  end
end

Instance Attribute Details

#client=(value) ⇒ Object (writeonly)

: Hash[Symbol, [String, Array[String]]]



32
33
34
# File 'lib/datadog/tracing/transport/telemetry.rb', line 32

def client=(value)
  @client = value
end

Instance Method Details

#record(observations) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog/tracing/transport/telemetry.rb', line 42

def record(observations)
  client = @client
  return unless client.enabled?

  @counts.each do |key, name, tags|
    value = observations.fetch(key, 0)
    client.inc("tracers", name, value, tags: tags) if value > 0
  end
  bytes = observations.fetch(:bytes_sent, 0)
  client.distribution("tracers", "trace_api.bytes", bytes, tags: @source_tags) if bytes > 0
  responses = observations.fetch(:responses_count, 0)
  if responses > 0
    client.inc("tracers", "trace_api.responses", responses,
      tags: @source_tags + ["status_code:#{observations.fetch(:status_code)}"])
  end
  nil
rescue
  nil
end