Skip to content

Commit 5d4fd5b

Browse files
tippmar-nrGitHub Copilot
andcommitted
chore: Add debug logging for MassTransit URI parsing exceptions
Log caught exceptions in MassTransitHelpers.GetQueueDataFromUri using Log.Debug, following the pattern used by other connection string parsers in the Extensions library. Add unit test to verify the catch block returns default values. Co-authored-by: GitHub Copilot <copilot@github.com>
1 parent 597e65b commit 5d4fd5b

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Helpers/MassTransit.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System;
5+
using NewRelic.Agent.Extensions.Logging;
56
using NewRelic.Agent.Extensions.Providers.Wrapper;
67

78

@@ -107,8 +108,10 @@ private static MassTransitQueueData GetQueueDataFromUri(Uri sourceAddress)
107108

108109
return data;
109110
}
110-
catch
111+
catch (Exception ex)
111112
{
113+
Log.Debug(ex, "Unexpected error parsing MassTransit URI. Falling back to default values.");
114+
112115
return data;
113116
}
114117
}
@@ -227,4 +230,4 @@ private static bool HasQueryParam(Uri uri, string key, string value = null)
227230

228231
return false;
229232
}
230-
}
233+
}

tests/Agent/UnitTests/NewRelic.Agent.Extensions.Tests/Helpers/MassTransitHelperTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,20 @@ public void GetQueueData_FallbackAddress(Uri primary, Uri fallback, string expec
125125
Assert.That(data.DestinationType, Is.EqualTo(expectedDestType));
126126
});
127127
}
128-
}
128+
129+
[Test]
130+
public void GetQueueData_ReturnsDefaults_WhenParsingThrows()
131+
{
132+
// A relative Uri passes the null check but throws InvalidOperationException
133+
// when .Scheme is accessed, exercising the catch block.
134+
var relativeUri = new Uri("relative-path", UriKind.Relative);
135+
136+
var data = MassTransitHelpers.GetQueueData(relativeUri);
137+
138+
Assert.Multiple(() =>
139+
{
140+
Assert.That(data.QueueName, Is.EqualTo("Unknown"));
141+
Assert.That(data.DestinationType, Is.EqualTo(MessageBrokerDestinationType.Queue));
142+
});
143+
}
144+
}

0 commit comments

Comments
 (0)