-
Notifications
You must be signed in to change notification settings - Fork 196
feat: suppress internal spans with Faraday instrumentation #1506
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
base: main
Are you sure you want to change the base?
feat: suppress internal spans with Faraday instrumentation #1506
Conversation
@@ -40,7 +40,13 @@ def call(env) | |||
) do |span| | |||
OpenTelemetry.propagation.inject(env.request_headers) | |||
|
|||
app.call(env).on_complete { |resp| trace_response(span, resp.status) } | |||
if config[:suppress_internal_instrumentation] | |||
OpenTelemetry::Common::Utilities.untraced do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that using untraced will suppress instrumentation for all child spans.
Is this what you want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, currently Faraday will generate child spans for its under-the-hood Net::Http instrumentation which creates an additional dependency metric for each request. We want to give the customer the option (preferably default) to suppress this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now, I misunderstood your goals here.
You only want to retain Faraday client spans and skip any driver generated spans.
Is that correct?
I think that may be an invalid combination here where if the Faraday span is configured to generate internal
spans only and also suppress driver spans.
I wonder then if what we want here is separate middleware implementations as opposed to conditional checks I.e. replacing conditional logic with polymorphism.
That would likely couple the span kind setting to this suppression setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring to the configuration below?
'OpenTelemetry::Instrumentation::Faraday' => {
suppress_internal_instrumentation: true,
span_kind: :internal
}
This may not make sense, but I think flexibility to configure the options separately is better. Some users may also want client spans where the internal instrumentation isn't suppressed for better transparency, which discourages the coupling of the two settings.
Also, why do you prefer the polymorphism approach when the conditional is simple enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring to the configuration below?
'OpenTelemetry::Instrumentation::Faraday' => { suppress_internal_instrumentation: true, span_kind: :internal }
This may not make sense, but I think flexibility to configure the options separately is better. Some users may also want client spans where the internal instrumentation isn't suppressed for better transparency, which discourages the coupling of the two settings.
The more configuration options we offer the more complex the instrumentations are to understand for our users.
The combination of having an internal
span and also suppressing the child span would be an invalid combination. I don't think it's one we want to support.
Also, why do you prefer the polymorphism approach when the conditional is simple enough?
Yes, I agree that this conditional check is a minimal implementation but I also believe that the instrumentation should do the minimal possible to achieve its goal. The config option cannot change for the life of the instrumentation so we are checking it with each request.
Yes, it will likely be optimized away by a JIT at some point and it's just a quick check, but for now anything we can remove from the users request path we should consider doing. Keep in mind that my comment was more of a nitpick and not a blocker.
@@ -28,6 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base | |||
|
|||
option :span_kind, default: :client, validate: %i[client internal] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding an option here like :none
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on this? The current behavior of setting the flag to false will ensure no spans are suppressed.
Addresses #1502 for Faraday library instrumentation. Allow user to set
suppress_internal_instrumentation
flag when configuring Faraday instrumentation to suppress additional client spans generated from underlying Net::Http instrumentation.Before merging, waiting for update on Github issue to see if internal span suppression can be made default behavior for both Faraday and AWS SDK.