refactor: moving telemetry wip

This commit is contained in:
Stevan Freeborn
2025-06-03 16:31:09 -05:00
parent 852f27c7b5
commit 8e0ec2d3d5
9 changed files with 69 additions and 17 deletions
@@ -7,12 +7,12 @@ public class HostExtensionsTests
{
var builder = WebApplication.CreateBuilder();
builder.AddTelemetry(static () => new StevesBotWebhookInstrumentation());
builder.AddTelemetry(static () => new TestInstrumentation());
var app = builder.Build();
app.Services
.GetService<StevesBotWebhookInstrumentation>()
.GetService<TestInstrumentation>()
.Should()
.BeNull();
@@ -42,7 +42,7 @@ public class HostExtensionsTests
builder.Configuration.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(json)));
builder.AddTelemetry(static () => new StevesBotWebhookInstrumentation());
builder.AddTelemetry(static () => new TestInstrumentation());
var app = builder.Build();
@@ -62,4 +62,16 @@ public class HostExtensionsTests
.Should()
.NotBeNull();
}
private class TestInstrumentation : IInstrumentation
{
public string SourceName { get; } = "TestSource";
public string SourceVersion { get; } = "1.0.0";
public ActivitySource Source { get; } = new ActivitySource("TestSource", "1.0.0");
public void Dispose()
{
Source.Dispose();
}
}
}
@@ -1,32 +0,0 @@
namespace StevesBot.Library.Tests.Unit;
public sealed class StevesBotWebhookInstrumentationTests : IDisposable
{
private readonly StevesBotWebhookInstrumentation _instrumentation = new();
[Fact]
public void SourceName_WhenCalled_ItShouldReturnCorrectName()
{
_instrumentation.SourceName.Should().Be("StevesBot.Webhook");
}
[Fact]
public void SourceVersion_WhenCalled_ItShouldReturnCorrectVersion()
{
_instrumentation.SourceVersion.Should().Be("0.0.0");
}
[Fact]
public void Constructor_WhenCalled_ItShouldReturnInstance()
{
using var result = new StevesBotWebhookInstrumentation();
using var expectedSource = new ActivitySource(_instrumentation.SourceName, _instrumentation.SourceVersion);
result.Source.Should().BeEquivalentTo(expectedSource);
}
public void Dispose()
{
_instrumentation.Dispose();
}
}
@@ -1,32 +0,0 @@
namespace StevesBot.Library.Tests.Unit;
public sealed class StevesBotWorkerInstrumentationTests : IDisposable
{
private readonly StevesBotWorkerInstrumentation _instrumentation = new();
[Fact]
public void SourceName_WhenCalled_ItShouldReturnCorrectName()
{
_instrumentation.SourceName.Should().Be("StevesBot.Worker");
}
[Fact]
public void SourceVersion_WhenCalled_ItShouldReturnCorrectVersion()
{
_instrumentation.SourceVersion.Should().Be("0.0.0");
}
[Fact]
public void Constructor_WhenCalled_ItShouldReturnInstance()
{
using var result = new StevesBotWorkerInstrumentation();
using var expectedSource = new ActivitySource(_instrumentation.SourceName, _instrumentation.SourceVersion);
result.Source.Should().BeEquivalentTo(expectedSource);
}
public void Dispose()
{
_instrumentation.Dispose();
}
}