lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.16.0 vs lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.17.0
- old
+ new
@@ -23,27 +23,35 @@
trace: 'TRACE'
}.freeze
def call(env)
http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
-
+ attributes = span_creation_attributes(
+ http_method: http_method, url: env.url
+ )
tracer.in_span(
- "HTTP #{http_method}",
- attributes: {
- 'http.method' => http_method,
- 'http.url' => env.url.to_s
- },
- kind: :client
+ "HTTP #{http_method}", attributes: attributes, kind: :client
) do |span|
OpenTelemetry.propagation.inject(env.request_headers)
app.call(env).on_complete { |resp| trace_response(span, resp) }
end
end
private
attr_reader :app
+
+ def span_creation_attributes(http_method:, url:)
+ instrumentation_attrs = {
+ 'http.method' => http_method, 'http.url' => url.to_s
+ }
+ config = Faraday::Instrumentation.instance.config
+ instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
+ instrumentation_attrs.merge(
+ OpenTelemetry::Common::HTTP::ClientContext.attributes
+ )
+ end
def tracer
Faraday::Instrumentation.instance.tracer
end