Skip to content

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions instrumentation/faraday/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ To install the instrumentation, call `use` with the name of the instrumentation.
```ruby
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::Faraday'
suppress_internal_instrumentation: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a related PR from @jterapin renaming the option as enable_internal_instrumentation, which is language I think I prefer when naming the options.

Ideally these options would have symmetric naming and functionality.

#1533

Would you be amenable to changing the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

end
```

Expand All @@ -30,6 +31,11 @@ OpenTelemetry::SDK.configure do |c|
end
```

### Configuration options
This instrumentation offers the following configuration options:
* `suppress_internal_instrumentation` (default: `false`): When set to `true`, any spans with
span kind of `internal` are suppressed from traces.

## Examples

Example usage of faraday can be seen in the `./example/faraday.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/faraday/example/faraday.rb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 :suppress_internal_instrumentation, default: false, validate: :boolean

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
end
else
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
end
rescue ::Faraday::Error => e
trace_response(span, e.response[:status]) if e.response

Expand Down
Loading