-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integration with V3 telemetry provider (#1186)
* feat: Integration with V3 telemetry provider * Fix CI failure * Fix CI failure - attempt 2 * Fix CI failure - attempt 3 * Fix CI failure - attempt 4 * Add minor cleanup * Address feedbacks * Add handler helper to contain shared methods * Add config documentation * Add minor update * Update based on feedbacks --------- Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com>
- Loading branch information
1 parent
745c333
commit a71d905
Showing
12 changed files
with
853 additions
and
315 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
81 changes: 81 additions & 0 deletions
81
instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler_helper.rb
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,81 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module AwsSdk | ||
# Utility module that contains shared methods between AwsSdk and Telemetry handlers | ||
module HandlerHelper | ||
class << self | ||
def instrumentation_config | ||
AwsSdk::Instrumentation.instance.config | ||
end | ||
|
||
def client_method(service_id, context) | ||
"#{service_id}.#{context.operation.name}".delete(' ') | ||
end | ||
|
||
def span_attributes(context, client_method, service_id, legacy: false) | ||
{ | ||
'aws.region' => context.config.region, | ||
OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => context.operation_name.to_s, | ||
OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => 'Aws::Plugins::Telemetry', | ||
OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => context.operation.name, | ||
OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_id, | ||
OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api' | ||
}.tap do |attrs| | ||
attrs[OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE] = 'Aws::Plugins::AwsSdk' if legacy | ||
attrs[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_id == 'DynamoDB' | ||
|
||
MessagingHelper.apply_span_attributes(context, attrs, client_method, service_id) if MessagingHelper::SUPPORTED_SERVICES.include?(service_id) | ||
end | ||
end | ||
|
||
def span_kind(client_method, service_id) | ||
case service_id | ||
when *MessagingHelper::SUPPORTED_SERVICES | ||
MessagingHelper.span_kind(client_method) | ||
else | ||
OpenTelemetry::Trace::SpanKind::CLIENT | ||
end | ||
end | ||
|
||
def span_name(context, client_method, service_id, legacy: false) | ||
case service_id | ||
when *MessagingHelper::SUPPORTED_SERVICES | ||
if legacy | ||
MessagingHelper.legacy_span_name(context, client_method) | ||
else | ||
MessagingHelper.span_name(context, client_method) | ||
end | ||
else | ||
client_method | ||
end | ||
end | ||
|
||
def service_id(context, legacy: false) | ||
if legacy | ||
legacy_service_id(context) | ||
else | ||
context.config.api.metadata['serviceId'] || | ||
context.config.api.metadata['serviceAbbreviation'] || | ||
context.config.api.metadata['serviceFullName'] | ||
end | ||
end | ||
|
||
private | ||
|
||
def legacy_service_id(context) | ||
# Support aws-sdk v2.0.x, which 'metadata' has a setter method only | ||
return context.client.class.to_s.split('::')[1] if ::Seahorse::Model::Api.instance_method(:metadata).parameters.length.positive? | ||
|
||
context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1] | ||
end | ||
end | ||
end | ||
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
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
Oops, something went wrong.