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 4 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'
enable_internal_instrumentation: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed that this example is incorrect. The options need to be a parameter to use so there should be a comma here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks for catching that

end
```

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

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

## Examples

Example usage of faraday can be seen in the [`./example/faraday.rb` file](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 :enable_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[:enable_internal_instrumentation] == false
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