Class: Datadog::DI::GuardrailsTelemetry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/di/guardrails_telemetry.rb,
lib/datadog/di/guardrails_telemetry/reason.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Telemetry reporter for the DI guardrails: the reason codes and the metric emitters.

Defined Under Namespace

Modules: Reason

Constant Summary collapse

EVENTS_SKIPPED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Skip count metric name, emitted under DI::TELEMETRY_NAMESPACE.

"events.skipped"
EVENTS_DROPPED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Drop count metric name, emitted under DI::TELEMETRY_NAMESPACE.

"events.dropped"
CAPTURE_INCOMPLETE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Incomplete-capture count metric name, emitted under DI::TELEMETRY_NAMESPACE.

"capture.incomplete"
QUEUE_DROPPED_BYTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Queue byte-count metric, emitted under DI::TELEMETRY_NAMESPACE.

"guardrails.queue.dropped_bytes"
EVENT_TYPE_SNAPSHOT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Tag value for probes that capture a full snapshot.

"snapshot"
EVENT_TYPE_LOG =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Tag value for probes that capture evaluated log output.

"log"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings:, logger:, telemetry:) ⇒ GuardrailsTelemetry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the reporter.

Parameters:



36
37
38
39
40
41
42
43
# File 'lib/datadog/di/guardrails_telemetry.rb', line 36

def initialize(settings:, logger:, telemetry:)
  @settings = settings
  @logger = logger
  @telemetry = telemetry
  @skipped_tags_memo = {}
  @dropped_tags_memo = {}
  @capture_incomplete_tags_memo = {}
end

Instance Attribute Details

#capture_incomplete_tags_memo ⇒ Hash{String => Hash{String => Hash{Symbol => String}}} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The memo of frozen tag hashes for emitted incomplete-capture metrics, keyed by reason and event type.

Returns:

  • (Hash{String => Hash{String => Hash{Symbol => String}}})


65
66
67
# File 'lib/datadog/di/guardrails_telemetry.rb', line 65

def capture_incomplete_tags_memo
  @capture_incomplete_tags_memo
end

#dropped_tags_memo ⇒ Hash{String => Hash{String => Hash{Symbol => String}}} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The memo of frozen tag hashes for emitted drop metrics, keyed by reason and event type.

Returns:

  • (Hash{String => Hash{String => Hash{Symbol => String}}})


61
62
63
# File 'lib/datadog/di/guardrails_telemetry.rb', line 61

def dropped_tags_memo
  @dropped_tags_memo
end

#logger ⇒ DI::Logger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The logger.

Returns:



50
51
52
# File 'lib/datadog/di/guardrails_telemetry.rb', line 50

def logger
  @logger
end

#settings ⇒ Datadog::Core::Configuration::Settings (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The tracer settings.



47
48
49
# File 'lib/datadog/di/guardrails_telemetry.rb', line 47

def settings
  @settings
end

#skipped_tags_memo ⇒ Hash{String => Hash{String => Hash{Symbol => String}}} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The memo of frozen tag hashes for emitted skip metrics without probe_id, keyed by reason and event type.

Returns:

  • (Hash{String => Hash{String => Hash{Symbol => String}}})


57
58
59
# File 'lib/datadog/di/guardrails_telemetry.rb', line 57

def skipped_tags_memo
  @skipped_tags_memo
end

#telemetry ⇒ Datadog::Core::Telemetry::Component? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The component the guardrails metrics are emitted through.



53
54
55
# File 'lib/datadog/di/guardrails_telemetry.rb', line 53

def telemetry
  @telemetry
end

Class Method Details

.probe_event_type_tag(probe) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the canonical event_type tag for a probe, derived from whether the probe captures a full snapshot.

Parameters:

  • probe (Probe) —

    the probe whose firing is being tagged

Returns:

  • (String) —

    EVENT_TYPE_SNAPSHOT or EVENT_TYPE_LOG



72
73
74
# File 'lib/datadog/di/guardrails_telemetry.rb', line 72

def self.probe_event_type_tag(probe)
  probe.capture_snapshot? ? EVENT_TYPE_SNAPSHOT : EVENT_TYPE_LOG
end

Instance Method Details

#capture_incomplete(reason:, event_type:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Emits the canonical debugger.capture.incomplete count metric for a capture limit enforced on a snapshot that is still sent.

Parameters:

  • reason (String) —

    a GuardrailsTelemetry::Reason constant naming the enforced capture limit

  • event_type (String) —

    the canonical event_type tag value



112
113
114
115
116
117
118
# File 'lib/datadog/di/guardrails_telemetry.rb', line 112

def capture_incomplete(reason:, event_type:)
  inc_metric(
    DI::TELEMETRY_NAMESPACE, CAPTURE_INCOMPLETE, 1,
    tags: capture_incomplete_tags(reason, event_type),
  )
  nil
end

#dropped(reason:, event_type:, bytes: nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Emits the canonical debugger.events.dropped count metric, and, when bytes is provided, the guardrails.queue.dropped_bytes count metric.

Parameters:

  • reason (String) —

    a GuardrailsTelemetry::Reason constant naming the drop cause

  • event_type (String) —

    the canonical event_type tag value

  • bytes (Integer, nil) (defaults to: nil) —

    encoded bytes discarded, when the drop site knows the count



99
100
101
102
103
104
# File 'lib/datadog/di/guardrails_telemetry.rb', line 99

def dropped(reason:, event_type:, bytes: nil)
  tags = dropped_tags(reason, event_type)
  inc_metric(DI::TELEMETRY_NAMESPACE, EVENTS_DROPPED, 1, tags: tags)
  inc_metric(DI::TELEMETRY_NAMESPACE, QUEUE_DROPPED_BYTES, bytes, tags: tags) if bytes
  nil
end

#skipped(reason:, probe:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Emits the canonical debugger.events.skipped count metric for a probe firing a guardrail rejected.

Parameters:

  • reason (String) —

    a GuardrailsTelemetry::Reason constant naming the skip cause

  • probe (Probe) —

    the probe whose firing was rejected



82
83
84
85
86
87
88
89
# File 'lib/datadog/di/guardrails_telemetry.rb', line 82

def skipped(reason:, probe:)
  probe_id = probe.id if Reason::PROBE_SCOPED_REASONS.include?(reason)
  inc_metric(
    DI::TELEMETRY_NAMESPACE, EVENTS_SKIPPED, 1,
    tags: skipped_tags(reason, self.class.probe_event_type_tag(probe), probe_id),
  )
  nil
end