From 6c6b009631674185804951501b5c116ce6daa52d Mon Sep 17 00:00:00 2001 From: Robert Laurin Date: Tue, 19 Sep 2023 15:42:46 -0500 Subject: [PATCH] feat: record action pack exceptions in metal --- .../action_pack/patches/action_controller/metal.rb | 4 ++++ .../action_pack/patches/action_controller/metal_test.rb | 3 +++ .../test/test_helpers/controllers/example_controller.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb index 6e3b17c9e..3e64931ed 100644 --- a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb +++ b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb @@ -16,6 +16,10 @@ def dispatch(name, request, response) if rack_span.recording? rack_span.name = "#{self.class.name}##{name}" unless request.env['action_dispatch.exception'] + if request.env['action_dispatch.exception'] + rack_span.record_exception(request.env['action_dispatch.exception']) + end + attributes_to_append = { OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => self.class.name, OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => String(name) diff --git a/instrumentation/action_pack/test/opentelemetry/instrumentation/action_pack/patches/action_controller/metal_test.rb b/instrumentation/action_pack/test/opentelemetry/instrumentation/action_pack/patches/action_controller/metal_test.rb index fe488d31c..2e37ba4fc 100644 --- a/instrumentation/action_pack/test/opentelemetry/instrumentation/action_pack/patches/action_controller/metal_test.rb +++ b/instrumentation/action_pack/test/opentelemetry/instrumentation/action_pack/patches/action_controller/metal_test.rb @@ -96,6 +96,9 @@ get 'internal_server_error' _(span.name).must_equal 'ExampleController#internal_server_error' + _(span.events[0].name).must_equal 'exception' + _(span.events[0].attributes['exception.type']).must_equal 'RuntimeError' + _(span.events[0].attributes['exception.message']).must_equal 'a little hell' end end diff --git a/instrumentation/action_pack/test/test_helpers/controllers/example_controller.rb b/instrumentation/action_pack/test/test_helpers/controllers/example_controller.rb index 228c3c8c2..b78defcce 100644 --- a/instrumentation/action_pack/test/test_helpers/controllers/example_controller.rb +++ b/instrumentation/action_pack/test/test_helpers/controllers/example_controller.rb @@ -20,6 +20,6 @@ def new_item end def internal_server_error - raise :internal_server_error + raise 'a little hell' end end