-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,462 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
module Aws | ||
module Plugins | ||
# @api private | ||
class Telemetry < Seahorse::Client::Plugin | ||
option( | ||
:telemetry_provider, | ||
default: Aws::Telemetry::NoOpTelemetryProvider, | ||
doc_type: Aws::Telemetry::TelemetryProviderBase, | ||
rbs_type: Aws::Telemetry::TelemetryProviderBase, | ||
docstring: <<-DOCS) do |_cfg| | ||
Allows you to provide a telemetry provider, which is used to | ||
emit telemetry data. By default, uses `NoOpTelemetryProvider` which | ||
will not record or emit any telemetry data. The SDK supports the | ||
following telemetry providers: | ||
* OpenTelemetry (OTel) - To use the OTel provider, install and require the | ||
`opentelemetry-sdk` gem and then, pass in an instance of a | ||
`Aws::Telemetry::OTelProvider` for telemetry provider. | ||
DOCS | ||
Aws::Telemetry::NoOpTelemetryProvider.new | ||
end | ||
|
||
def after_initialize(client) | ||
validate_telemetry_provider(client.config) | ||
end | ||
|
||
def validate_telemetry_provider(config) | ||
unless config.telemetry_provider.is_a?(Aws::Telemetry::TelemetryProviderBase) | ||
raise ArgumentError, | ||
'Must provide a telemetry provider for the '\ | ||
'`telemetry_provider` configuration option.' | ||
end | ||
end | ||
|
||
class Handler < Seahorse::Client::Handler | ||
def call(context) | ||
span_wrapper(context) { @handler.call(context) } | ||
end | ||
|
||
private | ||
|
||
def span_wrapper(context, &block) | ||
service_id = service_id(context) | ||
attributes = { | ||
'rpc.system' => 'aws-api', | ||
'rpc.service' => service_id, | ||
'rpc.method' => context.operation.name, | ||
'code.function' => context.operation_name.to_s, | ||
'code.namespace' => 'Aws::Plugins::Telemetry' | ||
} | ||
context.tracer.in_span( | ||
parent_span_name(context, service_id), | ||
attributes: attributes, | ||
kind: Aws::Telemetry::SpanKind::CLIENT, | ||
&block | ||
) | ||
end | ||
|
||
def service_id(context) | ||
context.config.api.metadata['serviceId'] || | ||
context.config.api.metadata['serviceAbbreviation'] || | ||
context.config.api.metadata['serviceFullName'] | ||
end | ||
|
||
def parent_span_name(context, service_id) | ||
"#{service_id}.#{context.operation.name}".delete(' ') | ||
end | ||
end | ||
|
||
handler(Handler, step: :initialize, priority: 99) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'telemetry/base' | ||
require_relative 'telemetry/no_op' | ||
require_relative 'telemetry/otel' | ||
require_relative 'telemetry/span_kind' | ||
require_relative 'telemetry/span_status' | ||
|
||
module Aws | ||
# Observability is the extent to which a system's current state can be | ||
# inferred from the data it emits. The data emitted is commonly referred | ||
# as Telemetry. The AWS SDK for Ruby currently supports traces as | ||
# a telemetry signal. | ||
# | ||
# A telemetry provider is used to emit telemetry data. By default, the | ||
# {NoOpTelemetryProvider} will not record or emit any telemetry data. | ||
# The SDK currently supports OpenTelemetry (OTel) as a provider. See | ||
# {OTelProvider} for more information. | ||
# | ||
# If a provider isn't supported, you can implement your own provider by | ||
# inheriting the following base classes and implementing the interfaces | ||
# defined: | ||
# * {TelemetryProviderBase} | ||
# * {ContextManagerBase} | ||
# * {TracerProviderBase} | ||
# * {TracerBase} | ||
# * {SpanBase} | ||
module Telemetry | ||
class << self | ||
# @api private | ||
def module_to_tracer_name(module_name) | ||
"#{module_name.gsub('::', '.')}.client".downcase | ||
end | ||
|
||
# @api private | ||
def http_request_attrs(context) | ||
{ | ||
'http.method' => context.http_request.http_method, | ||
'net.protocol.name' => 'http' | ||
}.tap do |h| | ||
h['net.protocol.version'] = | ||
if context.client.is_a? Seahorse::Client::AsyncBase | ||
'2' | ||
else | ||
Net::HTTP::HTTPVersion | ||
end | ||
|
||
unless context.config.stub_responses | ||
h['net.peer.name'] = context.http_request.endpoint.host | ||
h['net.peer.port'] = context.http_request.endpoint.port.to_s | ||
end | ||
|
||
if context.http_request.headers.key?('Content-Length') | ||
h['http.request_content_length'] = | ||
context.http_request.headers['Content-Length'] | ||
end | ||
end | ||
end | ||
|
||
# @api private | ||
def http_response_attrs(context) | ||
{ | ||
'http.status_code' => context.http_response.status_code.to_s | ||
}.tap do |h| | ||
if context.http_response.headers.key?('Content-Length') | ||
h['http.response_content_length'] = | ||
context.http_response.headers['Content-Length'] | ||
end | ||
|
||
if context.http_response.headers.key?('x-amz-request-id') | ||
h['aws.request_id'] = | ||
context.http_response.headers['x-amz-request-id'] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.