Skip to content

Commit 0400e13

Browse files
lailabougriaHEskandarimikeminutilloTim Bussmann
authoredJul 11, 2022
Initial support for OpenTelemetry (#6410)
Co-Authored-By: Hadi Eskandari <H.Eskandari@Gmail.com> Co-authored-by: Mike Minutillo <mike.minutillo@particular.net> Co-authored-by: Laila Bougria <laila.bougria@particular.net> Co-authored-by: Tim Bussmann <tim.bussmann@particular.net>
1 parent f7d93a4 commit 0400e13

File tree

86 files changed

+3969
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3969
-50
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace NServiceBus.AcceptanceTests.Core.OpenTelemetry;
2+
3+
using System;
4+
using System.Collections.Immutable;
5+
using System.Diagnostics;
6+
using NUnit.Framework;
7+
8+
public static class ActivityTestingExtensions
9+
{
10+
public static void VerifyTag(this ImmutableDictionary<string, string> tags, string tagName, string expectedValue)
11+
{
12+
Assert.IsTrue(tags.TryGetValue(tagName, out var tagValue), $"Tags should contain key '{tagName}'");
13+
Assert.AreEqual(expectedValue, tagValue, $"Tag value with key '{tagName}' is incorrect");
14+
}
15+
16+
/// <summary>
17+
/// Checks tags for duplicate tag keys.
18+
/// </summary>
19+
public static void VerifyUniqueTags(this Activity activity)
20+
{
21+
var tagsList = activity.Tags.ToImmutableList();
22+
23+
if (tagsList.Count < 2)
24+
{
25+
return;
26+
}
27+
28+
var sortedTags = tagsList.Sort((a, b) => StringComparer.CurrentCultureIgnoreCase.Compare(a.Key, b.Key));
29+
30+
for (int i = 0; i < sortedTags.Count - 1; i++)
31+
{
32+
if (StringComparer.InvariantCultureIgnoreCase.Equals(sortedTags[i].Key, sortedTags[i + 1].Key))
33+
{
34+
Assert.Fail($"duplicate tag found: {sortedTags[i].Key}. Tags should be unique.");
35+
}
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace NServiceBus.AcceptanceTests.Core.OpenTelemetry;
2+
3+
using NUnit.Framework;
4+
5+
[NonParallelizable] // Ensure only activities for the current test are captured
6+
public class OpenTelemetryAcceptanceTest : NServiceBusAcceptanceTest
7+
{
8+
protected TestingActivityListener NServicebusActivityListener { get; private set; }
9+
10+
[SetUp]
11+
public void Setup() => NServicebusActivityListener = TestingActivityListener.SetupDiagnosticListener("NServiceBus.Core");
12+
13+
[TearDown]
14+
public void Cleanup()
15+
{
16+
NServicebusActivityListener?.VerifyAllActivitiesCompleted();
17+
NServicebusActivityListener?.Dispose();
18+
}
19+
}

0 commit comments

Comments
 (0)
Please sign in to comment.