Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AWS SDK Changes to support Bedrock spans and Application Signals #2458

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

AsakerMohd
Copy link
Contributor

Changes

Added changes to detect bedrock spans and populate attributes accordingly. Also added logic to populate aws specific attributes used by AWS Application Signals like "aws.region", "aws.service", "aws.operation", "aws.requestId", etc. We are currently using our own fork of Opentelemetry-Instrumentation-AWS here: https://github.com/aws-observability/aws-otel-dotnet-instrumentation/tree/main/src/OpenTelemetry.Instrumentation.AWS. This change syncs our local fork so that we can stop relying on it and instead reference this directly instead.

I did some manual testing and was able to verify that the spans created contain the required information.

Pushing this PR for now to get some review going while we add some unit tests for the Bedrock related changes. Will add changes to CHANGELOG.md. No changes to public API.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@AsakerMohd AsakerMohd requested a review from a team as a code owner January 8, 2025 18:33
@github-actions github-actions bot added the comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS label Jan 8, 2025
@github-actions github-actions bot requested review from ppittle and srprash January 8, 2025 18:33
@AsakerMohd AsakerMohd changed the title Aws sdk changes Added AWS SDK Changes to support Bedrock and Application Signals Jan 8, 2025
@AsakerMohd AsakerMohd changed the title Added AWS SDK Changes to support Bedrock and Application Signals Added AWS SDK Changes to support Bedrock spans and Application Signals Jan 8, 2025
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.20%. Comparing base (71655ce) to head (8f09005).
Report is 678 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2458       +/-   ##
===========================================
+ Coverage   73.91%   84.20%   +10.28%     
===========================================
  Files         267       34      -233     
  Lines        9615      747     -8868     
===========================================
- Hits         7107      629     -6478     
+ Misses       2508      118     -2390     
Files with missing lines Coverage Δ
...rumentation.AWS/Implementation/AWSServiceHelper.cs 93.33% <ø> (-6.67%) ⬇️
...strumentation.AWS/Implementation/AWSServiceType.cs 71.42% <ø> (+4.76%) ⬆️
...on.AWS/Implementation/AWSTracingPipelineHandler.cs 87.17% <ø> (-0.58%) ⬇️

... and 271 files with indirect coverage changes

public override string AttributeAWSRegion => "aws.region";
public override string AttributeAWSServiceName => "aws.service";
public override string AttributeAWSOperationName => "aws.operation";
public override string AttributeAWSRequestId => "aws.requestId";
Copy link
Member

@muhammad-othman muhammad-othman Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already added these attributes from the SDK side using different names (rpc.method & rpc.service)
https://github.com/aws/aws-sdk-net-staging/blob/main-staging/sdk/src/Core/Amazon.Runtime/Telemetry/TelemetryConstants.cs#L37

And for aws.requestId we use aws.request_id to be aligned with the semantic conventions aws.request_id schema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to request_id. For the aws.region, i don't see it being added anywhere in the sdk side. I guess I don't need to use aws.service and aws.operation anymore and can just read the needed info from the rpc.* tags. I'll remove them.

@AsakerMohd
Copy link
Contributor Author

Not sure why the bedrock sem cov test is failing for v1.28. I didn't change how the sem covs are set there.

{
var results = resultsArray[0];
if (results.TryGetProperty("tokenCount", out var outputTokens))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of these empty if statements?

should this just be:

resutls.TryGetProperty("tokenCount", out var outputTokens);

}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch (Exception ex)
        {
            Console.WriteLine("Exception: " + ex.Message);

I forget, is this standard practice for exception handling within this library? I'm fine swallowing parsing exceptions - but I don't recall if there is a preferred channel to let the user know there was a problem.

/// <summary>
/// Not yet incorporated in Semantic Conventions repository.
/// </summary>
public virtual string AttributeAWSRegion => string.Empty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Semantic Convention has AttributeCloudRegion - can we use that instead?

/// <summary>
/// Not yet incorporated in Semantic Conventions repository. Check if more details need to be added
/// </summary>
public virtual string AttributeGenAiTopP => string.Empty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// <summary>
/// Not yet incorporated in Semantic Conventions repository. Check if more details need to be added
/// </summary>
public virtual string AttributeGenAiTemperature => string.Empty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -74,6 +84,12 @@ private abstract class AWSSemanticConventionsLegacy : AWSSemanticConventionsBase
// GEN AI Attributes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the GenAI documentation page, it looks like the new GenAI attributes all existed prior to v1.27: https://github.com/open-telemetry/semantic-conventions/blob/v1.27.0/docs/gen-ai/gen-ai-spans.md

Is that correct?

@@ -89,6 +105,7 @@ private abstract class AWSSemanticConventionsLegacy : AWSSemanticConventionsBase
public override string AttributeHttpTarget => "http.target";
[Obsolete("Replaced by <c>http.request.method</c>.")]
public override string AttributeHttpMethod => "http.method";
public override string AttributeHttpResponseContentLength => "http.response_content_length";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attribute is deprecated in v1.27 and newer: https://github.com/open-telemetry/semantic-conventions/blob/v1.27.0/docs/attributes-registry/http.md?plain=1#L93:

Deprecated, use `http.response.header.<key>` instead.

Can you update this to use http.response.header.` attribute instead.

public virtual string AttributeAWSSQSQueueName => string.Empty;

/// <summary>
/// Not yet incorporated in Semantic Conventions repository.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public virtual string AttributeAWSRegion => string.Empty;

/// <summary>
/// Not yet incorporated in Semantic Conventions repository.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public override string AttributeAWSSQSQueueName => "aws.sqs.queue_name";
public override string AttributeAWSS3BucketName => "aws.s3.bucket";
public override string AttributeAWSKinesisStreamName => "aws.kinesis.stream_name";
public override string AttributeAWSLambdaResourceMappingId => "aws.lambda.resource_mapping.id";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the attributes that are not yet part of the Semantic Convention - I'm not sure if they should be added as "Legacy".

I'm also not sure if they should be added to an existing code page - ie it feels odd to add them to say v.1.29.0 when they aren't actually part of that spec either.

Any thoughts on this?

OR - it might be better to first send a PR to the Semantic Convention repo and get the attributes added - then they'll be part of a SemConv release and we wont have this problem. Given they're attributes are all in the AWS namespace I would expect the PR to be accepted rather quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants