Skip to content

Commit

Permalink
chore: Refactor AwsSDKPipelineWrapper to encapsulate SQS handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jul 11, 2024
1 parent 814a557 commit 348aa9e
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,25 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
return Delegates.NoOp;
}
dynamic request = requestContext.OriginalRequest;
string requestType = request.GetType().Name;
string requestType = request.GetType().FullName;
agent.Logger.Finest($"AwsSdkPipelineWrapper: Request type is {requestType}");

agent.Logger.Finest("AwsSdkPipelineWrapper: Request type is " + requestType);
if (requestType.StartsWith("Amazon.SQS"))
{
return HandleSQSRequest(instrumentedMethodCall, agent, transaction, request, isAsync, executionContext);
}

agent.Logger.Debug($"AwsSdkPipelineWrapper: Unsupported request type: {requestType}. Returning NoOp delegate.");
return Delegates.NoOp;
}

private static AfterWrappedMethodDelegate HandleSQSRequest(InstrumentedMethodCall instrumentedMethodCall, IAgent agent,
ITransaction transaction, dynamic request, bool isAsync, dynamic executionContext)
{
var requestType = request.GetType().Name;

MessageBrokerAction action;
switch (requestType)
switch (requestType )
{
case "SendMessageRequest":
case "SendMessageBatchRequest":
Expand All @@ -72,7 +85,7 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
action = MessageBrokerAction.Purge;
break;
default:
agent.Logger.Finest($"AwsSdkPipelineWrapper: Request type {requestType} is not supported. Returning NoOp delegate.");
agent.Logger.Finest($"AwsSdkPipelineWrapper: SQS Request type {requestType } is not supported. Returning NoOp delegate.");
return Delegates.NoOp;
}

Expand All @@ -82,7 +95,7 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
ISegment segment = SqsHelper.GenerateSegment(transaction, instrumentedMethodCall.MethodCall, requestQueueUrl, action);
if (action == MessageBrokerAction.Produce)
{
if (requestType == "SendMessageRequest")
if (requestType == "SendMessageRequest")
{
if (request.MessageAttributes == null)
{
Expand All @@ -93,7 +106,7 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
SqsHelper.InsertDistributedTraceHeaders(transaction, request, dtHeaders.Count);
}
}
else if (requestType == "SendMessageBatchRequest")
else if (requestType == "SendMessageBatchRequest")
{
// loop through each message in the batch and insert distributed trace headers
foreach (var message in request.Entries)
Expand All @@ -116,7 +129,7 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
if (request.MessageAttributeNames == null)
request.MessageAttributeNames = new List<string>();

foreach(var header in dtHeaders)
foreach (var header in dtHeaders)
request.MessageAttributeNames.Add(header);
}

Expand Down

0 comments on commit 348aa9e

Please sign in to comment.