Skip to content

Commit 737b4f1

Browse files
authored
fix: Fix misleading log message on transaction name change. (#1857) (#1886)
1 parent 46c8f56 commit 737b4f1

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

src/Agent/NewRelic/Agent/Core/Wrapper/AgentWrapperApi/Builders/CandidateTransactionName.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public bool TrySet(ITransactionName transactionName, TransactionNamePriority pri
6161
_transaction.LogFinest($"Ignoring transaction name {FormatTransactionName(transactionName, priority)} because existing transaction name is frozen.");
6262
else if (_currentTransactionName == null)
6363
_transaction.LogFinest($"Setting transaction name to {FormatTransactionName(transactionName, priority)} from [nothing]");
64-
else if (priority > _highestPriority)
64+
else if ((priority == TransactionNamePriority.UserTransactionName) || (priority > _highestPriority))
6565
_transaction.LogFinest($"Setting transaction name to {FormatTransactionName(transactionName, priority)} from {FormatTransactionName(_currentTransactionName, _highestPriority)}");
6666
else
6767
_transaction.LogFinest($"Ignoring transaction name {FormatTransactionName(transactionName, priority)} in favor of existing name {FormatTransactionName(_currentTransactionName, _highestPriority)}");

tests/Agent/IntegrationTests/IntegrationTestHelpers/AgentLogBase.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ public abstract class AgentLogBase
6868
public const string SpanStreamingSuccessfullySentLogLineRegex = FinestLogLinePrefixRegex + @"SpanStreamingService: consumer \d+ - Attempting to send (\d+) item\(s\) - Success";
6969
public const string SpanStreamingSuccessfullyProcessedByServerResponseLogLineRegex = FinestLogLinePrefixRegex + @"SpanStreamingService: consumer \d+ - Received gRPC Server response messages: (\d+)";
7070
public const string SpanStreamingResponseGrpcError = FinestLogLinePrefixRegex + @"ResponseStreamWrapper: consumer \d+ - gRPC RpcException encountered while handling gRPC server responses: (.*)";
71-
71+
72+
// Transactions (either with an ID or "noop")
73+
public const string TransactionLinePrefix = FinestLogLinePrefixRegex + @"Trx ([a-fA-F0-9]*|Noop): ";
74+
7275
public AgentLogBase(RemoteApplication remoteApplication)
7376
{
7477
_remoteApplication = remoteApplication;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2020 New Relic, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using MultiFunctionApplicationHelpers;
8+
using NewRelic.Agent.IntegrationTestHelpers;
9+
using NewRelic.Agent.IntegrationTestHelpers.Models;
10+
using NewRelic.Testing.Assertions;
11+
using Xunit;
12+
using Xunit.Abstractions;
13+
14+
namespace NewRelic.Agent.IntegrationTests.Api
15+
{
16+
public abstract class TransactionNameTests<TFixture> : NewRelicIntegrationTest<TFixture> where TFixture : ConsoleDynamicMethodFixture
17+
{
18+
protected readonly TFixture Fixture;
19+
20+
public TransactionNameTests(TFixture fixture, ITestOutputHelper output) : base(fixture)
21+
{
22+
Fixture = fixture;
23+
Fixture.TestLogger = output;
24+
25+
Fixture.AddCommand("ApiCalls TestSetTransactionName TestGroup OriginalName,NewName");
26+
27+
Fixture.Actions
28+
(
29+
setupConfiguration: () =>
30+
{
31+
var configModifier = new NewRelicConfigModifier(Fixture.DestinationNewRelicConfigFilePath);
32+
configModifier.SetOrDeleteDistributedTraceEnabled(true);
33+
configModifier.SetLogLevel("finest");
34+
}
35+
);
36+
37+
Fixture.Initialize();
38+
}
39+
40+
[Fact]
41+
public void TestSetTransactionName()
42+
{
43+
var setNameLines = Fixture.AgentLog.TryGetLogLines(AgentLogBase.TransactionLinePrefix + "Setting transaction name to.*?");
44+
Assert.Equal(2, setNameLines.Count());
45+
46+
Assert.NotNull(Fixture.AgentLog.TryGetTransactionEvent("OtherTransaction/TestGroup/NewName"));
47+
Assert.Null(Fixture.AgentLog.TryGetTransactionEvent("OtherTransaction/TestGroup/OriginalName"));
48+
49+
// Note the trailing space is necessary here, or we'll find "Ignoring transaction_segment_term with invalid prefix" which is unrelated
50+
var notConnectedLogLine = Fixture.AgentLog.TryGetLogLine(AgentLogBase.TransactionLinePrefix + "Ignoring transaction name ");
51+
Assert.Null(notConnectedLogLine);
52+
53+
}
54+
}
55+
56+
[NetFrameworkTest]
57+
public class TransactionNameTestsFW : TransactionNameTests<ConsoleDynamicMethodFixtureFWLatest>
58+
{
59+
public TransactionNameTestsFW(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output)
60+
: base(fixture, output)
61+
{
62+
}
63+
}
64+
65+
[NetCoreTest]
66+
public class TransactionNameTestsCore : TransactionNameTests<ConsoleDynamicMethodFixtureCoreLatest>
67+
{
68+
public TransactionNameTestsCore(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output)
69+
: base(fixture, output)
70+
{
71+
}
72+
}
73+
}

tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/NetStandardLibraries/ApiCalls.cs

+18
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,23 @@ private static string ErrorGroupCallback(IReadOnlyDictionary<string, object> att
8282
}
8383
return errorGroupName;
8484
}
85+
86+
/// <summary>
87+
/// Tests setting the current transaction name via the API
88+
/// </summary>
89+
/// <param name="category">Category</param>
90+
/// <param name="names">Comma-separated list of names to be applied, in order</param>
91+
[LibraryMethod]
92+
[Transaction]
93+
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
94+
public static void TestSetTransactionName(string category, string names)
95+
{
96+
var namesList = names.Split(',');
97+
foreach (var name in namesList)
98+
{
99+
NewRelic.Api.Agent.NewRelic.SetTransactionName(category, name);
100+
}
101+
}
102+
85103
}
86104
}

0 commit comments

Comments
 (0)