Class: Datadog::DI::CaptureExpressionEvaluator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/di/capture_expression_evaluator.rb,
lib/datadog/di/capture_expression_evaluator/result.rb

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.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings:, serializer:, logger:, guardrails_telemetry:, telemetry: 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.

Initializes the evaluator.

Parameters:



23
24
25
26
27
28
29
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 23

def initialize(settings:, serializer:, logger:, guardrails_telemetry:, telemetry: nil)
  @settings = settings
  @serializer = serializer
  @logger = logger
  @guardrails_telemetry = guardrails_telemetry
  @telemetry = telemetry
end

Instance Attribute Details

#guardrails_telemetry ⇒ GuardrailsTelemetry (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 guardrails metric emitter.

Returns:



39
40
41
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 39

def guardrails_telemetry
  @guardrails_telemetry
end

#logger ⇒ Object (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.



35
36
37
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 35

def logger
  @logger
end

#serializer ⇒ Object (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.



33
34
35
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 33

def serializer
  @serializer
end

#settings ⇒ Object (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.



31
32
33
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 31

def settings
  @settings
end

#telemetry ⇒ Object (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.



41
42
43
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 41

def telemetry
  @telemetry
end

Instance Method Details

#evaluate(probe, context) ⇒ Result

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.

Evaluates each of the probe's capture expressions against the given context, serializing the captured values under one capture deadline resolved through the serializer and shared across all expressions. Each expression resolves its own evaluation deadline immediately before its evaluation and is evaluated under the earlier of that deadline and the capture deadline, so the capture expressions together stay within the capture budget. An expression the capture budget stops is reported as not captured; an expression that fails to evaluate or serialize otherwise contributes an entry to the returned errors.

Parameters:

  • probe (Probe) —

    the probe whose capture expressions are evaluated

  • context (Context) —

    evaluation context the expressions are evaluated against

Returns:

  • (Result) —

    the evaluation result: the serialized values keyed by capture expression name and the errors of the expressions that failed to evaluate or serialize



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 59

def evaluate(probe, context)
  deadline = serializer.serialization_deadline

  output = {}
  evaluation_errors = []

  probe.capture_expressions.each do |capture_expression|
    name = capture_expression.name

    if capture_deadline_passed?(deadline)
      record_capture_timeout(output, name, probe)
      next
    end

    begin
      evaluation_deadline = [serializer.evaluation_deadline, deadline].min
      value = capture_expression.expr.evaluate(context, evaluation_deadline: evaluation_deadline)
      limits = CaptureLimits.resolve(
        expr_limits: capture_expression.limits,
        probe: probe,
        settings: settings,
      )
      output[name] = serializer.serialize_value(
        value, name: name,
        depth: limits[:depth],
        attribute_count: limits[:attribute_count],
        length: limits[:length],
        collection_size: limits[:collection_size],
        deadline: deadline,
      )
    rescue Exception => exc # standard:disable Lint/RescueException
      Datadog::DI.reraise_if_fatal(exc)
      if exc.is_a?(DI::Error::EvaluationTimeout) && capture_deadline_passed?(deadline)
        record_capture_timeout(output, name, probe)
        next
      end
      DI.report_evaluation_timeout(
        telemetry: telemetry, guardrails_telemetry: guardrails_telemetry, logger: logger,
        probe: probe, kind: "capture expression", exc: exc,
      )
      evaluation_errors << EvaluationFailure.new(expr: name, message: "#{exc.class}: #{exc.message}")
      logger.debug do
        "di: probe #{probe.id}: capture expression #{name}: evaluation failed: #{exc.class}: #{exc.message}"
      end
      telemetry&.report(exc, description: "DI capture-expression evaluation failed")
    end
  end

  Result.new(serialized_values: output, errors: evaluation_errors)
end