From 8e0ec2d3d5fcb60869852dc3743dca77c329ecf0 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:31:09 -0500 Subject: [PATCH] refactor: moving telemetry wip --- src/compose.yml | 40 +++++++++++++++++++ .../StevesBotWebhookInstrumentation.cs | 4 +- .../StevesBotWorkerInstrumentation.cs | 4 +- src/src/StevesBot.Worker/Usings.cs | 8 ++-- .../Unit/HostExtensionsTests.cs | 18 +++++++-- .../StevesBotWebhookInstrumentationTests.cs | 2 +- src/tests/StevesBot.Webhook.Tests/Usings.cs | 2 + .../StevesBotWorkerInstrumentationTests.cs | 2 +- src/tests/StevesBot.Worker.Tests/Usings.cs | 6 +-- 9 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 src/compose.yml rename src/src/{StevesBot.Library => StevesBot.Webhook}/Telemetry/StevesBotWebhookInstrumentation.cs (78%) rename src/src/{StevesBot.Library => StevesBot.Worker}/Telemetry/StevesBotWorkerInstrumentation.cs (79%) rename src/tests/{StevesBot.Library.Tests => StevesBot.Webhook.Tests}/Unit/StevesBotWebhookInstrumentationTests.cs (95%) rename src/tests/{StevesBot.Library.Tests => StevesBot.Worker.Tests}/Unit/StevesBotWorkerInstrumentationTests.cs (95%) diff --git a/src/compose.yml b/src/compose.yml new file mode 100644 index 0000000..dfa8537 --- /dev/null +++ b/src/compose.yml @@ -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 diff --git a/src/src/StevesBot.Library/Telemetry/StevesBotWebhookInstrumentation.cs b/src/src/StevesBot.Webhook/Telemetry/StevesBotWebhookInstrumentation.cs similarity index 78% rename from src/src/StevesBot.Library/Telemetry/StevesBotWebhookInstrumentation.cs rename to src/src/StevesBot.Webhook/Telemetry/StevesBotWebhookInstrumentation.cs index e56aefa..eb7a13a 100644 --- a/src/src/StevesBot.Library/Telemetry/StevesBotWebhookInstrumentation.cs +++ b/src/src/StevesBot.Webhook/Telemetry/StevesBotWebhookInstrumentation.cs @@ -1,8 +1,8 @@ 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 SourceVersionValue = "0.0.0"; diff --git a/src/src/StevesBot.Library/Telemetry/StevesBotWorkerInstrumentation.cs b/src/src/StevesBot.Worker/Telemetry/StevesBotWorkerInstrumentation.cs similarity index 79% rename from src/src/StevesBot.Library/Telemetry/StevesBotWorkerInstrumentation.cs rename to src/src/StevesBot.Worker/Telemetry/StevesBotWorkerInstrumentation.cs index de63a27..5bc4663 100644 --- a/src/src/StevesBot.Library/Telemetry/StevesBotWorkerInstrumentation.cs +++ b/src/src/StevesBot.Worker/Telemetry/StevesBotWorkerInstrumentation.cs @@ -1,8 +1,8 @@ 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 SourceVersionValue = "0.0.0"; diff --git a/src/src/StevesBot.Worker/Usings.cs b/src/src/StevesBot.Worker/Usings.cs index 11b7725..7dce256 100644 --- a/src/src/StevesBot.Worker/Usings.cs +++ b/src/src/StevesBot.Worker/Usings.cs @@ -7,16 +7,16 @@ global using System.Text.Json.Serialization; global using Microsoft.Extensions.Options; 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.Worker; global using StevesBot.Worker.Discord; global using StevesBot.Worker.Discord.Gateway; global using StevesBot.Worker.Discord.Gateway.Events; 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.Telemetry; global using StevesBot.Worker.Threading; global using StevesBot.Worker.WebSockets; \ No newline at end of file diff --git a/src/tests/StevesBot.Library.Tests/Unit/HostExtensionsTests.cs b/src/tests/StevesBot.Library.Tests/Unit/HostExtensionsTests.cs index 48a9200..f2eb30d 100644 --- a/src/tests/StevesBot.Library.Tests/Unit/HostExtensionsTests.cs +++ b/src/tests/StevesBot.Library.Tests/Unit/HostExtensionsTests.cs @@ -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() + .GetService() .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(); + } + } } \ No newline at end of file diff --git a/src/tests/StevesBot.Library.Tests/Unit/StevesBotWebhookInstrumentationTests.cs b/src/tests/StevesBot.Webhook.Tests/Unit/StevesBotWebhookInstrumentationTests.cs similarity index 95% rename from src/tests/StevesBot.Library.Tests/Unit/StevesBotWebhookInstrumentationTests.cs rename to src/tests/StevesBot.Webhook.Tests/Unit/StevesBotWebhookInstrumentationTests.cs index 8eea5f8..723836b 100644 --- a/src/tests/StevesBot.Library.Tests/Unit/StevesBotWebhookInstrumentationTests.cs +++ b/src/tests/StevesBot.Webhook.Tests/Unit/StevesBotWebhookInstrumentationTests.cs @@ -1,4 +1,4 @@ -namespace StevesBot.Library.Tests.Unit; +namespace StevesBot.Webhook.Tests.Unit; public sealed class StevesBotWebhookInstrumentationTests : IDisposable { diff --git a/src/tests/StevesBot.Webhook.Tests/Usings.cs b/src/tests/StevesBot.Webhook.Tests/Usings.cs index ed26c30..9cba30d 100644 --- a/src/tests/StevesBot.Webhook.Tests/Usings.cs +++ b/src/tests/StevesBot.Webhook.Tests/Usings.cs @@ -1,4 +1,5 @@ global using System.Collections.Concurrent; +global using System.Diagnostics; global using System.Net; global using System.Text; @@ -13,6 +14,7 @@ global using RichardSzalay.MockHttp; global using StevesBot.Library.Discord.Rest; global using StevesBot.Library.Discord.Rest.Requests; +global using StevesBot.Webhook.Telemetry; global using StevesBot.Webhook.YouTube; global using StevesBot.Webhook.YouTube.Data; global using StevesBot.Webhook.YouTube.Handlers; diff --git a/src/tests/StevesBot.Library.Tests/Unit/StevesBotWorkerInstrumentationTests.cs b/src/tests/StevesBot.Worker.Tests/Unit/StevesBotWorkerInstrumentationTests.cs similarity index 95% rename from src/tests/StevesBot.Library.Tests/Unit/StevesBotWorkerInstrumentationTests.cs rename to src/tests/StevesBot.Worker.Tests/Unit/StevesBotWorkerInstrumentationTests.cs index 3d94aa6..6372b24 100644 --- a/src/tests/StevesBot.Library.Tests/Unit/StevesBotWorkerInstrumentationTests.cs +++ b/src/tests/StevesBot.Worker.Tests/Unit/StevesBotWorkerInstrumentationTests.cs @@ -1,4 +1,4 @@ -namespace StevesBot.Library.Tests.Unit; +namespace StevesBot.Worker.Tests.Unit; public sealed class StevesBotWorkerInstrumentationTests : IDisposable { diff --git a/src/tests/StevesBot.Worker.Tests/Usings.cs b/src/tests/StevesBot.Worker.Tests/Usings.cs index eeafbcc..fff654f 100644 --- a/src/tests/StevesBot.Worker.Tests/Usings.cs +++ b/src/tests/StevesBot.Worker.Tests/Usings.cs @@ -1,4 +1,4 @@ -global using System.Net; +global using System.Diagnostics; global using System.Net.WebSockets; global using System.Text; global using System.Text.Json; @@ -14,9 +14,6 @@ global using Microsoft.Extensions.Logging; global using Moq; -global using RichardSzalay.MockHttp; - -global using StevesBot.Library.Discord; global using StevesBot.Library.Discord.Common; global using StevesBot.Library.Discord.Rest; 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.Events; global using StevesBot.Worker.Discord.Gateway.Events.Data; +global using StevesBot.Worker.Telemetry; global using StevesBot.Worker.Tests.Integration.Infrastructure; global using StevesBot.Worker.Threading; global using StevesBot.Worker.WebSockets; \ No newline at end of file