diff --git a/src/Agent/NewRelic/Agent/Core/DistributedTracing/DistributedTracePayloadHandler.cs b/src/Agent/NewRelic/Agent/Core/DistributedTracing/DistributedTracePayloadHandler.cs index fd9c16586a..ca3490b1c7 100644 --- a/src/Agent/NewRelic/Agent/Core/DistributedTracing/DistributedTracePayloadHandler.cs +++ b/src/Agent/NewRelic/Agent/Core/DistributedTracing/DistributedTracePayloadHandler.cs @@ -74,6 +74,10 @@ public void InsertDistributedTraceHeaders(IInternalTransaction transaction, T setter(carrier, Constants.DistributedTracePayloadKeyAllLower, distributedTracePayload); } } + else + { + transaction.SetSampled(_adaptiveSampler); + } var createOutboundTraceContextHeadersSuccess = false; try diff --git a/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs b/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs index 9da57d6a69..a566bac2b4 100644 --- a/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs +++ b/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs @@ -243,6 +243,25 @@ public void SetOrDeleteDistributedTraceEnabled(bool? enabled) } } + /// + /// Sets or deletes the excludeNewrelicHeader setting in the newrelic.config. + /// + /// If null, the setting will be deleted; otherwise, the setting will be set to the value of this parameter. + public void SetOrDeleteDistributedTraceExcludeNewRelicHeader(bool? exclude) + { + const string config = "configuration"; + const string distributedTracing = "distributedTracing"; + if (null == exclude) + { + CommonUtils.DeleteXmlNodeFromNewRelicConfig(_configFilePath, new[] { config }, distributedTracing); + } + else + { + CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(_configFilePath, new[] { config, distributedTracing }, + "excludeNewrelicHeader", exclude.Value ? "true" : "false"); + } + } + public NewRelicConfigModifier SetAllowAllHeaders(bool? enabled) { const string config = "configuration"; diff --git a/tests/Agent/IntegrationTests/IntegrationTests/DistributedTracing/W3CInstrumentationTests/HttpClientW3CTestsNetCore.cs b/tests/Agent/IntegrationTests/IntegrationTests/DistributedTracing/W3CInstrumentationTests/HttpClientW3CTestsNetCore.cs index e04174781b..7a6473df16 100644 --- a/tests/Agent/IntegrationTests/IntegrationTests/DistributedTracing/W3CInstrumentationTests/HttpClientW3CTestsNetCore.cs +++ b/tests/Agent/IntegrationTests/IntegrationTests/DistributedTracing/W3CInstrumentationTests/HttpClientW3CTestsNetCore.cs @@ -19,7 +19,7 @@ namespace NewRelic.Agent.IntegrationTests.DistributedTracing.W3CInstrumentationT /// Instrumentations occur in this test are AspNetCore and HttpClient. /// [NetCoreTest] - public class HttpClientW3CTestsNetCore : NewRelicIntegrationTest + public abstract class HttpClientW3CTestsNetCore : NewRelicIntegrationTest { private readonly AspNetCoreDistTraceRequestChainFixture _fixture; @@ -30,11 +30,12 @@ public class HttpClientW3CTestsNetCore : NewRelicIntegrationTest @@ -46,7 +47,6 @@ public HttpClientW3CTestsNetCore(AspNetCoreDistTraceRequestChainFixture fixture, }; _fixture.ExecuteTraceRequestChain("CallNext", "CallNext", "CallEnd", headers); - _fixture.FirstCallAppAgentLog.WaitForLogLines(AgentLogBase.TransactionTransformCompletedLogLineRegex, TimeSpan.FromSeconds(15), ExpectedTransactionCount); _fixture.SecondCallAppAgentLog.WaitForLogLines(AgentLogBase.TransactionTransformCompletedLogLineRegex, TimeSpan.FromSeconds(15), ExpectedTransactionCount); _fixture.AgentLog.WaitForLogLines(AgentLogBase.TransactionTransformCompletedLogLineRegex, TimeSpan.FromSeconds(15), ExpectedTransactionCount); @@ -120,13 +120,17 @@ public void Test() var senderExpectedMetrics = new List { - new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/CreatePayload/Success", callCount = 1 }, new Assertions.ExpectedMetric { metricName = @"Supportability/SpanEvent/TotalEventsSeen", callCount = 4 }, new Assertions.ExpectedMetric { metricName = @"Supportability/TraceContext/Accept/Success", callCount = 1 }, new Assertions.ExpectedMetric { metricName = @"Supportability/TraceContext/Create/Success", callCount = 1 }, new Assertions.ExpectedMetric { metricName = @"Supportability/TraceContext/TraceState/NoNrEntry", callCount = 1 } }; + if (! _fixture.ExcludeNewRelicHeader) + { + senderExpectedMetrics.Add(new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/CreatePayload/Success", callCount = 1 }); + } + var accountId = _fixture.SecondCallAppAgentLog.GetAccountId(); var appId = _fixture.SecondCallAppAgentLog.GetApplicationId(); @@ -157,4 +161,22 @@ public void Test() ); } } + + public class HttpClientW3CTestsNetCoreWithNRHeader : HttpClientW3CTestsNetCore + { + public HttpClientW3CTestsNetCoreWithNRHeader(AspNetCoreDistTraceRequestChainFixture fixture, ITestOutputHelper output) + : base(fixture, output, excludeNewRelicHeader: false) + { + } + + } + + public class HttpClientW3CTestsNetCoreWithoutNRHeader : HttpClientW3CTestsNetCore + { + public HttpClientW3CTestsNetCoreWithoutNRHeader(AspNetCoreDistTraceRequestChainFixture fixture, ITestOutputHelper output) + : base(fixture, output, excludeNewRelicHeader: true) + { + } + } + } diff --git a/tests/Agent/IntegrationTests/IntegrationTests/RemoteServiceFixtures/AspNetCoreDistTraceRequestChainFixture.cs b/tests/Agent/IntegrationTests/IntegrationTests/RemoteServiceFixtures/AspNetCoreDistTraceRequestChainFixture.cs index 0007f3162d..5a2c6969fe 100644 --- a/tests/Agent/IntegrationTests/IntegrationTests/RemoteServiceFixtures/AspNetCoreDistTraceRequestChainFixture.cs +++ b/tests/Agent/IntegrationTests/IntegrationTests/RemoteServiceFixtures/AspNetCoreDistTraceRequestChainFixture.cs @@ -1,7 +1,6 @@ // Copyright 2020 New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 - using System; using System.Collections.Generic; using NewRelic.Agent.IntegrationTestHelpers; @@ -18,6 +17,8 @@ public class AspNetCoreDistTraceRequestChainFixture : RemoteApplicationFixture public RemoteService FirstCallApplication { get; set; } public RemoteService SecondCallApplication { get; set; } + public bool ExcludeNewRelicHeader = false; + private AgentLogFile _firstCallAppAgentLog; private AgentLogFile _secondCallAppAgentLog; @@ -42,8 +43,8 @@ public AspNetCoreDistTraceRequestChainFixture() configModifier.SetLogLevel("all"); //Do during setup so TestLogger is set. - FirstCallApplication = SetupDistributedTracingApplication(); - SecondCallApplication = SetupDistributedTracingApplication(); + FirstCallApplication = SetupDistributedTracingApplication(ExcludeNewRelicHeader); + SecondCallApplication = SetupDistributedTracingApplication(ExcludeNewRelicHeader); var environmentVariables = new Dictionary(); @@ -74,7 +75,7 @@ public void ExecuteTraceRequestChain(string firstAppAction, string secondAppActi } } - protected RemoteService SetupDistributedTracingApplication() + protected RemoteService SetupDistributedTracingApplication(bool excludeNewRelicHeader) { var service = new RemoteService( ApplicationDirectoryName, @@ -93,6 +94,7 @@ protected RemoteService SetupDistributedTracingApplication() var configModifier = new NewRelicConfigModifier(service.DestinationNewRelicConfigFilePath); configModifier.SetOrDeleteDistributedTraceEnabled(true); configModifier.SetOrDeleteSpanEventsEnabled(true); + configModifier.SetOrDeleteDistributedTraceExcludeNewRelicHeader(excludeNewRelicHeader); configModifier.SetLogLevel("all"); return service;