Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support including host name in faraday span names #1385

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base

option :span_kind, default: :client, validate: %i[client internal]
option :peer_service, default: nil, validate: :string
option :span_naming, default: :http_method, validate: %i[http_method host]

private

Original file line number Diff line number Diff line change
@@ -35,9 +35,14 @@ def call(env)
)

OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
tracer.in_span(
"HTTP #{http_method}", attributes: attrs, kind: config.fetch(:span_kind)
) do |span|
span_name = case config.fetch(:span_naming)
when :host
['HTTP', http_method, env.url.host].compact.join(' ')
else
"HTTP #{http_method}"
end

tracer.in_span(span_name, attributes: attrs, kind: config.fetch(:span_kind)) do |span|
OpenTelemetry.propagation.inject(env.request_headers)

app.call(env).on_complete { |resp| trace_response(span, resp.status) }
Original file line number Diff line number Diff line change
@@ -121,6 +121,24 @@
_(span.attributes['peer.service']).must_equal 'example:faraday'
end

it 'defaults to span naming by http method' do
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install

client.get('/success')

_(span.name).must_equal 'HTTP GET'
end

it 'allows including the host in the span name' do
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(span_naming: :host)

client.get('/success')

_(span.name).must_equal 'HTTP GET example.com'
end

it 'defaults to span kind client' do
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install