Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Context propagation data is always added to SQS and SNS requests regardless of sampling decision.
This enables downstream services to make consistent sampling decisions and prevents incomplete traces.
([#2447](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2447))

## 1.10.0-beta.3

Released 2024-Dec-20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public override async Task<T> InvokeAsync<T>(IExecutionContext executionContext)
return ret;
}

private static void AddPropagationDataToRequest(Activity activity, IRequestContext requestContext)
{
var service = requestContext.ServiceMetaData.ServiceId;

if (AWSServiceType.IsSqsService(service))
{
SqsRequestContextHelper.AddAttributes(
requestContext, AWSMessagingUtils.InjectIntoDictionary(new PropagationContext(activity.Context, Baggage.Current)));
}
else if (AWSServiceType.IsSnsService(service))
{
SnsRequestContextHelper.AddAttributes(
requestContext, AWSMessagingUtils.InjectIntoDictionary(new PropagationContext(activity.Context, Baggage.Current)));
}
}

#if NET
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(
"Trimming",
Expand Down Expand Up @@ -167,16 +183,6 @@ private void AddRequestSpecificInformation(Activity activity, IRequestContext re
{
this.awsSemanticConventions.TagBuilder.SetTagAttributeDbSystemToDynamoDb(activity);
}
else if (AWSServiceType.IsSqsService(service))
{
SqsRequestContextHelper.AddAttributes(
requestContext, AWSMessagingUtils.InjectIntoDictionary(new PropagationContext(activity.Context, Baggage.Current)));
}
else if (AWSServiceType.IsSnsService(service))
{
SnsRequestContextHelper.AddAttributes(
requestContext, AWSMessagingUtils.InjectIntoDictionary(new PropagationContext(activity.Context, Baggage.Current)));
}
else if (AWSServiceType.IsBedrockRuntimeService(service))
{
this.awsSemanticConventions.TagBuilder.SetTagAttributeGenAiSystemToBedrock(activity);
Expand All @@ -202,14 +208,21 @@ private void ProcessEndRequest(Activity? activity, IExecutionContext executionCo

var currentActivity = Activity.Current;

if (currentActivity == null
|| !currentActivity.Source.Name.StartsWith(TelemetryConstants.TelemetryScopePrefix, StringComparison.Ordinal)
|| !currentActivity.IsAllDataRequested)
if (currentActivity == null)
{
return null;
}

this.AddRequestSpecificInformation(currentActivity, executionContext.RequestContext);
if (currentActivity.IsAllDataRequested
&& currentActivity.Source.Name.StartsWith(TelemetryConstants.TelemetryScopePrefix, StringComparison.Ordinal))
{
this.AddRequestSpecificInformation(currentActivity, executionContext.RequestContext);
}

// Context propagation should always happen regardless of sampling decision (which affects Activity.IsAllDataRequested and Activity.Source).
// Otherwise, downstream services can make inconsistent sampling decisions and create incomplete traces.
AddPropagationDataToRequest(currentActivity, executionContext.RequestContext);

return currentActivity;
}
}