aspecto-opentelemetry-instrumentation-aws_sdk 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/lib/opentelemetry/instrumentation/aws_sdk/handler.rb +62 -34
- data/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +10 -4
- data/lib/opentelemetry/instrumentation/aws_sdk/message_attribute_setter.rb +27 -0
- data/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb +60 -0
- data/lib/opentelemetry/instrumentation/aws_sdk/version.rb +1 -1
- metadata +9 -8
- data/lib/opentelemetry/instrumentation/aws_sdk/db_helper.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07cea588556e47fdc18637f2eaafbfc925a54fa10b1a5f0e90e3252028512c52
|
4
|
+
data.tar.gz: 0b77c9ae3b96d84bdc2065fbce499c371d4d03b49789ab862b823cad9907b87b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd02cdfca52ecec95c992481bc42cb05e4b9568294fe05b279ea3015bbc39b80312be002590cdc68ccbb9f5125c8c80d14240df0b40ad01a847f76268a633ce1
|
7
|
+
data.tar.gz: 1691f847d0914cb362440813a9f8584d3811303b007cec058ca2b278618d3060ce38fbd32edfd7d30936f654e0090ec8f1d23fc41efd4993ad2827784431adf0
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# Release History: opentelemetry-instrumentation-aws_sdk
|
@@ -9,58 +9,86 @@ module OpenTelemetry
|
|
9
9
|
module AwsSdk
|
10
10
|
# Generates Spans for all interactions with AwsSdk
|
11
11
|
class Handler < Seahorse::Client::Handler
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
SQS_SEND_MESSAGE = 'SQS.SendMessage'
|
13
|
+
SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch'
|
14
|
+
SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
|
15
|
+
SNS_PUBLISH = 'SNS.Publish'
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def call(context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
18
|
+
return super unless context
|
19
|
+
|
20
|
+
service_name = context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
|
21
|
+
operation = context.operation&.name
|
22
|
+
client_method = "#{service_name}.#{operation}"
|
23
|
+
attributes = {
|
24
|
+
'aws.region' => context.config.region,
|
25
|
+
OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api',
|
26
|
+
OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => operation,
|
27
|
+
OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_name
|
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'
|
25
32
|
|
33
|
+
tracer.in_span(span_name(context, client_method), attributes: attributes, kind: span_kind(service_name, operation)) do |span|
|
34
|
+
inject_context(context, client_method)
|
26
35
|
if instrumentation_config[:suppress_internal_instrumentation]
|
27
|
-
OpenTelemetry::Common::Utilities.untraced
|
36
|
+
OpenTelemetry::Common::Utilities.untraced { super }
|
28
37
|
else
|
29
|
-
|
38
|
+
super
|
39
|
+
end.tap do |response|
|
40
|
+
if (err = response.error)
|
41
|
+
span.record_exception(err)
|
42
|
+
span.status = Trace::Status.error(err.to_s)
|
43
|
+
end
|
30
44
|
end
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
34
|
-
|
35
|
-
span_attributes = {
|
36
|
-
'aws.region' => context.config.region,
|
37
|
-
OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api',
|
38
|
-
OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => get_operation(context),
|
39
|
-
OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => get_service_name(context)
|
40
|
-
}
|
48
|
+
private
|
41
49
|
|
42
|
-
|
43
|
-
|
50
|
+
def tracer
|
51
|
+
AwsSdk::Instrumentation.instance.tracer
|
44
52
|
end
|
45
53
|
|
46
|
-
def
|
47
|
-
|
54
|
+
def instrumentation_config
|
55
|
+
AwsSdk::Instrumentation.instance.config
|
48
56
|
end
|
49
57
|
|
50
|
-
def
|
51
|
-
|
52
|
-
end
|
58
|
+
def inject_context(context, client_method)
|
59
|
+
return unless [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].include? client_method
|
53
60
|
|
54
|
-
|
55
|
-
|
61
|
+
if client_method == SQS_SEND_MESSAGE_BATCH
|
62
|
+
context.params[:entries].each do |entry|
|
63
|
+
entry[:message_attributes] ||= {}
|
64
|
+
OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
context.params[:message_attributes] ||= {}
|
68
|
+
OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
|
69
|
+
end
|
56
70
|
end
|
57
71
|
|
58
|
-
def
|
59
|
-
|
72
|
+
def span_kind(service_name, client_method)
|
73
|
+
case client_method
|
74
|
+
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
75
|
+
OpenTelemetry::Trace::SpanKind::PRODUCER
|
76
|
+
when SQS_RECEIVE_MESSAGE
|
77
|
+
OpenTelemetry::Trace::SpanKind::CONSUMER
|
78
|
+
else
|
79
|
+
OpenTelemetry::Trace::SpanKind::CLIENT
|
80
|
+
end
|
60
81
|
end
|
61
82
|
|
62
|
-
def
|
63
|
-
|
83
|
+
def span_name(context, client_method)
|
84
|
+
case client_method
|
85
|
+
when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
|
86
|
+
"#{MessagingHelper.queue_name(context)} send"
|
87
|
+
when SQS_RECEIVE_MESSAGE
|
88
|
+
"#{MessagingHelper.queue_name(context)} receive"
|
89
|
+
else
|
90
|
+
client_method
|
91
|
+
end
|
64
92
|
end
|
65
93
|
end
|
66
94
|
|
@@ -12,10 +12,7 @@ module OpenTelemetry
|
|
12
12
|
MINIMUM_VERSION = Gem::Version.new('2.0')
|
13
13
|
|
14
14
|
install do |_config|
|
15
|
-
|
16
|
-
require_relative 'services'
|
17
|
-
require_relative 'db_helper'
|
18
|
-
|
15
|
+
require_dependencies
|
19
16
|
add_plugin(Seahorse::Client::Base, *loaded_constants)
|
20
17
|
end
|
21
18
|
|
@@ -29,6 +26,15 @@ module OpenTelemetry
|
|
29
26
|
|
30
27
|
option :suppress_internal_instrumentation, default: false, validate: :boolean
|
31
28
|
|
29
|
+
private
|
30
|
+
|
31
|
+
def require_dependencies
|
32
|
+
require_relative 'handler'
|
33
|
+
require_relative 'services'
|
34
|
+
require_relative 'message_attribute_setter'
|
35
|
+
require_relative 'messaging_helper'
|
36
|
+
end
|
37
|
+
|
32
38
|
def gem_version
|
33
39
|
if Gem.loaded_specs['aws-sdk']
|
34
40
|
Gem.loaded_specs['aws-sdk'].version
|
@@ -0,0 +1,27 @@
|
|
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
|
+
# The MessageAttributeSetter class provides methods for writing tracing information to
|
11
|
+
# SNS / SQS messages.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
|
15
|
+
class MessageAttributeSetter
|
16
|
+
def self.set(carrier, key, value)
|
17
|
+
# https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html
|
18
|
+
if carrier.length < 10
|
19
|
+
carrier[key] = { string_value: value, data_type: 'String' }
|
20
|
+
else
|
21
|
+
OpenTelemetry.logger.warn('aws-sdk instrumentation: cannot set context propagation on SQS/SNS message due to maximum amount of MessageAttributes')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
# MessagingHelper class provides methods for calculating messaging span attributes
|
11
|
+
class MessagingHelper
|
12
|
+
class << self
|
13
|
+
def queue_name(context) # rubocop:disable Metrics/CyclomaticComplexity
|
14
|
+
topic_arn = params(context, :topic_arn)
|
15
|
+
target_arn = params(context, :target_arn)
|
16
|
+
phone_number = params(context, :phone_number)
|
17
|
+
queue_url = params(context, :queue_url)
|
18
|
+
|
19
|
+
if topic_arn || target_arn
|
20
|
+
arn = topic_arn || target_arn
|
21
|
+
begin
|
22
|
+
return arn.split(':')[-1]
|
23
|
+
rescue StandardError
|
24
|
+
return arn
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
return phone_number if phone_number
|
29
|
+
|
30
|
+
return queue_url.split('/')[-1] if queue_url
|
31
|
+
|
32
|
+
'unknown'
|
33
|
+
end
|
34
|
+
|
35
|
+
def apply_sqs_attributes(attributes, context, client_method)
|
36
|
+
attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
|
37
|
+
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue'
|
38
|
+
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
|
39
|
+
attributes[SemanticConventions::Trace::MESSAGING_URL] = params(context, :queue_url)
|
40
|
+
|
41
|
+
attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
|
42
|
+
end
|
43
|
+
|
44
|
+
def apply_sns_attributes(attributes, context, client_method)
|
45
|
+
attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'
|
46
|
+
|
47
|
+
return unless client_method == 'SNS.Publish'
|
48
|
+
|
49
|
+
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
|
50
|
+
attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
|
51
|
+
end
|
52
|
+
|
53
|
+
def params(context, param)
|
54
|
+
defined?(context.metadata[:original_params][param]) ? context.metadata[:original_params][param] : context.params[param]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aspecto-opentelemetry-instrumentation-aws_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Aspecto Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -222,7 +222,7 @@ dependencies:
|
|
222
222
|
version: 0.1.6
|
223
223
|
description: AWS SDK instrumentation for the OpenTelemetry framework
|
224
224
|
email:
|
225
|
-
-
|
225
|
+
- info@aspecto.io
|
226
226
|
executables: []
|
227
227
|
extensions: []
|
228
228
|
extra_rdoc_files: []
|
@@ -234,19 +234,20 @@ files:
|
|
234
234
|
- lib/opentelemetry-instrumentation-aws_sdk.rb
|
235
235
|
- lib/opentelemetry/instrumentation.rb
|
236
236
|
- lib/opentelemetry/instrumentation/aws_sdk.rb
|
237
|
-
- lib/opentelemetry/instrumentation/aws_sdk/db_helper.rb
|
238
237
|
- lib/opentelemetry/instrumentation/aws_sdk/handler.rb
|
239
238
|
- lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb
|
239
|
+
- lib/opentelemetry/instrumentation/aws_sdk/message_attribute_setter.rb
|
240
|
+
- lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
|
240
241
|
- lib/opentelemetry/instrumentation/aws_sdk/services.rb
|
241
242
|
- lib/opentelemetry/instrumentation/aws_sdk/version.rb
|
242
|
-
homepage: https://
|
243
|
+
homepage: https://aspecto.io
|
243
244
|
licenses:
|
244
245
|
- Apache-2.0
|
245
246
|
metadata:
|
246
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.
|
247
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.4/file.CHANGELOG.html
|
247
248
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/aws_sdk
|
248
249
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
249
|
-
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.
|
250
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.4
|
250
251
|
post_install_message:
|
251
252
|
rdoc_options: []
|
252
253
|
require_paths:
|
@@ -1,28 +0,0 @@
|
|
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
|
-
# DbHelper class provides methods for calculating aws db span attributes
|
11
|
-
class DbHelper
|
12
|
-
class << self
|
13
|
-
def get_db_attributes(context, service_name, operation)
|
14
|
-
return get_dynamodb_attributes(context, operation) if service_name == 'DynamoDB'
|
15
|
-
|
16
|
-
{}
|
17
|
-
end
|
18
|
-
|
19
|
-
def get_dynamodb_attributes(context, operation)
|
20
|
-
{
|
21
|
-
SemanticConventions::Trace::DB_SYSTEM => 'dynamodb'
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|