Skip to content

Commit 9ec8703

Browse files
jterapinarielvalentin
authored andcommitted
feat!: Suppress internal spans by default (open-telemetry#1533)
* Suppress internal spans by default * Update specs * Remove unnecessary gems * Address feedback * Improve deprecated config impl * Update to just include warn --------- Co-authored-by: Ariel Valentin <[email protected]>
1 parent d561e86 commit 9ec8703

File tree

8 files changed

+88
-114
lines changed

8 files changed

+88
-114
lines changed

instrumentation/aws_sdk/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To install the instrumentation, call `use` with the name of the instrumentation.
2020
OpenTelemetry::SDK.configure do |c|
2121
c.use 'OpenTelemetry::Instrumentation::AwsSdk', {
2222
inject_messaging_context: true,
23-
suppress_internal_instrumentation: true
23+
enable_internal_instrumentation: true
2424
}
2525
end
2626
```
@@ -36,8 +36,10 @@ end
3636
This instrumentation offers the following configuration options:
3737
* `:inject_messaging_context` (default: `false`): When set to `true`, adds context key/value
3838
to Message Attributes for SQS/SNS messages.
39-
* `suppress_internal_instrumentation` (default: `false`): When set to `true`, any spans with
40-
span kind of `internal` are suppressed from traces.
39+
* `:enable_internal_instrumentation` (default: `false`): When set to `true`, any spans with
40+
span kind of `internal` are traced.
41+
* `:suppress_internal_instrumentation`: **Deprecated**. This configuration has been
42+
deprecated in a favor of `:enable_internal_instrumentation`
4143

4244
## Integration with SDK V3's Telemetry support
4345
AWS SDK for Ruby V3 added support for Observability which includes a new configuration,

instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def call(context)
2323
) do |span|
2424
MessagingHelper.inject_context_if_supported(context, client_method, service_id)
2525

26-
if HandlerHelper.instrumentation_config[:suppress_internal_instrumentation]
26+
if HandlerHelper.skip_internal_instrumentation?
2727
OpenTelemetry::Common::Utilities.untraced { super }
2828
else
2929
super
@@ -32,7 +32,6 @@ def call(context)
3232
OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE,
3333
context.http_response.status_code
3434
)
35-
3635
if (err = response.error)
3736
span.record_exception(err)
3837
span.status = Trace::Status.error(err.to_s)

instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def instrumentation_config
1414
AwsSdk::Instrumentation.instance.config
1515
end
1616

17+
def skip_internal_instrumentation?
18+
instrumentation_config[:enable_internal_instrumentation] == false
19+
end
20+
1721
def client_method(service_id, context)
1822
"#{service_id}.#{context.operation.name}".delete(' ')
1923
end

instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@ module AwsSdk
1919
# - `false` **(default)** - Context key/value will not be added.
2020
# - `true` - Context key/value will be added.
2121
#
22-
# ### `:suppress_internal_instrumentation`
22+
# ### `:enable_internal_instrumentation`
23+
# Enables tracing of spans of `internal` span kind.
2324
#
24-
# Disables tracing of spans of `internal` span kind.
25+
# - `false` **(default)** - Internal spans are not traced
26+
# - `true` - Internal spans are traced.
2527
#
26-
# - `false` **(default)** - Internal spans are traced.
27-
# - `true` - Internal spans are not traced.
28+
# ### `:suppress_internal_instrumentation` (deprecated)
29+
# This configuration has been deprecated in a favor of `:enable_internal_instrumentation`
2830
#
29-
# @example An explicit default configuration
31+
# @example An explicit default configurations
3032
# OpenTelemetry::SDK.configure do |c|
3133
# c.use 'OpenTelemetry::Instrumentation::AwsSdk', {
3234
# inject_messaging_context: false,
33-
# suppress_internal_instrumentation: false
35+
# enable_internal_instrumentation: false
3436
# }
3537
# end
3638
class Instrumentation < OpenTelemetry::Instrumentation::Base
3739
MINIMUM_VERSION = Gem::Version.new('2.0.0')
3840

39-
install do |_config|
41+
install do |config|
42+
resolve_config(config)
4043
require_dependencies
4144
patch_telemetry_plugin if telemetry_plugin?
4245
add_plugins(Seahorse::Client::Base, *loaded_service_clients)
@@ -52,6 +55,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
5255

5356
option :inject_messaging_context, default: false, validate: :boolean
5457
option :suppress_internal_instrumentation, default: false, validate: :boolean
58+
option :enable_internal_instrumentation, default: false, validate: :boolean
5559

5660
def gem_version
5761
if Gem.loaded_specs['aws-sdk']
@@ -65,6 +69,15 @@ def gem_version
6569

6670
private
6771

72+
def resolve_config(config)
73+
return unless config[:suppress_internal_instrumentation]
74+
75+
OpenTelemetry.logger.warn(
76+
'Instrumentation AwsSdk configuration option suppress_internal_instrumentation has been deprecated,' \
77+
'use enable_internal_instrumentation option instead'
78+
)
79+
end
80+
6881
def require_dependencies
6982
require_relative 'handler'
7083
require_relative 'handler_helper'

instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/patches/telemetry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def span_wrapper(context, &)
2626
) do |span|
2727
MessagingHelper.inject_context_if_supported(context, client_method, service_id)
2828

29-
if HandlerHelper.instrumentation_config[:suppress_internal_instrumentation]
29+
if HandlerHelper.skip_internal_instrumentation?
3030
OpenTelemetry::Common::Utilities.untraced { super }
3131
else
3232
yield span

instrumentation/aws_sdk/test/opentelemetry/handler_test.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require 'test_helper'
7+
require_relative '../test_helper'
88

99
describe OpenTelemetry::Instrumentation::AwsSdk do
1010
describe 'AwsSdk Plugin' do
@@ -95,8 +95,7 @@
9595
client.publish(message: 'msg', phone_number: '123456')
9696

9797
_(span.name).must_equal('phone_number publish')
98-
_(span.attributes[otel_semantic::MESSAGING_DESTINATION])
99-
.must_equal('phone_number')
98+
_(span.attributes[otel_semantic::MESSAGING_DESTINATION]).must_equal('phone_number')
10099
end
101100
end
102101

@@ -178,8 +177,7 @@
178177

179178
client.get_queue_url(queue_name: 'queue-name')
180179

181-
_(span.attributes['messaging.destination'])
182-
.must_equal('unknown')
180+
_(span.attributes['messaging.destination']).must_equal('unknown')
183181
_(span.attributes).wont_include('messaging.url')
184182
end
185183
end
@@ -193,8 +191,7 @@
193191

194192
client.list_tables
195193

196-
_(span.attributes[otel_semantic::DB_SYSTEM])
197-
.must_equal('dynamodb')
194+
_(span.attributes[otel_semantic::DB_SYSTEM]).must_equal('dynamodb')
198195
end
199196
end
200197
end

instrumentation/aws_sdk/test/opentelemetry/instrumentation_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,18 @@
6565
instrumentation.instance_variable_set(:@installed, false)
6666
end
6767
end
68+
69+
it 'with default options' do
70+
instrumentation.instance_variable_set(:@installed, false)
71+
instrumentation.install
72+
_(instrumentation.config[:inject_messaging_context]).must_equal(false)
73+
_(instrumentation.config[:enable_internal_instrumentation]).must_equal(false)
74+
_(instrumentation.config[:suppress_internal_instrumentation]).must_equal(false)
75+
end
76+
77+
it 'honors deprecated config, :suppress_internal_instrumentation' do
78+
instrumentation.instance_variable_set(:@installed, false)
79+
instrumentation.install(suppress_internal_instrumentation: true)
80+
_(instrumentation.config[:enable_internal_instrumentation]).must_equal(false)
81+
end
6882
end

0 commit comments

Comments
 (0)