Class: Datadog::DI::ProbeNotificationBuilder Private
- Inherits:
-
Object
- Object
- Datadog::DI::ProbeNotificationBuilder
- Defined in:
- lib/datadog/di/probe_notification_builder.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.
Builds probe status notification and snapshot payloads.
Constant Summary collapse
- NANOSECONDS =
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.
1_000_000_000- MILLISECONDS =
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.
1000
Instance Attribute Summary collapse
- #capture_expression_evaluator ⇒ Object readonly private
-
#guardrails_telemetry ⇒ GuardrailsTelemetry
readonly
private
The guardrails metric emitter.
- #logger ⇒ Object readonly private
- #serializer ⇒ Object readonly private
- #settings ⇒ Object readonly private
-
#telemetry ⇒ Datadog::Core::Telemetry::Component?
readonly
private
The telemetry component evaluation timeouts are counted through.
Instance Method Summary collapse
- #build_condition_evaluation_failed(context, expression, exception) ⇒ Object private
- #build_disabled(probe, duration) ⇒ Object private
- #build_emitting(probe) ⇒ Object private
- #build_errored(probe, exc) ⇒ Object private
-
#build_executed(context) ⇒ Object
private
Duration is in seconds.
- #build_installed(probe) ⇒ Object private
- #build_received(probe) ⇒ Object private
- #build_snapshot(context) ⇒ Object private
-
#build_status(probe, message:, status:, exception: nil) ⇒ Hash
private
Builds a probe status notification payload.
-
#initialize(settings, serializer, logger, capture_expression_evaluator:, guardrails_telemetry:, telemetry:) ⇒ void
constructor
private
Initializes the builder.
Constructor Details
#initialize(settings, serializer, logger, capture_expression_evaluator:, guardrails_telemetry:, telemetry:) ⇒ 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 builder.
24 25 26 27 28 29 30 31 32 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 24 def initialize(settings, serializer, logger, capture_expression_evaluator:, guardrails_telemetry:, telemetry:) @settings = settings @serializer = serializer @logger = logger @capture_expression_evaluator = capture_expression_evaluator @guardrails_telemetry = guardrails_telemetry @telemetry = telemetry end |
Instance Attribute Details
#capture_expression_evaluator ⇒ 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.
40 41 42 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 40 def capture_expression_evaluator @capture_expression_evaluator end |
#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.
44 45 46 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 44 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.
38 39 40 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 38 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.
36 37 38 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 36 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.
34 35 36 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 34 def settings @settings 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 telemetry component evaluation timeouts are counted through.
48 49 50 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 48 def telemetry @telemetry end |
Instance Method Details
#build_condition_evaluation_failed(context, expression, exception) ⇒ 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.
170 171 172 173 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 170 def build_condition_evaluation_failed(context, expression, exception) error = EvaluationFailure.new(expr: expression.dsl_expr, message: "#{exception.class}: #{exception}") build_snapshot_base(context, evaluation_errors: [error]) end |
#build_disabled(probe, duration) ⇒ 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.
75 76 77 78 79 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 75 def build_disabled(probe, duration) build_status(probe, message: "Probe #{probe.id} was disabled because it consumed #{duration} seconds of CPU time in DI processing", status: "ERROR") end |
#build_emitting(probe) ⇒ 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.
62 63 64 65 66 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 62 def build_emitting(probe) build_status(probe, message: "Probe #{probe.id} is emitting", status: "EMITTING") end |
#build_errored(probe, exc) ⇒ 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.
68 69 70 71 72 73 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 68 def build_errored(probe, exc) build_status(probe, message: "Instrumentation for probe #{probe.id} failed: #{exc}", status: "ERROR", exception: exc) end |
#build_executed(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.
Duration is in seconds. path is the actual path of the instrumented file.
83 84 85 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 83 def build_executed(context) build_snapshot(context) end |
#build_installed(probe) ⇒ 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.
56 57 58 59 60 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 56 def build_installed(probe) build_status(probe, message: "Probe #{probe.id} has been instrumented correctly", status: "INSTALLED") end |
#build_received(probe) ⇒ 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.
50 51 52 53 54 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 50 def build_received(probe) build_status(probe, message: "Probe #{probe.id} has been received correctly", status: "RECEIVED") end |
#build_snapshot(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.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 90 def build_snapshot(context) probe = context.probe if probe.capture_snapshot? && !context.target_self raise ArgumentError, "Asked to build snapshot with snapshot capture but target_self is nil" end # TODO also verify that non-capturing probe does not pass # snapshot or vars/args into this method capture_expression_evaluation_errors = [] captures = if probe.capture_snapshot? snapshot_limits = probe.snapshot_serializer_limits(settings) serialization_deadline = serializer.serialization_deadline if probe.method? return_arguments = { "@return": serializer.serialize_value(context.return_value, deadline: serialization_deadline, **snapshot_limits), self: serializer.serialize_value(context.target_self, deadline: serialization_deadline, **snapshot_limits), } { entry: { arguments: context.serialized_entry_args, }, return: { arguments: return_arguments, throwable: context.exception ? serialize_throwable(context.exception) : nil, }, } elsif probe.line? { lines: (locals = context.serialized_locals(serialization_deadline: serialization_deadline)) && { probe.line_no => { locals: locals, arguments: {self: serializer.serialize_value(context.target_self, deadline: serialization_deadline, **snapshot_limits)}, }, }, } end elsif probe.capture_expressions? if probe.method? if probe.evaluate_at_entry? captured_block = context.entry_capture_expressions || {} capture_expression_evaluation_errors = context.entry_capture_evaluation_errors || [] { entry: {captureExpressions: captured_block}, } else capture_evaluation_result = capture_expression_evaluator.evaluate(probe, context) captured_block = capture_evaluation_result.serialized_values capture_expression_evaluation_errors = capture_evaluation_result.errors { return: { captureExpressions: captured_block, throwable: context.exception ? serialize_throwable(context.exception) : nil, }, } end elsif probe.line? capture_evaluation_result = capture_expression_evaluator.evaluate(probe, context) captured_block = capture_evaluation_result.serialized_values capture_expression_evaluation_errors = capture_evaluation_result.errors { lines: { probe.line_no => {captureExpressions: captured_block}, }, } end end = nil evaluation_errors = [] if segments = probe.template_segments , evaluation_errors = evaluate_template(segments, context, evaluation_deadline: serializer.evaluation_deadline) end evaluation_errors.concat(capture_expression_evaluation_errors) build_snapshot_base(context, evaluation_errors: evaluation_errors, message: , captures: captures) end |
#build_status(probe, message:, status:, exception: nil) ⇒ 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.
Builds a probe status notification payload.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/datadog/di/probe_notification_builder.rb', line 182 def build_status(probe, message:, status:, exception: nil) diagnostics = { probeId: probe.id, probeVersion: 0, runtimeId: Core::Environment::Identity.id, parentId: nil, status: status, } # Exception field is required by the backend for ERROR status. # If the ERROR status is sent without the exception field, the status # appears to be completely ignored by the backend. # Note: The Go DI implementation does not send the top-level message # field at all when sending error statuses. if status == "ERROR" diagnostics[:exception] = { # steep:ignore type: exception ? exception.class.name : "Error", message: exception ? exception. : , } end { service: settings.service, timestamp: , message: , ddsource: "dd_debugger", debugger: { diagnostics: diagnostics, }, } end |