Skip to content

Commit 2c11325

Browse files
authored
feat: suppress internal spans with Faraday instrumentation (#1506)
* add flag to suppress downstream instrumentation * update README * change flag name * fix README
1 parent 645d1ca commit 2c11325

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

instrumentation/faraday/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ To install the instrumentation, call `use` with the name of the instrumentation.
1818

1919
```ruby
2020
OpenTelemetry::SDK.configure do |c|
21-
c.use 'OpenTelemetry::Instrumentation::Faraday'
21+
c.use 'OpenTelemetry::Instrumentation::Faraday', {
22+
enable_internal_instrumentation: false
23+
}
2224
end
2325
```
2426

@@ -30,6 +32,11 @@ OpenTelemetry::SDK.configure do |c|
3032
end
3133
```
3234

35+
### Configuration options
36+
This instrumentation offers the following configuration options:
37+
* `enable_internal_instrumentation` (default: `false`): When set to `true`, any spans with
38+
span kind of `internal` are included in traces.
39+
3340
## Examples
3441

3542
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)

instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/instrumentation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2828

2929
option :span_kind, default: :client, validate: %i[client internal]
3030
option :peer_service, default: nil, validate: :string
31+
option :enable_internal_instrumentation, default: false, validate: :boolean
3132

3233
private
3334

instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ def call(env)
4040
) do |span|
4141
OpenTelemetry.propagation.inject(env.request_headers)
4242

43-
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
43+
if config[:enable_internal_instrumentation] == false
44+
OpenTelemetry::Common::Utilities.untraced do
45+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
46+
end
47+
else
48+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
49+
end
4450
rescue ::Faraday::Error => e
4551
trace_response(span, e.response[:status]) if e.response
4652

0 commit comments

Comments
 (0)