You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had to get custom to implement extracting traceparent + tracestate from my SQS consuming BackgroundService. A lot of it's inspiration came from AWSLambdaWrapper.Trace. I would like the same thing as AWSLambdaWrapper.Trace for non-lambda SQS consumers.
What is the expected behavior?
There is a Trace extraction and propagation wrapper/helper for non-Lambda SQS Consumers (BackgroundService, CLI tool, whatever).
Which alternative solutions or features have you considered?
publicstaticvoidMain(string[]args){Host.CreateDefaultBuilder(args).ConfigureServices((context,services)=>{varactivitySource=newActivitySource(Assembly.GetExecutingAssembly().FullName!);services.AddSingleton(activitySource);services.AddAWSService<IAmazonSimpleNotificationService>();services.AddAWSService<IAmazonSQS>();services.AddOpenTelemetry().WithTracing(tracerBuilder =>{tracerBuilder.AddSource(activitySource.Name).AddAWSInstrumentation();});services.AddSingleton<IHostedService,Service>();}).Build().Run();}publicclassService:BackgroundService{privatereadonlyActivitySource_activitySource;privatereadonlyIAmazonSQS_sqsClient;privatereadonlyIAmazonSimpleNotificationService_snsClient;publicService(ActivitySourceactivitySource,IAmazonSQSsqsClient,IAmazonSimpleNotificationServicesnsClient){_activitySource=activitySource;_sqsClient=sqsClient;_snsClient=snsClient;}protectedasyncoverrideTaskExecuteAsync(CancellationTokencancellationToken){varreceiveMessageResponse=await_sqsClient.ReceiveMessageAsync(newReceiveMessageRequest{QueueUrl="queue-url",MessageAttributeNames=["traceparent","tracestate"],},cancellationToken);if(!receiveMessageResponse.Messages.Any()){return;}foreach(varmessageinreceiveMessageResponse.Messages){// Extract incoming trace information from the SQSMessage, if there is any.varparentContext=TraceContext.Extract(message);// Start an Activity, which is .NETs way of starting Traces. If there was a trace extracted from the// incoming SQSMessage then that trace will be continued. If not, then a new trace will be started.using(_activitySource.StartActivity("ExecuteAsync",ActivityKind.Server,parentContext.ActivityContext)){// This call will now automatically include traceparent and tracestate in MessageAttributes// thanks to the "AddAWSInstrumentation(...)".await_snsClient.PublishAsync(...);}}}}
Additional context
No response
The text was updated successfully, but these errors were encountered:
Component
None
Is your feature request related to a problem?
I had to get custom to implement extracting traceparent + tracestate from my SQS consuming BackgroundService. A lot of it's inspiration came from AWSLambdaWrapper.Trace. I would like the same thing as AWSLambdaWrapper.Trace for non-lambda SQS consumers.
What is the expected behavior?
There is a Trace extraction and propagation wrapper/helper for non-Lambda SQS Consumers (BackgroundService, CLI tool, whatever).
Which alternative solutions or features have you considered?
Additional context
No response
The text was updated successfully, but these errors were encountered: