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

chore: Refactor AwsSDKPipelineWrapper to encapsulate SQS handling #2621

Merged
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AwsSdkPipelineWrapper : IWrapper

private const string WrapperName = "AwsSdkPipelineWrapper";
private static readonly ConcurrentDictionary<Type, Func<object, object>> _getRequestResponseFromGeneric = new();
private static HashSet<string> _unsupportedRequestTypes = new();
private static HashSet<string> _unsupportedSQSRequestTypes = new();

public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
{
Expand Down Expand Up @@ -54,9 +56,23 @@ 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);
if (requestType.StartsWith("Amazon.SQS"))
{
return HandleSQSRequest(instrumentedMethodCall, agent, transaction, request, isAsync, executionContext);
}

if (_unsupportedRequestTypes.Add(requestType)) // log once per unsupported request type
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)
Expand All @@ -72,7 +88,9 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
action = MessageBrokerAction.Purge;
break;
default:
agent.Logger.Finest($"AwsSdkPipelineWrapper: Request type {requestType} is not supported. Returning NoOp delegate.");
if (_unsupportedSQSRequestTypes.Add(requestType)) // log once per unsupported request type
agent.Logger.Debug($"AwsSdkPipelineWrapper: SQS Request type {requestType} is not supported. Returning NoOp delegate.");

return Delegates.NoOp;
}

Expand Down Expand Up @@ -116,7 +134,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
Loading