opentelemetry-instrumentation-aws_sdk 0.5.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +27 -2
- data/lib/opentelemetry/instrumentation/aws_sdk/handler.rb +17 -73
- data/lib/opentelemetry/instrumentation/aws_sdk/handler_helper.rb +81 -0
- data/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +70 -14
- data/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb +79 -5
- data/lib/opentelemetry/instrumentation/aws_sdk/patches/telemetry.rb +40 -0
- data/lib/opentelemetry/instrumentation/aws_sdk/version.rb +1 -1
- metadata +12 -11
- data/lib/opentelemetry/instrumentation/aws_sdk/services.rb +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc28b8e181dc59950237cb56fbde713e2083003bab88acd345bd90dba7b5eb1a
|
4
|
+
data.tar.gz: a479a21f7d6c14d691df13d7683bf5a680045185520205018d70a9736b306a2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86d3e8d2c0a94cd739f5abdeae3c762573d6e175b0fc4ffd682fc1811ce1da7fc2d4fd73ce0131573531b9f3643d9ef5b3bf775869aa9445012d43295af2c02c
|
7
|
+
data.tar.gz: 1b1d40e77d958f1869163cf01f1d6ddf6bb8713170747cf6d754fc225d6a9715efe6454a3b5f4fb7e9d5d0025d22ca745c0dccf46385718509f97a604fd3c33f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Release History: opentelemetry-instrumentation-aws_sdk
|
2
2
|
|
3
|
+
### v0.7.0 / 2024-10-08
|
4
|
+
|
5
|
+
* ADDED: Integration with V3 telemetry provider
|
6
|
+
|
7
|
+
### v0.6.0 / 2024-09-19
|
8
|
+
|
9
|
+
* ADDED: All AWS services emit traces
|
10
|
+
|
3
11
|
### v0.5.4 / 2024-07-23
|
4
12
|
|
5
13
|
* DOCS: Add cspell to CI
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ The OpenTelemetry `aws-sdk` gem is a community maintained instrumentation for [a
|
|
6
6
|
|
7
7
|
Install the gem using:
|
8
8
|
|
9
|
-
```
|
9
|
+
```console
|
10
10
|
gem install opentelemetry-instrumentation-aws_sdk
|
11
11
|
```
|
12
12
|
|
@@ -32,6 +32,30 @@ OpenTelemetry::SDK.configure do |c|
|
|
32
32
|
c.use_all
|
33
33
|
end
|
34
34
|
```
|
35
|
+
### Configuration options
|
36
|
+
This instrumentation offers the following configuration options:
|
37
|
+
* `:inject_messaging_context` (default: `false`): When set to `true`, adds context key/value
|
38
|
+
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.
|
41
|
+
|
42
|
+
## Integration with SDK V3's Telemetry support
|
43
|
+
AWS SDK for Ruby V3 added support for Observability which includes a new configuration,
|
44
|
+
`telemetry_provider` and an OpenTelemetry-based telemetry provider. Only applies to
|
45
|
+
AWS service gems released after 2024-09-03.
|
46
|
+
|
47
|
+
Using later versions of these gems will give more details on the internal spans.
|
48
|
+
See below for example usage:
|
49
|
+
```ruby
|
50
|
+
# configures the OpenTelemetry SDK with instrumentation defaults
|
51
|
+
OpenTelemetry::SDK.configure do |c|
|
52
|
+
c.use 'OpenTelemetry::Instrumentation::AwsSdk'
|
53
|
+
end
|
54
|
+
|
55
|
+
# create open-telemetry provider and pass to client config
|
56
|
+
otel_provider = Aws::Telemetry::OTelProvider.new
|
57
|
+
client = Aws::S3::Client.new(telemetry_provider: otel_provider)
|
58
|
+
```
|
35
59
|
|
36
60
|
## Example
|
37
61
|
|
@@ -49,7 +73,7 @@ This will run SNS publish command, printing OpenTelemetry traces to the console
|
|
49
73
|
|
50
74
|
The `opentelemetry-instrumentation-aws_sdk` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
|
51
75
|
|
52
|
-
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry
|
76
|
+
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
|
53
77
|
|
54
78
|
## License
|
55
79
|
|
@@ -61,4 +85,5 @@ Apache 2.0 license. See [LICENSE][license-github] for more information.
|
|
61
85
|
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
|
62
86
|
[ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
|
63
87
|
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
88
|
+
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
64
89
|
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
@@ -7,38 +7,31 @@
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module Instrumentation
|
9
9
|
module AwsSdk
|
10
|
-
#
|
10
|
+
# This handler supports specifically supports V2 and V3
|
11
|
+
# prior to Observability support released on 2024-09-03.
|
11
12
|
class Handler < Seahorse::Client::Handler
|
12
|
-
SQS_SEND_MESSAGE = 'SQS.SendMessage'
|
13
|
-
SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch'
|
14
|
-
SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
|
15
|
-
SNS_PUBLISH = 'SNS.Publish'
|
16
|
-
|
17
13
|
def call(context)
|
18
14
|
return super unless context
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
attributes[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_name == 'DynamoDB'
|
30
|
-
MessagingHelper.apply_sqs_attributes(attributes, context, client_method) if service_name == 'SQS'
|
31
|
-
MessagingHelper.apply_sns_attributes(attributes, context, client_method) if service_name == 'SNS'
|
16
|
+
service_id = HandlerHelper.service_id(context, legacy: true)
|
17
|
+
client_method = HandlerHelper.client_method(service_id, context)
|
18
|
+
|
19
|
+
tracer.in_span(
|
20
|
+
HandlerHelper.span_name(context, client_method, service_id, legacy: true),
|
21
|
+
attributes: HandlerHelper.span_attributes(context, client_method, service_id, legacy: true),
|
22
|
+
kind: HandlerHelper.span_kind(client_method, service_id)
|
23
|
+
) do |span|
|
24
|
+
MessagingHelper.inject_context_if_supported(context, client_method, service_id)
|
32
25
|
|
33
|
-
|
34
|
-
inject_context(context, client_method)
|
35
|
-
if instrumentation_config[:suppress_internal_instrumentation]
|
26
|
+
if HandlerHelper.instrumentation_config[:suppress_internal_instrumentation]
|
36
27
|
OpenTelemetry::Common::Utilities.untraced { super }
|
37
28
|
else
|
38
29
|
super
|
39
30
|
end.tap do |response|
|
40
|
-
span.set_attribute(
|
41
|
-
|
31
|
+
span.set_attribute(
|
32
|
+
OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE,
|
33
|
+
context.http_response.status_code
|
34
|
+
)
|
42
35
|
|
43
36
|
if (err = response.error)
|
44
37
|
span.record_exception(err)
|
@@ -53,60 +46,11 @@ module OpenTelemetry
|
|
53
46
|
def tracer
|
54
47
|
AwsSdk::Instrumentation.instance.tracer
|
55
48
|
end
|
56
|
-
|
57
|
-
def instrumentation_config
|
58
|
-
AwsSdk::Instrumentation.instance.config
|
59
|
-
end
|
60
|
-
|
61
|
-
def service_name(context)
|
62
|
-
# Support aws-sdk v2.0.x, which 'metadata' has a setter method only
|
63
|
-
return context.client.class.to_s.split('::')[1] if ::Seahorse::Model::Api.instance_method(:metadata).parameters.length.positive?
|
64
|
-
|
65
|
-
context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
|
66
|
-
end
|
67
|
-
|
68
|
-
SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze
|
69
|
-
def inject_context(context, client_method)
|
70
|
-
return unless SEND_MESSAGE_CLIENT_METHODS.include? client_method
|
71
|
-
return unless instrumentation_config[:inject_messaging_context]
|
72
|
-
|
73
|
-
if client_method == SQS_SEND_MESSAGE_BATCH
|
74
|
-
context.params[:entries].each do |entry|
|
75
|
-
entry[:message_attributes] ||= {}
|
76
|
-
OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter)
|
77
|
-
end
|
78
|
-
else
|
79
|
-
context.params[:message_attributes] ||= {}
|
80
|
-
OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def span_kind(client_method)
|
85
|
-
case client_method
|
86
|
-
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
87
|
-
OpenTelemetry::Trace::SpanKind::PRODUCER
|
88
|
-
when SQS_RECEIVE_MESSAGE
|
89
|
-
OpenTelemetry::Trace::SpanKind::CONSUMER
|
90
|
-
else
|
91
|
-
OpenTelemetry::Trace::SpanKind::CLIENT
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def span_name(context, client_method)
|
96
|
-
case client_method
|
97
|
-
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
98
|
-
"#{MessagingHelper.queue_name(context)} publish"
|
99
|
-
when SQS_RECEIVE_MESSAGE
|
100
|
-
"#{MessagingHelper.queue_name(context)} receive"
|
101
|
-
else
|
102
|
-
client_method
|
103
|
-
end
|
104
|
-
end
|
105
49
|
end
|
106
50
|
|
107
51
|
# A Seahorse::Client::Plugin that enables instrumentation for all AWS services
|
108
52
|
class Plugin < Seahorse::Client::Plugin
|
109
|
-
def add_handlers(handlers,
|
53
|
+
def add_handlers(handlers, _config)
|
110
54
|
# run before Seahorse::Client::Plugin::ParamValidator (priority 50)
|
111
55
|
handlers.add Handler, step: :validate, priority: 49
|
112
56
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module AwsSdk
|
10
|
+
# Utility module that contains shared methods between AwsSdk and Telemetry handlers
|
11
|
+
module HandlerHelper
|
12
|
+
class << self
|
13
|
+
def instrumentation_config
|
14
|
+
AwsSdk::Instrumentation.instance.config
|
15
|
+
end
|
16
|
+
|
17
|
+
def client_method(service_id, context)
|
18
|
+
"#{service_id}.#{context.operation.name}".delete(' ')
|
19
|
+
end
|
20
|
+
|
21
|
+
def span_attributes(context, client_method, service_id, legacy: false)
|
22
|
+
{
|
23
|
+
'aws.region' => context.config.region,
|
24
|
+
OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => context.operation_name.to_s,
|
25
|
+
OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => 'Aws::Plugins::Telemetry',
|
26
|
+
OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => context.operation.name,
|
27
|
+
OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_id,
|
28
|
+
OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api'
|
29
|
+
}.tap do |attrs|
|
30
|
+
attrs[OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE] = 'Aws::Plugins::AwsSdk' if legacy
|
31
|
+
attrs[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_id == 'DynamoDB'
|
32
|
+
|
33
|
+
MessagingHelper.apply_span_attributes(context, attrs, client_method, service_id) if MessagingHelper::SUPPORTED_SERVICES.include?(service_id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def span_kind(client_method, service_id)
|
38
|
+
case service_id
|
39
|
+
when *MessagingHelper::SUPPORTED_SERVICES
|
40
|
+
MessagingHelper.span_kind(client_method)
|
41
|
+
else
|
42
|
+
OpenTelemetry::Trace::SpanKind::CLIENT
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def span_name(context, client_method, service_id, legacy: false)
|
47
|
+
case service_id
|
48
|
+
when *MessagingHelper::SUPPORTED_SERVICES
|
49
|
+
if legacy
|
50
|
+
MessagingHelper.legacy_span_name(context, client_method)
|
51
|
+
else
|
52
|
+
MessagingHelper.span_name(context, client_method)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
client_method
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def service_id(context, legacy: false)
|
60
|
+
if legacy
|
61
|
+
legacy_service_id(context)
|
62
|
+
else
|
63
|
+
context.config.api.metadata['serviceId'] ||
|
64
|
+
context.config.api.metadata['serviceAbbreviation'] ||
|
65
|
+
context.config.api.metadata['serviceFullName']
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def legacy_service_id(context)
|
72
|
+
# Support aws-sdk v2.0.x, which 'metadata' has a setter method only
|
73
|
+
return context.client.class.to_s.split('::')[1] if ::Seahorse::Model::Api.instance_method(:metadata).parameters.length.positive?
|
74
|
+
|
75
|
+
context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -7,13 +7,39 @@
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module Instrumentation
|
9
9
|
module AwsSdk
|
10
|
-
# Instrumentation class
|
10
|
+
# The `OpenTelemetry::Instrumentation::AwsSdk::Instrumentation` class contains
|
11
|
+
# logic to detect and install the AwsSdk instrumentation.
|
12
|
+
#
|
13
|
+
# ## Configuration keys and options
|
14
|
+
#
|
15
|
+
# ### `:inject_messaging_context`
|
16
|
+
#
|
17
|
+
# Allows adding of context key/value to Message Attributes for SQS/SNS messages.
|
18
|
+
#
|
19
|
+
# - `false` **(default)** - Context key/value will not be added.
|
20
|
+
# - `true` - Context key/value will be added.
|
21
|
+
#
|
22
|
+
# ### `:suppress_internal_instrumentation`
|
23
|
+
#
|
24
|
+
# Disables tracing of spans of `internal` span kind.
|
25
|
+
#
|
26
|
+
# - `false` **(default)** - Internal spans are traced.
|
27
|
+
# - `true` - Internal spans are not traced.
|
28
|
+
#
|
29
|
+
# @example An explicit default configuration
|
30
|
+
# OpenTelemetry::SDK.configure do |c|
|
31
|
+
# c.use 'OpenTelemetry::Instrumentation::AwsSdk', {
|
32
|
+
# inject_messaging_context: false,
|
33
|
+
# suppress_internal_instrumentation: false
|
34
|
+
# }
|
35
|
+
# end
|
11
36
|
class Instrumentation < OpenTelemetry::Instrumentation::Base
|
12
37
|
MINIMUM_VERSION = Gem::Version.new('2.0.0')
|
13
38
|
|
14
39
|
install do |_config|
|
15
40
|
require_dependencies
|
16
|
-
|
41
|
+
patch_telemetry_plugin if telemetry_plugin?
|
42
|
+
add_plugins(Seahorse::Client::Base, *loaded_service_clients)
|
17
43
|
end
|
18
44
|
|
19
45
|
present do
|
@@ -41,31 +67,61 @@ module OpenTelemetry
|
|
41
67
|
|
42
68
|
def require_dependencies
|
43
69
|
require_relative 'handler'
|
44
|
-
require_relative '
|
70
|
+
require_relative 'handler_helper'
|
45
71
|
require_relative 'message_attributes'
|
46
72
|
require_relative 'messaging_helper'
|
73
|
+
require_relative 'patches/telemetry'
|
47
74
|
end
|
48
75
|
|
49
|
-
def
|
50
|
-
targets.each
|
76
|
+
def add_plugins(*targets)
|
77
|
+
targets.each do |klass|
|
78
|
+
next if supports_telemetry_plugin?(klass)
|
79
|
+
|
80
|
+
klass.add_plugin(AwsSdk::Plugin)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def supports_telemetry_plugin?(klass)
|
85
|
+
telemetry_plugin? &&
|
86
|
+
klass.plugins.include?(Aws::Plugins::Telemetry)
|
87
|
+
end
|
88
|
+
|
89
|
+
def telemetry_plugin?
|
90
|
+
::Aws::Plugins.const_defined?(:Telemetry)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Patches AWS SDK V3's telemetry plugin for integration
|
94
|
+
# This patch supports configuration set by this gem and
|
95
|
+
# additional span attributes that was not provided by the plugin
|
96
|
+
def patch_telemetry_plugin
|
97
|
+
::Aws::Plugins::Telemetry::Handler.prepend(Patches::Handler)
|
51
98
|
end
|
52
99
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# the wrong constant, resulting in patch failure.
|
58
|
-
available_services = ::Aws.constants & SERVICES.map(&:to_sym)
|
59
|
-
available_services.each_with_object([]) do |service, constants|
|
60
|
-
next if ::Aws.autoload?(service)
|
100
|
+
def loaded_service_clients
|
101
|
+
::Aws.constants.each_with_object([]) do |c, constants|
|
102
|
+
m = ::Aws.const_get(c)
|
103
|
+
next unless loaded_service?(c, m)
|
61
104
|
|
62
105
|
begin
|
63
|
-
constants <<
|
106
|
+
constants << m.const_get(:Client)
|
64
107
|
rescue StandardError => e
|
65
108
|
OpenTelemetry.logger.warn("Constant could not be loaded: #{e}")
|
66
109
|
end
|
67
110
|
end
|
68
111
|
end
|
112
|
+
|
113
|
+
# This check does the following:
|
114
|
+
# 1 - Checks if the service client is autoload or not
|
115
|
+
# 2 - Validates whether if is a service client
|
116
|
+
# note that Seahorse::Client::Base is a superclass for V3 clients
|
117
|
+
# but for V2, it is Aws::Client
|
118
|
+
def loaded_service?(constant, service_module)
|
119
|
+
!::Aws.autoload?(constant) &&
|
120
|
+
service_module.is_a?(Module) &&
|
121
|
+
service_module.const_defined?(:Client) &&
|
122
|
+
(service_module.const_get(:Client).superclass == Seahorse::Client::Base ||
|
123
|
+
service_module.const_get(:Client).superclass == Aws::Client)
|
124
|
+
end
|
69
125
|
end
|
70
126
|
end
|
71
127
|
end
|
@@ -7,9 +7,20 @@
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module Instrumentation
|
9
9
|
module AwsSdk
|
10
|
-
#
|
10
|
+
# An utility class to help SQS/SNS-related span attributes/context injection
|
11
11
|
class MessagingHelper
|
12
|
+
SUPPORTED_SERVICES = %w[SQS SNS].freeze
|
12
13
|
class << self
|
14
|
+
SQS_SEND_MESSAGE = 'SQS.SendMessage'
|
15
|
+
SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch'
|
16
|
+
SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
|
17
|
+
SNS_PUBLISH = 'SNS.Publish'
|
18
|
+
SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze
|
19
|
+
|
20
|
+
def supported_services
|
21
|
+
SUPPORTED_SERVICES
|
22
|
+
end
|
23
|
+
|
13
24
|
def queue_name(context)
|
14
25
|
topic_arn = context.params[:topic_arn]
|
15
26
|
target_arn = context.params[:target_arn]
|
@@ -28,19 +39,82 @@ module OpenTelemetry
|
|
28
39
|
'unknown'
|
29
40
|
end
|
30
41
|
|
42
|
+
def span_name(context, client_method)
|
43
|
+
case client_method
|
44
|
+
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
45
|
+
"#{client_method}.#{queue_name(context)}.Publish"
|
46
|
+
when SQS_RECEIVE_MESSAGE
|
47
|
+
"#{client_method}.#{queue_name(context)}.Receive"
|
48
|
+
else
|
49
|
+
client_method
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def legacy_span_name(context, client_method)
|
54
|
+
case client_method
|
55
|
+
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
56
|
+
"#{MessagingHelper.queue_name(context)} publish"
|
57
|
+
when SQS_RECEIVE_MESSAGE
|
58
|
+
"#{MessagingHelper.queue_name(context)} receive"
|
59
|
+
else
|
60
|
+
client_method
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def apply_span_attributes(context, attrs, client_method, service_id)
|
65
|
+
case service_id
|
66
|
+
when 'SQS'
|
67
|
+
apply_sqs_attributes(attrs, context, client_method)
|
68
|
+
when 'SNS'
|
69
|
+
apply_sns_attributes(attrs, context, client_method)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def span_kind(client_method)
|
74
|
+
case client_method
|
75
|
+
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
76
|
+
OpenTelemetry::Trace::SpanKind::PRODUCER
|
77
|
+
when SQS_RECEIVE_MESSAGE
|
78
|
+
OpenTelemetry::Trace::SpanKind::CONSUMER
|
79
|
+
else
|
80
|
+
OpenTelemetry::Trace::SpanKind::CLIENT
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def inject_context_if_supported(context, client_method, service_id)
|
85
|
+
if HandlerHelper.instrumentation_config[:inject_messaging_context] &&
|
86
|
+
SUPPORTED_SERVICES.include?(service_id)
|
87
|
+
inject_context(context, client_method)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def inject_context(context, client_method)
|
92
|
+
return unless SEND_MESSAGE_CLIENT_METHODS.include?(client_method)
|
93
|
+
|
94
|
+
if client_method == SQS_SEND_MESSAGE_BATCH
|
95
|
+
context.params[:entries].each do |entry|
|
96
|
+
entry[:message_attributes] ||= {}
|
97
|
+
OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter)
|
98
|
+
end
|
99
|
+
else
|
100
|
+
context.params[:message_attributes] ||= {}
|
101
|
+
OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
31
107
|
def apply_sqs_attributes(attributes, context, client_method)
|
32
108
|
attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
|
33
109
|
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue'
|
34
110
|
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
|
35
111
|
attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url] if context.params[:queue_url]
|
36
|
-
|
37
|
-
attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
|
112
|
+
attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == SQS_RECEIVE_MESSAGE
|
38
113
|
end
|
39
114
|
|
40
115
|
def apply_sns_attributes(attributes, context, client_method)
|
41
116
|
attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'
|
42
|
-
|
43
|
-
return unless client_method == 'SNS.Publish'
|
117
|
+
return unless client_method == SNS_PUBLISH
|
44
118
|
|
45
119
|
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
|
46
120
|
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module AwsSdk
|
10
|
+
module Patches
|
11
|
+
# Patch for Telemetry Plugin Handler in V3 SDK
|
12
|
+
module Handler
|
13
|
+
def call(context)
|
14
|
+
span_wrapper(context) { @handler.call(context) }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def span_wrapper(context, &block)
|
20
|
+
service_id = HandlerHelper.service_id(context)
|
21
|
+
client_method = HandlerHelper.client_method(service_id, context)
|
22
|
+
context.tracer.in_span(
|
23
|
+
HandlerHelper.span_name(context, client_method, service_id),
|
24
|
+
attributes: HandlerHelper.span_attributes(context, client_method, service_id),
|
25
|
+
kind: HandlerHelper.span_kind(client_method, service_id)
|
26
|
+
) do |span|
|
27
|
+
MessagingHelper.inject_context_if_supported(context, client_method, service_id)
|
28
|
+
|
29
|
+
if HandlerHelper.instrumentation_config[:suppress_internal_instrumentation]
|
30
|
+
OpenTelemetry::Common::Utilities.untraced { super }
|
31
|
+
else
|
32
|
+
yield span
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-instrumentation-aws_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -156,28 +156,28 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.66.0
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
166
|
+
version: 1.66.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rubocop-performance
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 1.22.0
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 1.22.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: simplecov
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,14 +198,14 @@ dependencies:
|
|
198
198
|
requirements:
|
199
199
|
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
201
|
+
version: 3.24.0
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
208
|
+
version: 3.24.0
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: yard
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -235,19 +235,20 @@ files:
|
|
235
235
|
- lib/opentelemetry/instrumentation.rb
|
236
236
|
- lib/opentelemetry/instrumentation/aws_sdk.rb
|
237
237
|
- lib/opentelemetry/instrumentation/aws_sdk/handler.rb
|
238
|
+
- lib/opentelemetry/instrumentation/aws_sdk/handler_helper.rb
|
238
239
|
- lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb
|
239
240
|
- lib/opentelemetry/instrumentation/aws_sdk/message_attributes.rb
|
240
241
|
- lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
|
241
|
-
- lib/opentelemetry/instrumentation/aws_sdk/
|
242
|
+
- lib/opentelemetry/instrumentation/aws_sdk/patches/telemetry.rb
|
242
243
|
- lib/opentelemetry/instrumentation/aws_sdk/version.rb
|
243
244
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
244
245
|
licenses:
|
245
246
|
- Apache-2.0
|
246
247
|
metadata:
|
247
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.
|
248
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.7.0/file/CHANGELOG.md
|
248
249
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/aws_sdk
|
249
250
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
250
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.
|
251
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.7.0
|
251
252
|
post_install_message:
|
252
253
|
rdoc_options: []
|
253
254
|
require_paths:
|
@@ -1,121 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenTelemetry
|
4
|
-
module Instrumentation
|
5
|
-
# rubocop:disable Metrics/ModuleLength:
|
6
|
-
module AwsSdk
|
7
|
-
SERVICES = %w[
|
8
|
-
ACM
|
9
|
-
APIGateway
|
10
|
-
AppStream
|
11
|
-
ApplicationAutoScaling
|
12
|
-
ApplicationDiscoveryService
|
13
|
-
Athena
|
14
|
-
AutoScaling
|
15
|
-
Batch
|
16
|
-
Budgets
|
17
|
-
CloudDirectory
|
18
|
-
CloudFormation
|
19
|
-
CloudFront
|
20
|
-
CloudHSM
|
21
|
-
CloudHSMV2
|
22
|
-
CloudSearch
|
23
|
-
CloudSearchDomain
|
24
|
-
CloudTrail
|
25
|
-
CloudWatch
|
26
|
-
CloudWatchEvents
|
27
|
-
CloudWatchLogs
|
28
|
-
CodeBuild
|
29
|
-
CodeCommit
|
30
|
-
CodeDeploy
|
31
|
-
CodePipeline
|
32
|
-
CodeStar
|
33
|
-
CognitoIdentity
|
34
|
-
CognitoIdentityProvider
|
35
|
-
CognitoSync
|
36
|
-
ConfigService
|
37
|
-
CostandUsageReportService
|
38
|
-
DAX
|
39
|
-
DataPipeline
|
40
|
-
DatabaseMigrationService
|
41
|
-
DeviceFarm
|
42
|
-
DirectConnect
|
43
|
-
DirectoryService
|
44
|
-
DynamoDB
|
45
|
-
DynamoDBStreams
|
46
|
-
EC2
|
47
|
-
ECR
|
48
|
-
ECS
|
49
|
-
EFS
|
50
|
-
EMR
|
51
|
-
ElastiCache
|
52
|
-
ElasticBeanstalk
|
53
|
-
ElasticLoadBalancing
|
54
|
-
ElasticLoadBalancingV2
|
55
|
-
ElasticTranscoder
|
56
|
-
ElasticsearchService
|
57
|
-
EventBridge
|
58
|
-
Firehose
|
59
|
-
GameLift
|
60
|
-
Glacier
|
61
|
-
Glue
|
62
|
-
Greengrass
|
63
|
-
Health
|
64
|
-
IAM
|
65
|
-
ImportExport
|
66
|
-
Inspector
|
67
|
-
IoT
|
68
|
-
IoTDataPlane
|
69
|
-
KMS
|
70
|
-
Kinesis
|
71
|
-
KinesisAnalytics
|
72
|
-
Lambda
|
73
|
-
LambdaPreview
|
74
|
-
Lex
|
75
|
-
LexModelBuildingService
|
76
|
-
Lightsail
|
77
|
-
MTurk
|
78
|
-
MachineLearning
|
79
|
-
MarketplaceCommerceAnalytics
|
80
|
-
MarketplaceEntitlementService
|
81
|
-
MarketplaceMetering
|
82
|
-
MigrationHub
|
83
|
-
Mobile
|
84
|
-
OpsWorks
|
85
|
-
OpsWorksCM
|
86
|
-
Organizations
|
87
|
-
Pinpoint
|
88
|
-
Polly
|
89
|
-
RDS
|
90
|
-
Redshift
|
91
|
-
Rekognition
|
92
|
-
ResourceGroupsTaggingAPI
|
93
|
-
Route53
|
94
|
-
Route53Domains
|
95
|
-
S3
|
96
|
-
SES
|
97
|
-
SMS
|
98
|
-
SNS
|
99
|
-
SQS
|
100
|
-
SSM
|
101
|
-
STS
|
102
|
-
SWF
|
103
|
-
ServiceCatalog
|
104
|
-
Schemas
|
105
|
-
Shield
|
106
|
-
SimpleDB
|
107
|
-
Snowball
|
108
|
-
States
|
109
|
-
StorageGateway
|
110
|
-
Support
|
111
|
-
Textract
|
112
|
-
WAF
|
113
|
-
WAFRegional
|
114
|
-
WorkDocs
|
115
|
-
WorkSpaces
|
116
|
-
XRay
|
117
|
-
].freeze
|
118
|
-
end
|
119
|
-
# rubocop:enable Metrics/ModuleLength:
|
120
|
-
end
|
121
|
-
end
|