From 3768157efe3e8da9196b5c366f8d71c7aa0527cf Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Wed, 11 Mar 2026 12:52:47 +0000 Subject: [PATCH] seq-tokens (#1308) --- .../ServiceRegistration.cs | 55 +++++++++++-- Sdk/Speckle.Connectors.Common/Connector.cs | 79 +++++++++++-------- .../Internal/LogBuilder.cs | 2 +- .../Internal/MetricsBuilder.cs | 2 +- .../Internal/TracingBuilder.cs | 2 +- .../SpeckleObservability.cs | 18 +---- 6 files changed, 100 insertions(+), 58 deletions(-) diff --git a/Importers/Rhino/Speckle.Importers.JobProcessor/ServiceRegistration.cs b/Importers/Rhino/Speckle.Importers.JobProcessor/ServiceRegistration.cs index efd91011c..c4e4cadd0 100644 --- a/Importers/Rhino/Speckle.Importers.JobProcessor/ServiceRegistration.cs +++ b/Importers/Rhino/Speckle.Importers.JobProcessor/ServiceRegistration.cs @@ -1,7 +1,11 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; using Speckle.Connectors.Common; +using Speckle.Connectors.Common.Common; +using Speckle.Connectors.Logging; using Speckle.Importers.JobProcessor.Blobs; using Speckle.Importers.JobProcessor.JobQueue; +using Speckle.Objects.Geometry; using Speckle.Sdk; namespace Speckle.Importers.JobProcessor; @@ -9,20 +13,61 @@ namespace Speckle.Importers.JobProcessor; internal static class ServiceRegistration { private static readonly Application s_application = new(".NET File Import Job Processor", "jobprocessor"); + private const HostAppVersion HOST_APP_VERSION = HostAppVersion.v3; public static IServiceCollection AddJobProcessor(this IServiceCollection serviceCollection) { + var assemblyVersion = Assembly.GetExecutingAssembly().GetVersion(); + + serviceCollection.AddSpeckleSdk( + s_application, + HostApplications.GetVersion(HOST_APP_VERSION), + assemblyVersion, + typeof(Point).Assembly + ); + serviceCollection.AddLoggingConfig(); + serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddHostedService(); return serviceCollection; } - private static IServiceCollection AddLoggingConfig(this IServiceCollection serviceCollection) + private static void AddLoggingConfig(this IServiceCollection serviceCollection) { - serviceCollection.Initialize(s_application, HostAppVersion.v3); - - return serviceCollection; + serviceCollection.AddSeqLogging( + s_application, + HOST_APP_VERSION, +#if DEBUG || LOCAL + new SpeckleLogging(Console: true, File: new(), MinimumLevel: SpeckleLogLevel.Debug), + new SpeckleTracing(Console: false), + new SpeckleMetrics(Console: false) +#else + new SpeckleLogging( + Console: true, + File: new(), + Otel: + [ + new( + Endpoint: new Uri("https://seq.speckle.systems/ingest/otlp/v1/logs"), + Headers: new() { { "X-Seq-ApiKey", "zG4cU1MbOhMD699iGlAq" } } + ) + ], + MinimumLevel: SpeckleLogLevel.Information + ), + new SpeckleTracing( + Console: false, + Otel: + [ + new( + Endpoint: new Uri("https://seq.speckle.systems/ingest/otlp/v1/traces"), + Headers: new() { { "X-Seq-ApiKey", "zG4cU1MbOhMD699iGlAq" } } + ) + ] + ), + null +#endif + ); } } diff --git a/Sdk/Speckle.Connectors.Common/Connector.cs b/Sdk/Speckle.Connectors.Common/Connector.cs index 126952b7c..9d5b878e9 100644 --- a/Sdk/Speckle.Connectors.Common/Connector.cs +++ b/Sdk/Speckle.Connectors.Common/Connector.cs @@ -37,54 +37,63 @@ public static class Connector typeof(Point).Assembly ); + return serviceCollection.AddSeqLogging( + application, + version, #if DEBUG || LOCAL - var minimumLevel = SpeckleLogLevel.Debug; + new SpeckleLogging(Console: true, File: new(), MinimumLevel: SpeckleLogLevel.Debug), + new SpeckleTracing(Console: false), + new SpeckleMetrics(Console: false) #else - var minimumLevel = SpeckleLogLevel.Information; + new SpeckleLogging( + Console: true, + File: new(), + Otel: + [ + new( + Endpoint: new Uri("https://seq.speckle.systems/ingest/otlp/v1/logs"), + Headers: new() { { "X-Seq-ApiKey", "Y0Ya2CFVt1tCSgrbY07c" } } + ) + ], + MinimumLevel: SpeckleLogLevel.Information + ), + new SpeckleTracing( + Console: false, + Otel: + [ + new( + Endpoint: new Uri("https://seq.speckle.systems/ingest/otlp/v1/traces"), + Headers: new() { { "X-Seq-ApiKey", "Y0Ya2CFVt1tCSgrbY07c" } } + ) + ] + ), + null #endif + ); + } + + public static IDisposable AddSeqLogging( + this IServiceCollection serviceCollection, + Application application, + HostAppVersion version, + SpeckleLogging loggingConfig, + SpeckleTracing? tracingConfig, + SpeckleMetrics? metricsConfig + ) + { + var assemblyVersion = Assembly.GetExecutingAssembly().GetVersion(); var (logging, tracing, metrics) = Observability.Initialize( application.Name + " " + HostApplications.GetVersion(version), application.Slug, assemblyVersion, -#if DEBUG || LOCAL - new( - new SpeckleLogging(Console: true, File: new(), MinimumLevel: minimumLevel), - new SpeckleTracing(Console: false), - new SpeckleMetrics(Console: false) - ) -#else - new( - new SpeckleLogging( - Console: true, - File: new(), - Otel: - [ - new( - Endpoint: "https://seq-dev.speckle.systems/ingest/otlp/v1/logs", - Headers: new() { { "X-Seq-ApiKey", "y5YnBp12ZE1Czh4tzZWn" } } - ) - ], - MinimumLevel: minimumLevel - ), - new SpeckleTracing( - Console: false, - Otel: - [ - new( - Endpoint: "https://seq-dev.speckle.systems/ingest/otlp/v1/traces", - Headers: new() { { "X-Seq-ApiKey", "y5YnBp12ZE1Czh4tzZWn" } } - ) - ] - ) - ) -#endif + new(loggingConfig, tracingConfig, metricsConfig) ); //do this after the AddSpeckleSdk so that the logging system gets values from here. serviceCollection.AddLogging(x => { x.ClearProviders(); x.AddProvider(new SpeckleLogProvider(logging)); - x.SetMinimumLevel(GetMicrosoftLevel(minimumLevel)); + x.SetMinimumLevel(GetMicrosoftLevel(loggingConfig.MinimumLevel)); }); serviceCollection.AddSingleton(); return new LoggingDisposable(logging, tracing, metrics); diff --git a/Sdk/Speckle.Connectors.Logging/Internal/LogBuilder.cs b/Sdk/Speckle.Connectors.Logging/Internal/LogBuilder.cs index a2976853d..b2e8b4b22 100644 --- a/Sdk/Speckle.Connectors.Logging/Internal/LogBuilder.cs +++ b/Sdk/Speckle.Connectors.Logging/Internal/LogBuilder.cs @@ -84,7 +84,7 @@ internal static class LogBuilder y.Protocol = OtlpExportProtocol.HttpProtobuf; y.Endpoint = speckleOtelLogging.Endpoint is null ? throw new InvalidOperationException("Need a logging endpoint") - : new Uri(speckleOtelLogging.Endpoint); + : speckleOtelLogging.Endpoint; var sb = new StringBuilder(); bool appendSemicolon = false; foreach (var kvp in speckleOtelLogging.Headers ?? []) diff --git a/Sdk/Speckle.Connectors.Logging/Internal/MetricsBuilder.cs b/Sdk/Speckle.Connectors.Logging/Internal/MetricsBuilder.cs index d8f39e92b..e5a84e0c5 100644 --- a/Sdk/Speckle.Connectors.Logging/Internal/MetricsBuilder.cs +++ b/Sdk/Speckle.Connectors.Logging/Internal/MetricsBuilder.cs @@ -38,7 +38,7 @@ internal static class MetricsBuilder if (metrics.Endpoint is not null) { - options.Endpoint = new Uri(metrics.Endpoint); + options.Endpoint = metrics.Endpoint; } } } diff --git a/Sdk/Speckle.Connectors.Logging/Internal/TracingBuilder.cs b/Sdk/Speckle.Connectors.Logging/Internal/TracingBuilder.cs index 4600d1ed3..a3178a613 100644 --- a/Sdk/Speckle.Connectors.Logging/Internal/TracingBuilder.cs +++ b/Sdk/Speckle.Connectors.Logging/Internal/TracingBuilder.cs @@ -44,7 +44,7 @@ internal static class TracingBuilder if (tracing.Endpoint is not null) { - options.Endpoint = new Uri(tracing.Endpoint); + options.Endpoint = tracing.Endpoint; } } } diff --git a/Sdk/Speckle.Connectors.Logging/SpeckleObservability.cs b/Sdk/Speckle.Connectors.Logging/SpeckleObservability.cs index ba14a59ec..a500e7c34 100644 --- a/Sdk/Speckle.Connectors.Logging/SpeckleObservability.cs +++ b/Sdk/Speckle.Connectors.Logging/SpeckleObservability.cs @@ -28,11 +28,7 @@ public record SpeckleLogging( public record SpeckleFileLogging(string? Path = null, bool Enabled = true); -public record SpeckleOtelLogging( - string? Endpoint = null, - bool Enabled = true, - Dictionary? Headers = null -); +public record SpeckleOtelLogging(Uri? Endpoint = null, bool Enabled = true, Dictionary? Headers = null); public record SpeckleTracing(bool Console = false, IEnumerable? Otel = null) { @@ -40,11 +36,7 @@ public record SpeckleTracing(bool Console = false, IEnumerable? Headers = null -); +public record SpeckleOtelTracing(Uri? Endpoint = null, bool Enabled = true, Dictionary? Headers = null); public record SpeckleMetrics(bool Console = false, IEnumerable? Otel = null) { @@ -52,8 +44,4 @@ public record SpeckleMetrics(bool Console = false, IEnumerable? Headers = null -); +public record SpeckleOtelMetrics(Uri? Endpoint = null, bool Enabled = true, Dictionary? Headers = null);