Class: Datadog::DI::CaptureExpressionEvaluator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/di/capture_expression_evaluator.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.

Constant Summary collapse

TELEMETRY_NAMESPACE =

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.

"dynamic_instrumentation"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings:, serializer:, logger:, telemetry: nil) ⇒ CaptureExpressionEvaluator

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 a new instance of CaptureExpressionEvaluator.



12
13
14
15
16
17
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 12

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

Instance Attribute Details

#loggerObject (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.



23
24
25
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 23

def logger
  @logger
end

#serializerObject (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.



21
22
23
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 21

def serializer
  @serializer
end

#settingsObject (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.



19
20
21
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 19

def settings
  @settings
end

#telemetryObject (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.



25
26
27
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 25

def telemetry
  @telemetry
end

Instance Method Details

#evaluate(probe, context) ⇒ Object

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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/datadog/di/capture_expression_evaluator.rb', line 27

def evaluate(probe, context)
  budget_ns = settings.dynamic_instrumentation.max_time_to_serialize_ms * 1_000_000
  deadline_ns = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :nanosecond) + budget_ns

  output = {}
  evaluation_errors = []

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

    if ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :nanosecond) >= deadline_ns
      output[name] = {notCapturedReason: "timeout"}
      telemetry&.inc(TELEMETRY_NAMESPACE, "capture_expressions_skipped_by_timeout", 1)
      next
    end

    begin
      value = capture_expression.expr.evaluate(context)
      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],
      )
    rescue Exception => exc # standard:disable Lint/RescueException
      Datadog::DI.reraise_if_fatal(exc)
      evaluation_errors << {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

  [output, evaluation_errors]
end