Class: Datadog::DI::Context Private

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

Contains local and instance variables used when evaluating expressions in DI Expression Language.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(probe:, settings:, serializer:, locals: nil, target_self: nil, path: nil, caller_locations: nil, serialized_entry_args: nil, entry_capture_expressions: nil, entry_capture_evaluation_errors: nil, admission_trace: nil, admission_span: nil, return_value: nil, duration: nil, exception: 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 context with the probe hit's state.

Parameters:

  • probe (Datadog::DI::Probe) —

    the probe whose hit is being evaluated

  • settings (Datadog::Core::Configuration::Settings) —

    the current configuration settings

  • serializer (Datadog::DI::Serializer) —

    the serializer for captured values

  • locals (Hash{Symbol => Object}, nil) (defaults to: nil) —

    local variables captured at the probe hit

  • target_self (Object, nil) (defaults to: nil) —

    the object the instrumented method runs on

  • path (String, nil) (defaults to: nil) —

    actual path of the instrumented file

  • caller_locations (Array<Thread::Backtrace::Location>, nil) (defaults to: nil) —

    stack frames captured at the probe hit

  • serialized_entry_args (Hash{Symbol => Object}, nil) (defaults to: nil) —

    entry arguments of the instrumented method, in serialized form

  • entry_capture_expressions (Hash{String => Object}, nil) (defaults to: nil) —

    entry capture expressions, in serialized form

  • entry_capture_evaluation_errors (Array<Datadog::DI::EvaluationFailure>, nil) (defaults to: nil) —

    failures from evaluating the entry capture expressions

  • admission_trace (Datadog::Tracing::TraceOperation, nil) (defaults to: nil) —

    the APM trace active when the sampling gate admitted the probe hit

  • admission_span (Datadog::Tracing::SpanOperation, nil) (defaults to: nil) —

    the APM span active when the sampling gate admitted the probe hit

  • return_value (Object, nil) (defaults to: nil) —

    the instrumented method's return value, for a method probe

  • duration (Float, nil) (defaults to: nil) —

    the instrumented method's execution time, in seconds, for a method probe

  • exception (Exception, nil) (defaults to: nil) —

    the exception raised by the instrumented method, for a method probe



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
69
# File 'lib/datadog/di/context.rb', line 42

def initialize(probe:, settings:, serializer:, locals: nil,
  # In Ruby everything is a method, therefore we should always have
  # a target self. However, if we are not capturing a snapshot,
  # there is no need to pass in the target self.
  target_self: nil,
  path: nil, caller_locations: nil,
  serialized_entry_args: nil,
  entry_capture_expressions: nil,
  entry_capture_evaluation_errors: nil,
  admission_trace: nil,
  admission_span: nil,
  return_value: nil, duration: nil, exception: nil)
  @probe = probe
  @settings = settings
  @serializer = serializer
  @locals = locals
  @target_self = target_self
  @path = path
  @caller_locations = caller_locations
  @serialized_entry_args = serialized_entry_args
  @entry_capture_expressions = entry_capture_expressions
  @entry_capture_evaluation_errors = entry_capture_evaluation_errors
  @admission_trace = admission_trace
  @admission_span = admission_span
  @return_value = return_value
  @duration = duration
  @exception = exception
end

Instance Attribute Details

#admission_span ⇒ Datadog::Tracing::SpanOperation? (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 APM span active when the probe's hit was admitted by the sampling gate, for a method probe; nil when the hit carried no admission span.



103
104
105
# File 'lib/datadog/di/context.rb', line 103

def admission_span
  @admission_span
end

#admission_trace ⇒ Datadog::Tracing::TraceOperation? (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 APM trace active when the probe's hit was admitted by the sampling gate, for a method probe; nil when the hit carried no admission trace.



96
97
98
# File 'lib/datadog/di/context.rb', line 96

def admission_trace
  @admission_trace
end

#caller_locations ⇒ 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.

TODO check how many stack frames we should be keeping/sending, this should be all frames for enriched probes and no frames for non-enriched probes?



83
84
85
# File 'lib/datadog/di/context.rb', line 83

def caller_locations
  @caller_locations
end

#duration ⇒ 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.

How long the method took to execute, for a method probe



109
110
111
# File 'lib/datadog/di/context.rb', line 109

def duration
  @duration
end

#entry_capture_evaluation_errors ⇒ 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.



89
90
91
# File 'lib/datadog/di/context.rb', line 89

def entry_capture_evaluation_errors
  @entry_capture_evaluation_errors
end

#entry_capture_expressions ⇒ 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.



87
88
89
# File 'lib/datadog/di/context.rb', line 87

def entry_capture_expressions
  @entry_capture_expressions
end

#exception ⇒ 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.

Exception raised by the method, if any, for a method probe



112
113
114
# File 'lib/datadog/di/context.rb', line 112

def exception
  @exception
end

#locals ⇒ 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.



74
75
76
# File 'lib/datadog/di/context.rb', line 74

def locals
  @locals
end

#path ⇒ 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.

Actual path of the instrumented file.



78
79
80
# File 'lib/datadog/di/context.rb', line 78

def path
  @path
end

#probe ⇒ 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.



71
72
73
# File 'lib/datadog/di/context.rb', line 71

def probe
  @probe
end

#return_value ⇒ 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.

Return value for the method, for a method probe



106
107
108
# File 'lib/datadog/di/context.rb', line 106

def return_value
  @return_value
end

#serialized_entry_args ⇒ 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.



85
86
87
# File 'lib/datadog/di/context.rb', line 85

def serialized_entry_args
  @serialized_entry_args
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.



73
74
75
# File 'lib/datadog/di/context.rb', line 73

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.



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

def settings
  @settings
end

#target_self ⇒ 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.



75
76
77
# File 'lib/datadog/di/context.rb', line 75

def target_self
  @target_self
end

Instance Method Details

#fetch(var_name) ⇒ 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.



124
125
126
127
128
129
130
# File 'lib/datadog/di/context.rb', line 124

def fetch(var_name)
  unless locals
    # TODO return "undefined" instead?
    return nil
  end
  locals[var_name.to_sym]
end

#fetch_ivar(var_name) ⇒ 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.



132
133
134
# File 'lib/datadog/di/context.rb', line 132

def fetch_ivar(var_name)
  target_self.instance_variable_get(var_name)
end

#serialized_locals(serialization_deadline:) ⇒ Hash{Symbol => Hash}?

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 locals captured at the probe hit in serialized form, or nil when no locals were captured.

Parameters:

  • serialization_deadline (Float) —

    absolute capture deadline in monotonic clock seconds

Returns:

  • (Hash{Symbol => Hash}, nil) —

    serialized locals keyed by variable name



119
120
121
122
# File 'lib/datadog/di/context.rb', line 119

def serialized_locals(serialization_deadline:)
  # TODO cache?
  locals && serializer.serialize_vars(locals, deadline: serialization_deadline, **probe.snapshot_serializer_limits(settings))
end