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
+40
View File
@@ -0,0 +1,40 @@
name: StevesBot
services:
webhook:
container_name: steves-bot-webhook
image: stevanfreeborn/steves-bot:${WEBHOOK_VERSION}
ports:
- '34827:8080'
restart: always
environment:
- Logging__LogLevel__Default=Debug
- Logging__LogLevel__Microsoft=Information
- Logging__LogLevel__Microsoft.Hosting.Lifetime=Information
- YouTubeClientOptions__BaseUrl=${YOUTUBE_BASE_URL}
- YouTubeClientOptions__ApiKey=${YOUTUBE_API_KEY}
- SubscriptionOptions__CallbackUrl=${SUBSCRIPTION_CALLBACK_URL}
- SubscriptionOptions__TopicUrl=${SUBSCRIPTION_TOPIC_URL}
- PubSubClientOptions__BaseUrl=${PUBSUB_BASE_URL}
- DiscordClientOptions__ApiUrl=${DISCORD_API_URL}
- DiscordClientOptions__AppToken=${DISCORD_APP_TOKEN}
- DiscordClientOptions__Intents=${DISCORD_INTENTS}
- DiscordNotificationOptions__ChannelId=${DISCORD_NOTIFICATION_CHANNEL_ID}
- DiscordNotificationOptions__MessageFormat="${DISCORD_NOTIFICATION_MESSAGE_FORMAT}"
- SeqOptions__ServerUrl=${SEQ_SERVER_URL}
- SeqOptions__ApiKeyHeader=${SEQ_API_KEY_HEADER}
- SeqOptions__ApiKey=${SEQ_API_KEY}
- DOTNET_ENVIRONMENT=Production
worker:
container_name: steves-bot-worker
image: stevanfreeborn/steves-bot:${WORKER_VERSION}
environment:
- Logging__LogLevel__Default=Debug
- Logging__LogLevel__Microsoft=Information
- Logging__LogLevel__Microsoft.Hosting.Lifetime=Information
- DiscordClientOptions__ApiUrl=${DISCORD_API_URL}
- DiscordClientOptions__AppToken=${DISCORD_APP_TOKEN}
- DiscordClientOptions__Intents=${DISCORD_INTENTS}
- SeqOptions__ServerUrl=${SEQ_SERVER_URL}
- SeqOptions__ApiKeyHeader=${SEQ_API_KEY_HEADER}
- SeqOptions__ApiKey=${SEQ_API_KEY}
- DOTNET_ENVIRONMENT=Production
@@ -1,8 +1,8 @@
using System.Diagnostics; using System.Diagnostics;
namespace StevesBot.Library.Telemetry; namespace StevesBot.Webhook.Telemetry;
public sealed class StevesBotWebhookInstrumentation : IInstrumentation internal sealed class StevesBotWebhookInstrumentation : IInstrumentation
{ {
private const string SourceNameValue = "StevesBot.Webhook"; private const string SourceNameValue = "StevesBot.Webhook";
private const string SourceVersionValue = "0.0.0"; private const string SourceVersionValue = "0.0.0";
@@ -1,8 +1,8 @@
using System.Diagnostics; using System.Diagnostics;
namespace StevesBot.Library.Telemetry; namespace StevesBot.Worker.Telemetry;
public sealed class StevesBotWorkerInstrumentation : IInstrumentation internal sealed class StevesBotWorkerInstrumentation : IInstrumentation
{ {
private const string SourceNameValue = "StevesBot.Worker"; private const string SourceNameValue = "StevesBot.Worker";
private const string SourceVersionValue = "0.0.0"; private const string SourceVersionValue = "0.0.0";
+4 -4
View File
@@ -7,16 +7,16 @@ global using System.Text.Json.Serialization;
global using Microsoft.Extensions.Options; global using Microsoft.Extensions.Options;
global using StevesBot.Library.Discord; global using StevesBot.Library.Discord;
global using StevesBot.Library.Discord.Common;
global using StevesBot.Library.Discord.Rest;
global using StevesBot.Library.Discord.Rest.Requests;
global using StevesBot.Library.Telemetry; global using StevesBot.Library.Telemetry;
global using StevesBot.Worker; global using StevesBot.Worker;
global using StevesBot.Worker.Discord; global using StevesBot.Worker.Discord;
global using StevesBot.Worker.Discord.Gateway; global using StevesBot.Worker.Discord.Gateway;
global using StevesBot.Worker.Discord.Gateway.Events; global using StevesBot.Worker.Discord.Gateway.Events;
global using StevesBot.Worker.Discord.Gateway.Events.Data; global using StevesBot.Worker.Discord.Gateway.Events.Data;
global using StevesBot.Library.Discord.Rest;
global using StevesBot.Library.Discord.Rest.Requests;
global using StevesBot.Library.Discord.Common;
global using StevesBot.Worker.Handlers; global using StevesBot.Worker.Handlers;
global using StevesBot.Worker.Telemetry;
global using StevesBot.Worker.Threading; global using StevesBot.Worker.Threading;
global using StevesBot.Worker.WebSockets; global using StevesBot.Worker.WebSockets;
@@ -7,12 +7,12 @@ public class HostExtensionsTests
{ {
var builder = WebApplication.CreateBuilder(); var builder = WebApplication.CreateBuilder();
builder.AddTelemetry(static () => new StevesBotWebhookInstrumentation()); builder.AddTelemetry(static () => new TestInstrumentation());
var app = builder.Build(); var app = builder.Build();
app.Services app.Services
.GetService<StevesBotWebhookInstrumentation>() .GetService<TestInstrumentation>()
.Should() .Should()
.BeNull(); .BeNull();
@@ -42,7 +42,7 @@ public class HostExtensionsTests
builder.Configuration.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(json))); builder.Configuration.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(json)));
builder.AddTelemetry(static () => new StevesBotWebhookInstrumentation()); builder.AddTelemetry(static () => new TestInstrumentation());
var app = builder.Build(); var app = builder.Build();
@@ -62,4 +62,16 @@ public class HostExtensionsTests
.Should() .Should()
.NotBeNull(); .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,4 +1,4 @@
namespace StevesBot.Library.Tests.Unit; namespace StevesBot.Webhook.Tests.Unit;
public sealed class StevesBotWebhookInstrumentationTests : IDisposable public sealed class StevesBotWebhookInstrumentationTests : IDisposable
{ {
@@ -1,4 +1,5 @@
global using System.Collections.Concurrent; global using System.Collections.Concurrent;
global using System.Diagnostics;
global using System.Net; global using System.Net;
global using System.Text; global using System.Text;
@@ -13,6 +14,7 @@ global using RichardSzalay.MockHttp;
global using StevesBot.Library.Discord.Rest; global using StevesBot.Library.Discord.Rest;
global using StevesBot.Library.Discord.Rest.Requests; global using StevesBot.Library.Discord.Rest.Requests;
global using StevesBot.Webhook.Telemetry;
global using StevesBot.Webhook.YouTube; global using StevesBot.Webhook.YouTube;
global using StevesBot.Webhook.YouTube.Data; global using StevesBot.Webhook.YouTube.Data;
global using StevesBot.Webhook.YouTube.Handlers; global using StevesBot.Webhook.YouTube.Handlers;
@@ -1,4 +1,4 @@
namespace StevesBot.Library.Tests.Unit; namespace StevesBot.Worker.Tests.Unit;
public sealed class StevesBotWorkerInstrumentationTests : IDisposable public sealed class StevesBotWorkerInstrumentationTests : IDisposable
{ {
+2 -4
View File
@@ -1,4 +1,4 @@
global using System.Net; global using System.Diagnostics;
global using System.Net.WebSockets; global using System.Net.WebSockets;
global using System.Text; global using System.Text;
global using System.Text.Json; global using System.Text.Json;
@@ -14,9 +14,6 @@ global using Microsoft.Extensions.Logging;
global using Moq; global using Moq;
global using RichardSzalay.MockHttp;
global using StevesBot.Library.Discord;
global using StevesBot.Library.Discord.Common; global using StevesBot.Library.Discord.Common;
global using StevesBot.Library.Discord.Rest; global using StevesBot.Library.Discord.Rest;
global using StevesBot.Library.Discord.Rest.Requests; global using StevesBot.Library.Discord.Rest.Requests;
@@ -24,6 +21,7 @@ global using StevesBot.Worker.Discord;
global using StevesBot.Worker.Discord.Gateway; global using StevesBot.Worker.Discord.Gateway;
global using StevesBot.Worker.Discord.Gateway.Events; global using StevesBot.Worker.Discord.Gateway.Events;
global using StevesBot.Worker.Discord.Gateway.Events.Data; global using StevesBot.Worker.Discord.Gateway.Events.Data;
global using StevesBot.Worker.Telemetry;
global using StevesBot.Worker.Tests.Integration.Infrastructure; global using StevesBot.Worker.Tests.Integration.Infrastructure;
global using StevesBot.Worker.Threading; global using StevesBot.Worker.Threading;
global using StevesBot.Worker.WebSockets; global using StevesBot.Worker.WebSockets;