Module: Datadog::Tracing::Contrib::HTTP::Instrumentation::InstanceMethods
- Defined in:
- lib/datadog/tracing/contrib/http/instrumentation.rb
Overview
InstanceMethods - implementing instrumentation
Instance Method Summary collapse
- #annotate_span_with_request!(span, request, request_options) ⇒ Object
- #annotate_span_with_response!(span, response, request_options) ⇒ Object
-
#request(req, body = nil, &block) ⇒ Object
:yield:
response. - #set_analytics_sample_rate(span, request_options) ⇒ Object
Methods included from Datadog::Tracing::Contrib::HttpAnnotationHelper
Instance Method Details
#annotate_span_with_request!(span, request, request_options) ⇒ Object
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 88 89 90 91 92 93 94 |
# File 'lib/datadog/tracing/contrib/http/instrumentation.rb', line 59 def annotate_span_with_request!(span, request, ) if [:peer_service] span.set_tag( Tracing::Metadata::Ext::TAG_PEER_SERVICE, [:peer_service] ) end span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT) span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST) span.set_tag( Tracing::Metadata::Ext::HTTP::TAG_URL, Contrib::Utils::Quantization::HTTP.url(request.path, {query: {exclude: :all}}) ) span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_METHOD, request.method) host, port = host_and_port(request) span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, host) span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, port.to_s) span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, host) # Set analytics sample rate set_analytics_sample_rate(span, ) span.( Datadog.configuration.tracing..(request) ) Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES) rescue => e Datadog.logger.error("error preparing span from http request: #{e.class}: #{e.}") Datadog::Core::Telemetry::Logger.report(e) end |
#annotate_span_with_response!(span, response, request_options) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/datadog/tracing/contrib/http/instrumentation.rb', line 96 def annotate_span_with_response!(span, response, ) return unless response&.code span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, response.code) span.set_error(response) if [:error_status_codes].include? response.code.to_i span.( Datadog.configuration.tracing..(response) ) rescue => e Datadog.logger.error("error preparing span from http response: #{e.class}: #{e.}") Datadog::Core::Telemetry::Logger.report(e) end |
#request(req, body = nil, &block) ⇒ Object
:yield: response
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/datadog/tracing/contrib/http/instrumentation.rb', line 26 def request(req, body = nil, &block) host, = host_and_port(req) = datadog_configuration(host) client_config = Datadog.configuration_for(self) return super if Contrib::HTTP.should_skip_tracing?(req) Tracing.trace(Ext::SPAN_REQUEST) do |span, trace| span.service = service_name(host, , client_config) span.set_tag(Tracing::Metadata::Ext::TAG_SVC_SRC, Ext::TAG_COMPONENT) span.type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND span.resource = req.method if Tracing::Distributed::PropagationPolicy.enabled?( pin_config: client_config, global_config: , trace: trace ) Contrib::HTTP.inject(trace, req) end # Add additional request specific tags to the span. annotate_span_with_request!(span, req, ) response = super(req, body, &block) # Add additional response specific tags to the span. annotate_span_with_response!(span, response, ) response end end |
#set_analytics_sample_rate(span, request_options) ⇒ Object
111 112 113 114 115 |
# File 'lib/datadog/tracing/contrib/http/instrumentation.rb', line 111 def set_analytics_sample_rate(span, ) return unless analytics_enabled?() Contrib::Analytics.set_sample_rate(span, analytics_sample_rate()) end |