Class: OpenTelemetry::Instrumentation::Excon::Middlewares::Stable::TracerMiddleware
- Inherits:
-
Excon::Middleware::Base
- Object
- Excon::Middleware::Base
- OpenTelemetry::Instrumentation::Excon::Middlewares::Stable::TracerMiddleware
- Defined in:
- lib/opentelemetry/instrumentation/excon/middlewares/stable/tracer_middleware.rb
Overview
Excon middleware for instrumentation
Constant Summary collapse
- HTTP_STATUS_SUCCESS_RANGE =
Constant for the HTTP status range
(100..399)
Class Method Summary collapse
-
.around_default_stack ⇒ Object
Returns a copy of the default stack with the trace middleware injected.
Instance Method Summary collapse
Class Method Details
.around_default_stack ⇒ Object
Returns a copy of the default stack with the trace middleware injected
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/opentelemetry/instrumentation/excon/middlewares/stable/tracer_middleware.rb', line 55 def self.around_default_stack ::Excon.defaults[:middlewares].dup.tap do |default_stack| # If the default stack contains a version of the trace middleware already... existing_trace_middleware = default_stack.find { |m| m <= TracerMiddleware } default_stack.delete(existing_trace_middleware) if existing_trace_middleware # Inject after the ResponseParser middleware response_middleware_index = default_stack.index(::Excon::Middleware::ResponseParser).to_i default_stack.insert(response_middleware_index + 1, self) end end |
Instance Method Details
#error_call(datum) ⇒ Object
49 50 51 52 |
# File 'lib/opentelemetry/instrumentation/excon/middlewares/stable/tracer_middleware.rb', line 49 def error_call(datum) handle_response(datum) @stack.error_call(datum) end |
#request_call(datum) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/opentelemetry/instrumentation/excon/middlewares/stable/tracer_middleware.rb', line 17 def request_call(datum) return @stack.request_call(datum) if untraced?(datum) span_data = HttpHelper.span_attrs_for(datum[:method]) attributes = { 'http.request.method' => span_data.normalized_method, 'url.scheme' => datum[:scheme], 'url.path' => datum[:path], 'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(::Excon::Utils.request_uri(datum)), 'server.address' => datum[:hostname], 'server.port' => datum[:port] } attributes['http.request.method_original'] = span_data.original_method if span_data.original_method attributes['url.query'] = datum[:query] if datum[:query] peer_service = Excon::Instrumentation.instance.config[:peer_service] attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = peer_service if peer_service attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes) span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client) ctx = OpenTelemetry::Trace.context_with_span(span) datum[:otel_span] = span datum[:otel_token] = OpenTelemetry::Context.attach(ctx) OpenTelemetry.propagation.inject(datum[:headers]) @stack.request_call(datum) end |
#response_call(datum) ⇒ Object
43 44 45 46 47 |
# File 'lib/opentelemetry/instrumentation/excon/middlewares/stable/tracer_middleware.rb', line 43 def response_call(datum) @stack.response_call(datum).tap do |d| handle_response(d) end end |