Module: Datadog::Tracing::Contrib::ActionPack::ActionController::Instrumentation
- Defined in:
- lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb
Overview
Instrumentation for ActionController components
Defined Under Namespace
Modules: Metal
Class Method Summary collapse
Class Method Details
.finish_processing(payload) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb', line 50 def finish_processing(payload) return unless Tracing.enabled? # retrieve the tracing context and the latest active span tracing_context = payload.fetch(:tracing_context) trace = tracing_context[:dd_request_trace] span = tracing_context[:dd_request_span] return unless span && !span.finished? begin # We repeat this in both start and at finish because the resource may have changed during the request trace.resource = span.resource unless payload[:headers][:request_exception] # Set analytics sample rate Utils.set_analytics_sample_rate(span) # Measure service stats Contrib::Analytics.set_measured(span) span.set_tag(Ext::TAG_ROUTE_ACTION, payload.fetch(:action)) span.set_tag(Ext::TAG_ROUTE_CONTROLLER, payload.fetch(:controller)) exception = payload[:exception_object] if exception.nil? # [christian] in some cases :status is not defined, # rather than firing an error, simply acknowledge we don't know it. status = payload.fetch(:status, '?').to_s span.status = 1 if status.start_with?('5') elsif Utils.exception_is_error?(exception) span.set_error(exception) end ensure span.finish end rescue StandardError => e Datadog.logger.error(e.) Datadog::Core::Telemetry::Logger.report(e) end |
.start_processing(payload) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb', line 21 def start_processing(payload) return unless Tracing.enabled? # trace the execution service = Datadog.configuration.tracing[:action_pack][:service_name] type = Tracing::Metadata::Ext::HTTP::TYPE_INBOUND span = Tracing.trace( Ext::SPAN_ACTION_CONTROLLER, service: service, type: type, resource: "#{payload.fetch(:controller)}##{payload.fetch(:action)}", ) trace = Tracing.active_trace # attach the current span to the tracing context tracing_context = payload.fetch(:tracing_context) tracing_context[:dd_request_trace] = trace tracing_context[:dd_request_span] = span # We want the route to show up as the trace's resource trace.resource = span.resource unless payload[:headers][:request_exception] span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_CONTROLLER) rescue StandardError => e Datadog.logger.error(e.) Datadog::Core::Telemetry::Logger.report(e) end |