@@ -398,25 +398,125 @@ def assert_received_and_errored
398398 where : {
399399 typeName : 'EverythingFromRemoteConfigSpecTestClass' , methodName : 'target_method' ,
400400 } ,
401- when : { json : { foo : 'bar' } } ,
401+ when : { json : { foo : 'bar' } , dsl : '(expression)' } ,
402402 }
403403 end
404404
405405 let ( :propagate_all_exceptions ) { false }
406406
407- it 'catches the exception' do
407+ it 'catches the exception and reports probe status error ' do
408408 expect_lazy_log ( logger , :debug , /di: unhandled exception handling a probe in DI remote receiver: Datadog::DI::Error::InvalidExpression: Unknown operation: foo/ )
409409
410410 do_rc ( expect_add_probe : false )
411411 expect ( probe_manager . installed_probes . length ) . to eq 0
412412
413413 payload = payloads . first
414414 expect ( payload ) . to be_a ( Hash )
415+ expect ( payload ) . to match (
416+ ddsource : 'dd_debugger' ,
417+ debugger : {
418+ diagnostics : {
419+ parentId : nil ,
420+ probeId : '11' ,
421+ probeVersion : 0 ,
422+ runtimeId : String ,
423+ status : 'ERROR' ,
424+ } ,
425+ } ,
426+ path : '/debugger/v1/diagnostics' ,
427+ service : 'rspec' ,
428+ timestamp : Integer ,
429+ message : String ,
430+ )
415431 expect ( payload [ :message ] ) . to match (
416432 /Instrumentation for probe .* failed: Unknown operation: foo/ ,
417433 )
418434 end
419435 end
436+
437+ context 'when there is a message template' do
438+ let ( :probe_spec ) do
439+ {
440+ id : '11' , name : 'bar' , type : 'LOG_PROBE' ,
441+ where : {
442+ typeName : 'EverythingFromRemoteConfigSpecTestClass' , methodName : 'target_method' ,
443+ } ,
444+ segments : [
445+ # String segment
446+ { str : 'hello ' } ,
447+ # Expression segment - valid at runtime
448+ { json : { eq : [ { ref : '@ivar' } , 51 ] } , dsl : '(good expression)' } ,
449+ # Another expression which fails evaluation at runtime
450+ { json : { filter : [ { ref : '@ivar' } , 'x' ] } , dsl : '(failing expression)' } ,
451+ ] ,
452+ }
453+ end
454+
455+ let ( :expected_snapshot_payload ) do
456+ {
457+ path : '/debugger/v1/input' ,
458+ # We do not have active span/trace in the test.
459+ "dd.span_id" : nil ,
460+ "dd.trace_id" : nil ,
461+ "debugger.snapshot" : {
462+ captures : nil ,
463+ evaluationErrors : [
464+ { 'expr' => '(failing expression)' , 'message' => 'Datadog::DI::Error::ExpressionEvaluationError: Bad collection type for filter: NilClass' } ,
465+ ] ,
466+ id : LOWERCASE_UUID_REGEXP ,
467+ language : 'ruby' ,
468+ probe : {
469+ id : '11' ,
470+ location : {
471+ method : 'target_method' ,
472+ type : 'EverythingFromRemoteConfigSpecTestClass' ,
473+ } ,
474+ version : 0 ,
475+ } ,
476+ stack : Array ,
477+ timestamp : Integer ,
478+ } ,
479+ ddsource : 'dd_debugger' ,
480+ duration : Integer ,
481+ host : nil ,
482+ logger : {
483+ method : 'target_method' ,
484+ name : nil ,
485+ thread_id : nil ,
486+ thread_name : 'Thread.main' ,
487+ version : 2 ,
488+ } ,
489+ # false is the result of first expression evaluation
490+ # second expression fails evaluation
491+ message : 'hello false[evaluation error]' ,
492+ service : 'rspec' ,
493+ timestamp : Integer ,
494+ }
495+ end
496+
497+ it 'evaluates expressions and reports errors' do
498+ expect_lazy_log ( logger , :debug , /di: received log probe/ )
499+
500+ do_rc
501+ assert_received_and_installed
502+
503+ # invocation
504+
505+ expect ( EverythingFromRemoteConfigSpecTestClass . new . target_method ) . to eq 42
506+
507+ component . probe_notifier_worker . flush
508+
509+ # assertions
510+
511+ expect ( payloads . length ) . to eq 2
512+
513+ emitting_payload = payloads . shift
514+ expect ( emitting_payload ) . to match ( expected_emitting_payload )
515+
516+ snapshot_payload = payloads . shift
517+ expect ( order_hash_keys ( snapshot_payload ) ) . to match ( deep_stringify_keys ( order_hash_keys ( expected_snapshot_payload ) ) )
518+ end
519+ end
420520 end
421521
422522 context 'line probe' do
@@ -514,7 +614,7 @@ def assert_received_and_errored
514614 where : {
515615 sourceFile : 'hook_line_load.rb' , lines : [ 14 ] ,
516616 } ,
517- when : { json : { 'contains' => [ { 'ref' => 'bar' } , 'baz' ] } } ,
617+ when : { json : { 'contains' => [ { 'ref' => 'bar' } , 'baz' ] } , dsl : '(expression)' } ,
518618 }
519619 end
520620
0 commit comments