diff --git a/.github/workflows/all_solutions.yml b/.github/workflows/all_solutions.yml index 567aa648a..f8dd45d0c 100644 --- a/.github/workflows/all_solutions.yml +++ b/.github/workflows/all_solutions.yml @@ -510,7 +510,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -577,7 +577,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -688,7 +688,7 @@ jobs: if: always() steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/.github/workflows/assignproj.yml b/.github/workflows/assignproj.yml index d5ac11f63..2893ad038 100644 --- a/.github/workflows/assignproj.yml +++ b/.github/workflows/assignproj.yml @@ -16,7 +16,7 @@ jobs: name: Assign to One Project steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/.github/workflows/build_profiler.yml b/.github/workflows/build_profiler.yml index d34d423e5..1b23d8d98 100644 --- a/.github/workflows/build_profiler.yml +++ b/.github/workflows/build_profiler.yml @@ -193,7 +193,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit @@ -347,7 +347,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit diff --git a/.github/workflows/check_modified_files.yml b/.github/workflows/check_modified_files.yml index 7d8cf88d0..d1dc074bd 100644 --- a/.github/workflows/check_modified_files.yml +++ b/.github/workflows/check_modified_files.yml @@ -22,7 +22,7 @@ jobs: non-workflow-files-changed: ${{ steps.filter.outputs.non-workflow-files-changed }} steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5756e10ce..06aa25a90 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -49,7 +49,7 @@ jobs: fetch-depth: 0 - name: Initialize CodeQL - uses: github/codeql-action/init@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # v3.25.12 + uses: github/codeql-action/init@2d790406f505036ef40ecba973cc774a50395aac # v3.25.13 with: languages: csharp @@ -59,7 +59,7 @@ jobs: shell: powershell - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # v3.25.12 + uses: github/codeql-action/analyze@2d790406f505036ef40ecba973cc774a50395aac # v3.25.13 with: category: "/language:csharp" @@ -84,7 +84,7 @@ jobs: fetch-depth: 0 - name: Initialize CodeQL - uses: github/codeql-action/init@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # v3.25.12 + uses: github/codeql-action/init@2d790406f505036ef40ecba973cc774a50395aac # v3.25.13 with: languages: c-cpp @@ -100,6 +100,6 @@ jobs: shell: powershell - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # v3.25.12 + uses: github/codeql-action/analyze@2d790406f505036ef40ecba973cc774a50395aac # v3.25.13 with: category: "/language:c-cpp" diff --git a/.github/workflows/deploy_agent.yml b/.github/workflows/deploy_agent.yml index 027ab6d08..4e0147fb2 100644 --- a/.github/workflows/deploy_agent.yml +++ b/.github/workflows/deploy_agent.yml @@ -61,7 +61,7 @@ jobs: workflow_run_id: ${{ steps.step2.outputs.workflow_run_id }} steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -155,7 +155,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -350,7 +350,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit diff --git a/.github/workflows/markdowncheck.yml b/.github/workflows/markdowncheck.yml index 74d21818e..70990a0ab 100644 --- a/.github/workflows/markdowncheck.yml +++ b/.github/workflows/markdowncheck.yml @@ -22,7 +22,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit # Leave it audit mode diff --git a/.github/workflows/multiverse_run.yml b/.github/workflows/multiverse_run.yml index 30d240baa..8eeeab07a 100644 --- a/.github/workflows/multiverse_run.yml +++ b/.github/workflows/multiverse_run.yml @@ -36,7 +36,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit @@ -102,7 +102,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit diff --git a/.github/workflows/nuget_slack_notifications.yml b/.github/workflows/nuget_slack_notifications.yml index 4f28da294..fef375015 100644 --- a/.github/workflows/nuget_slack_notifications.yml +++ b/.github/workflows/nuget_slack_notifications.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit # Leave it audit mode diff --git a/.github/workflows/post_deploy_agent.yml b/.github/workflows/post_deploy_agent.yml index e6365f5fb..3e7fd52b2 100644 --- a/.github/workflows/post_deploy_agent.yml +++ b/.github/workflows/post_deploy_agent.yml @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: false egress-policy: audit @@ -78,7 +78,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -119,7 +119,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -143,7 +143,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -171,7 +171,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/.github/workflows/publish_release_notes.yml b/.github/workflows/publish_release_notes.yml index 20b0c59bb..9ce277048 100644 --- a/.github/workflows/publish_release_notes.yml +++ b/.github/workflows/publish_release_notes.yml @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 2fc7c955c..35ab16d39 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/.github/workflows/repolinter.yml b/.github/workflows/repolinter.yml index 0bab8d3fb..512e34081 100644 --- a/.github/workflows/repolinter.yml +++ b/.github/workflows/repolinter.yml @@ -31,7 +31,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/.github/workflows/run_integration_tests.yml b/.github/workflows/run_integration_tests.yml index c9e8f2c59..868257f7b 100644 --- a/.github/workflows/run_integration_tests.yml +++ b/.github/workflows/run_integration_tests.yml @@ -44,7 +44,7 @@ jobs: unbounded-tests-matrix: ${{ steps.configure_unbounded_tests_matrix.outputs.matrix }} steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit diff --git a/.github/workflows/run_linux_container_tests.yml b/.github/workflows/run_linux_container_tests.yml index 08bcb4e2c..60cdce8c1 100644 --- a/.github/workflows/run_linux_container_tests.yml +++ b/.github/workflows/run_linux_container_tests.yml @@ -42,12 +42,12 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: egress-policy: audit - name: Docker Setup QEMU - uses: docker/setup-qemu-action@5927c834f5b4fdf503fca6f4c7eccda82949e1ee # v3.1.0 + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 4639fbf25..10f9efe75 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit @@ -73,6 +73,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # v3.25.12 + uses: github/codeql-action/upload-sarif@2d790406f505036ef40ecba973cc774a50395aac # v3.25.13 with: sarif_file: results.sarif diff --git a/.github/workflows/scripts/nugetSlackNotifications/nugetSlackNotifications.csproj b/.github/workflows/scripts/nugetSlackNotifications/nugetSlackNotifications.csproj index 78ee31f3f..19813cd6b 100644 --- a/.github/workflows/scripts/nugetSlackNotifications/nugetSlackNotifications.csproj +++ b/.github/workflows/scripts/nugetSlackNotifications/nugetSlackNotifications.csproj @@ -6,7 +6,7 @@ - + diff --git a/.github/workflows/set_community_label.yml b/.github/workflows/set_community_label.yml index 7edbf30b3..77ac76fc0 100644 --- a/.github/workflows/set_community_label.yml +++ b/.github/workflows/set_community_label.yml @@ -15,7 +15,7 @@ jobs: issues: write steps: - name: Harden Runner - uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0 with: disable-sudo: true egress-policy: audit diff --git a/src/Agent/MsiInstaller/Installer/Installer.csproj b/src/Agent/MsiInstaller/Installer/Installer.csproj index 113c76d8b..b74f3a124 100644 --- a/src/Agent/MsiInstaller/Installer/Installer.csproj +++ b/src/Agent/MsiInstaller/Installer/Installer.csproj @@ -18,10 +18,10 @@ - - - - + + + + diff --git a/src/Agent/MsiInstaller/InstallerActions/InstallerActions.csproj b/src/Agent/MsiInstaller/InstallerActions/InstallerActions.csproj index 4a6a9cead..d014ec018 100644 --- a/src/Agent/MsiInstaller/InstallerActions/InstallerActions.csproj +++ b/src/Agent/MsiInstaller/InstallerActions/InstallerActions.csproj @@ -18,8 +18,8 @@ - - + + diff --git a/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs b/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs index 128fa381b..bc772687c 100644 --- a/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs +++ b/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs @@ -1,15 +1,9 @@ // Copyright 2020 New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -using System.Collections.Concurrent; -using System; using System.Collections.Generic; -using System.Threading.Tasks; using NewRelic.Agent.Api; -using NewRelic.Agent.Extensions.AwsSdk; using NewRelic.Agent.Extensions.Providers.Wrapper; -using NewRelic.Reflection; -using System.Linq; namespace NewRelic.Providers.Wrapper.AwsSdk { @@ -18,9 +12,7 @@ public class AwsSdkPipelineWrapper : IWrapper public bool IsTransactionRequired => true; private const string WrapperName = "AwsSdkPipelineWrapper"; - private static readonly ConcurrentDictionary> _getRequestResponseFromGeneric = new(); private static HashSet _unsupportedRequestTypes = new(); - private static HashSet _unsupportedSQSRequestTypes = new(); public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo) { @@ -60,7 +52,7 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins if (requestType.StartsWith("Amazon.SQS")) { - return HandleSQSRequest(instrumentedMethodCall, agent, transaction, request, isAsync, executionContext); + return SQSRequestHandler.HandleSQSRequest(instrumentedMethodCall, agent, transaction, request, isAsync, executionContext); } if (_unsupportedRequestTypes.Add(requestType)) // log once per unsupported request type @@ -68,113 +60,5 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins 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) - { - case "SendMessageRequest": - case "SendMessageBatchRequest": - action = MessageBrokerAction.Produce; - break; - case "ReceiveMessageRequest": - action = MessageBrokerAction.Consume; - break; - case "PurgeQueueRequest": - action = MessageBrokerAction.Purge; - break; - default: - 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; - } - - var dtHeaders = agent.GetConfiguredDTHeaders(); - - string requestQueueUrl = request.QueueUrl; - ISegment segment = SqsHelper.GenerateSegment(transaction, instrumentedMethodCall.MethodCall, requestQueueUrl, action); - if (action == MessageBrokerAction.Produce) - { - if (requestType == "SendMessageRequest") - { - if (request.MessageAttributes == null) - { - agent.Logger.Debug("AwsSdkPipelineWrapper: requestContext.OriginalRequest.MessageAttributes is null, unable to insert distributed trace headers."); - } - else - { - SqsHelper.InsertDistributedTraceHeaders(transaction, request, dtHeaders.Count); - } - } - else if (requestType == "SendMessageBatchRequest") - { - // loop through each message in the batch and insert distributed trace headers - foreach (var message in request.Entries) - { - if (message.MessageAttributes == null) - { - agent.Logger.Debug("AwsSdkPipelineWrapper: requestContext.OriginalRequest.Entries.MessageAttributes is null, unable to insert distributed trace headers."); - } - else - { - SqsHelper.InsertDistributedTraceHeaders(transaction, message, dtHeaders.Count); - } - } - } - } - - // modify the request to ask for DT headers in the response message attributes. - if (action == MessageBrokerAction.Consume) - { - if (request.MessageAttributeNames == null) - request.MessageAttributeNames = new List(); - - foreach (var header in dtHeaders) - request.MessageAttributeNames.Add(header); - } - - if (isAsync) - { - return Delegates.GetAsyncDelegateFor(agent, segment, true, ProcessResponse, TaskContinuationOptions.ExecuteSynchronously); - - void ProcessResponse(Task responseTask) - { - if (!ValidTaskResponse(responseTask) || (segment == null) || action != MessageBrokerAction.Consume) - return; - - // taskResult is a ReceiveMessageResponse - var taskResultGetter = _getRequestResponseFromGeneric.GetOrAdd(responseTask.GetType(), t => VisibilityBypasser.Instance.GeneratePropertyAccessor(t, "Result")); - dynamic receiveMessageResponse = taskResultGetter(responseTask); - - // accept distributed trace headers from the first message in the response - SqsHelper.AcceptDistributedTraceHeaders(transaction, receiveMessageResponse.Messages[0].MessageAttributes); - } - } - - return Delegates.GetDelegateFor( - onComplete: segment.End, - onSuccess: () => - { - if (action != MessageBrokerAction.Consume) - return; - - var ec = executionContext; - var response = ec.ResponseContext.Response; // response is a ReceiveMessageResponse - - // accept distributed trace headers from the first message in the response - SqsHelper.AcceptDistributedTraceHeaders(transaction, response.Messages[0].MessageAttributes); - } - ); - } - - private static bool ValidTaskResponse(Task response) - { - return response?.Status == TaskStatus.RanToCompletion; - } } } diff --git a/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/SQSRequestHandler.cs b/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/SQSRequestHandler.cs new file mode 100644 index 000000000..1af74c48b --- /dev/null +++ b/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/SQSRequestHandler.cs @@ -0,0 +1,135 @@ +// Copyright 2020 New Relic, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading.Tasks; +using NewRelic.Agent.Api; +using NewRelic.Agent.Extensions.AwsSdk; +using NewRelic.Agent.Extensions.Providers.Wrapper; +using NewRelic.Reflection; + +namespace NewRelic.Providers.Wrapper.AwsSdk +{ + internal static class SQSRequestHandler + { + private static readonly ConcurrentDictionary> _getRequestResponseFromGeneric = new(); + private static readonly HashSet _unsupportedSQSRequestTypes = []; + + public static AfterWrappedMethodDelegate HandleSQSRequest(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction, dynamic request, bool isAsync, dynamic executionContext) + { + var requestType = request.GetType().Name; + + MessageBrokerAction action; + switch (requestType) + { + case "SendMessageRequest": + case "SendMessageBatchRequest": + action = MessageBrokerAction.Produce; + break; + case "ReceiveMessageRequest": + action = MessageBrokerAction.Consume; + break; + case "PurgeQueueRequest": + action = MessageBrokerAction.Purge; + break; + default: + 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; + } + + var dtHeaders = agent.GetConfiguredDTHeaders(); + + string requestQueueUrl = request.QueueUrl; + ISegment segment = SqsHelper.GenerateSegment(transaction, instrumentedMethodCall.MethodCall, requestQueueUrl, action); + switch (action) + { + case MessageBrokerAction.Produce when requestType == "SendMessageRequest": + { + if (request.MessageAttributes == null) + { + agent.Logger.Debug("AwsSdkPipelineWrapper: requestContext.OriginalRequest.MessageAttributes is null, unable to insert distributed trace headers."); + } + else + { + SqsHelper.InsertDistributedTraceHeaders(transaction, request, dtHeaders.Count); + } + + break; + } + case MessageBrokerAction.Produce: + { + if (requestType == "SendMessageBatchRequest") + { + // loop through each message in the batch and insert distributed trace headers + foreach (var message in request.Entries) + { + if (message.MessageAttributes == null) + { + agent.Logger.Debug("AwsSdkPipelineWrapper: requestContext.OriginalRequest.Entries.MessageAttributes is null, unable to insert distributed trace headers."); + } + else + { + SqsHelper.InsertDistributedTraceHeaders(transaction, message, dtHeaders.Count); + } + } + } + + break; + } + + // modify the request to ask for DT headers in the response message attributes. + case MessageBrokerAction.Consume: + { + // create a new list or clone the existing one so we don't modify the original list + request.MessageAttributeNames = request.MessageAttributeNames == null ? new List() : new List(request.MessageAttributeNames); + + foreach (var header in dtHeaders) + request.MessageAttributeNames.Add(header); + + break; + } + } + + return isAsync ? + Delegates.GetAsyncDelegateFor(agent, segment, true, ProcessResponse, TaskContinuationOptions.ExecuteSynchronously) + : + Delegates.GetDelegateFor( + onComplete: segment.End, + onSuccess: () => + { + if (action != MessageBrokerAction.Consume) + return; + + var ec = executionContext; + var response = ec.ResponseContext.Response; // response is a ReceiveMessageResponse + + // accept distributed trace headers from the first message in the response + SqsHelper.AcceptDistributedTraceHeaders(transaction, response.Messages[0].MessageAttributes); + } + ); + + void ProcessResponse(Task responseTask) + { + if (!ValidTaskResponse(responseTask) || (segment == null) || action != MessageBrokerAction.Consume) + return; + + // taskResult is a ReceiveMessageResponse + var taskResultGetter = _getRequestResponseFromGeneric.GetOrAdd(responseTask.GetType(), t => VisibilityBypasser.Instance.GeneratePropertyAccessor(t, "Result")); + dynamic receiveMessageResponse = taskResultGetter(responseTask); + + // accept distributed trace headers from the first message in the response + SqsHelper.AcceptDistributedTraceHeaders(transaction, receiveMessageResponse.Messages[0].MessageAttributes); + } + } + + private static bool ValidTaskResponse(Task response) + { + return response?.Status == TaskStatus.RanToCompletion; + } + + } +} diff --git a/tests/Agent/IntegrationTests/ContainerApplications/AwsSdkTestApp/AwsSdkExerciser/AwsSdkExerciser.cs b/tests/Agent/IntegrationTests/ContainerApplications/AwsSdkTestApp/AwsSdkExerciser/AwsSdkExerciser.cs index 77e2a0ec9..1299a341f 100644 --- a/tests/Agent/IntegrationTests/ContainerApplications/AwsSdkTestApp/AwsSdkExerciser/AwsSdkExerciser.cs +++ b/tests/Agent/IntegrationTests/ContainerApplications/AwsSdkTestApp/AwsSdkExerciser/AwsSdkExerciser.cs @@ -104,13 +104,19 @@ public async Task> SQS_ReceiveMessageAsync(int maxMessagesT throw new InvalidOperationException("Queue URL is not set. Call SQS_Initialize or SQS_SetQueueUrl first."); } + List messageAttributeNames = ["All"]; + var response = await _amazonSqsClient.ReceiveMessageAsync(new ReceiveMessageRequest { QueueUrl = _sqsQueueUrl, MaxNumberOfMessages = maxMessagesToReceive, - MessageAttributeNames = ["All"] + MessageAttributeNames = messageAttributeNames }); + + if (messageAttributeNames.Count != 1) + throw new Exception("Expected messageAttributeNames to have a single element"); + foreach (var message in response.Messages) { Console.WriteLine($"Message: {message.Body}"); diff --git a/tests/Agent/IntegrationTests/ContainerIntegrationTests/Fixtures/AwsSdkContainerTestFixtures.cs b/tests/Agent/IntegrationTests/ContainerIntegrationTests/Fixtures/AwsSdkContainerTestFixtures.cs index 15262be13..fb9c6a7d9 100644 --- a/tests/Agent/IntegrationTests/ContainerIntegrationTests/Fixtures/AwsSdkContainerTestFixtures.cs +++ b/tests/Agent/IntegrationTests/ContainerIntegrationTests/Fixtures/AwsSdkContainerTestFixtures.cs @@ -41,6 +41,8 @@ public void ExerciseSQS_SendReceivePurge(string queueName) { var address = $"http://localhost:{Port}/awssdk"; + // The exerciser will return a 500 error if the `RequestMessage.MessageAttributeNames` collection is modified by our instrumentation. + // See https://github.com/newrelic/newrelic-dotnet-agent/pull/2646 GetAndAssertStatusCode($"{address}/SQS_SendReceivePurge?queueName={queueName}", System.Net.HttpStatusCode.OK); } diff --git a/tests/Agent/IntegrationTests/IntegrationTests.sln b/tests/Agent/IntegrationTests/IntegrationTests.sln index 974b8a593..8a2b0522b 100644 --- a/tests/Agent/IntegrationTests/IntegrationTests.sln +++ b/tests/Agent/IntegrationTests/IntegrationTests.sln @@ -183,6 +183,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSerializationHelpers", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSerializationHelpers.Test", "..\Shared\TestSerializationHelpers.Test\TestSerializationHelpers.Test.csproj", "{D33E155E-C7EC-49F1-AA24-B293A74F472D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MFALatestPackages", "SharedApplications\Common\MFALatestPackages\MFALatestPackages.csproj", "{78C0CA57-4E16-4E3E-B0CF-E8C9259BA1F2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -417,6 +419,10 @@ Global {D33E155E-C7EC-49F1-AA24-B293A74F472D}.Debug|Any CPU.Build.0 = Debug|Any CPU {D33E155E-C7EC-49F1-AA24-B293A74F472D}.Release|Any CPU.ActiveCfg = Release|Any CPU {D33E155E-C7EC-49F1-AA24-B293A74F472D}.Release|Any CPU.Build.0 = Release|Any CPU + {78C0CA57-4E16-4E3E-B0CF-E8C9259BA1F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78C0CA57-4E16-4E3E-B0CF-E8C9259BA1F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78C0CA57-4E16-4E3E-B0CF-E8C9259BA1F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78C0CA57-4E16-4E3E-B0CF-E8C9259BA1F2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -472,6 +478,7 @@ Global {8F7EBBC3-B22F-43AC-978E-2CD8AD7C02CF} = {F0F6F2CE-8AE8-49E1-8EE9-A44B451EFC29} {31DB04AF-2ED3-4379-98D7-7D02F38864F9} = {F0F6F2CE-8AE8-49E1-8EE9-A44B451EFC29} {472F6F9A-97E9-4DC3-9D70-AE79A20FA240} = {F0F6F2CE-8AE8-49E1-8EE9-A44B451EFC29} + {78C0CA57-4E16-4E3E-B0CF-E8C9259BA1F2} = {30CF078E-E531-441E-83AB-24AB9B1C179F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3830ABDF-4AEA-4D91-83A2-13F091D1DF5F} diff --git a/tests/Agent/IntegrationTests/SharedApplications/Common/MFALatestPackages/MFALatestPackages.csproj b/tests/Agent/IntegrationTests/SharedApplications/Common/MFALatestPackages/MFALatestPackages.csproj new file mode 100644 index 000000000..f969f512f --- /dev/null +++ b/tests/Agent/IntegrationTests/SharedApplications/Common/MFALatestPackages/MFALatestPackages.csproj @@ -0,0 +1,94 @@ + + + + net481;net8.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/MultiFunctionApplicationHelpers.csproj b/tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/MultiFunctionApplicationHelpers.csproj index ac5081373..875661905 100644 --- a/tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/MultiFunctionApplicationHelpers.csproj +++ b/tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/MultiFunctionApplicationHelpers.csproj @@ -11,16 +11,12 @@ - - - - @@ -28,15 +24,11 @@ - - - - - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -46,11 +38,9 @@ - - @@ -60,83 +50,67 @@ - - - - - - - - - - - - - - - - @@ -149,10 +123,6 @@ - - - - @@ -165,12 +135,6 @@ - - - - - - NU1701 @@ -203,16 +167,12 @@ - - - - @@ -227,24 +187,12 @@ - - - - - - - - - - - - @@ -255,13 +203,6 @@ - - - - - - - @@ -277,9 +218,7 @@ - - @@ -312,8 +251,6 @@ - - @@ -325,15 +262,14 @@ - - + diff --git a/tests/Agent/IntegrationTests/UnboundedIntegrationTests.sln b/tests/Agent/IntegrationTests/UnboundedIntegrationTests.sln index 08ab617db..ee5a75db3 100644 --- a/tests/Agent/IntegrationTests/UnboundedIntegrationTests.sln +++ b/tests/Agent/IntegrationTests/UnboundedIntegrationTests.sln @@ -48,6 +48,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSerializationHelpers", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSerializationHelpers.Test", "..\Shared\TestSerializationHelpers.Test\TestSerializationHelpers.Test.csproj", "{06DC61C8-F4BF-47C5-8624-1F441E6C2A04}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MFALatestPackages", "SharedApplications\Common\MFALatestPackages\MFALatestPackages.csproj", "{C544A8F0-A222-42AF-91C8-9F556C293C11}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -118,6 +120,10 @@ Global {06DC61C8-F4BF-47C5-8624-1F441E6C2A04}.Debug|Any CPU.Build.0 = Debug|Any CPU {06DC61C8-F4BF-47C5-8624-1F441E6C2A04}.Release|Any CPU.ActiveCfg = Release|Any CPU {06DC61C8-F4BF-47C5-8624-1F441E6C2A04}.Release|Any CPU.Build.0 = Release|Any CPU + {C544A8F0-A222-42AF-91C8-9F556C293C11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C544A8F0-A222-42AF-91C8-9F556C293C11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C544A8F0-A222-42AF-91C8-9F556C293C11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C544A8F0-A222-42AF-91C8-9F556C293C11}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -131,9 +137,10 @@ Global {3E8423E9-1FBF-451F-8117-88CE3DADEF7F} = {129FF113-1F3A-4DAA-8D6F-287DF67A68FA} {B64766CA-8731-493F-8417-61A70F783EB7} = {129FF113-1F3A-4DAA-8D6F-287DF67A68FA} {F35861EC-9861-4776-AF51-9C2B7F1DBA5C} = {129FF113-1F3A-4DAA-8D6F-287DF67A68FA} + {C544A8F0-A222-42AF-91C8-9F556C293C11} = {129FF113-1F3A-4DAA-8D6F-287DF67A68FA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.Data.6.0.1304.0\lib\NET45 SolutionGuid = {656848E2-BFD2-4092-9328-C6CDF39B1274} + EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.Data.6.0.1304.0\lib\NET45 EndGlobalSection EndGlobal