seq-tokens (#1308)
This commit is contained in:
@@ -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<Repository>();
|
||||
serviceCollection.AddTransient<ImportJobFileDownloader>();
|
||||
serviceCollection.AddHostedService<JobProcessorInstance>();
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Speckle.Sdk.Logging.ISdkActivityFactory, ConnectorActivityFactory>();
|
||||
return new LoggingDisposable(logging, tracing, metrics);
|
||||
|
||||
@@ -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 ?? [])
|
||||
|
||||
@@ -38,7 +38,7 @@ internal static class MetricsBuilder
|
||||
|
||||
if (metrics.Endpoint is not null)
|
||||
{
|
||||
options.Endpoint = new Uri(metrics.Endpoint);
|
||||
options.Endpoint = metrics.Endpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ internal static class TracingBuilder
|
||||
|
||||
if (tracing.Endpoint is not null)
|
||||
{
|
||||
options.Endpoint = new Uri(tracing.Endpoint);
|
||||
options.Endpoint = tracing.Endpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string, string>? Headers = null
|
||||
);
|
||||
public record SpeckleOtelLogging(Uri? Endpoint = null, bool Enabled = true, Dictionary<string, string>? Headers = null);
|
||||
|
||||
public record SpeckleTracing(bool Console = false, IEnumerable<SpeckleOtelTracing>? Otel = null)
|
||||
{
|
||||
@@ -40,11 +36,7 @@ public record SpeckleTracing(bool Console = false, IEnumerable<SpeckleOtelTracin
|
||||
: this(console, otel is null ? null : [otel]) { }
|
||||
}
|
||||
|
||||
public record SpeckleOtelTracing(
|
||||
string? Endpoint = null,
|
||||
bool Enabled = true,
|
||||
Dictionary<string, string>? Headers = null
|
||||
);
|
||||
public record SpeckleOtelTracing(Uri? Endpoint = null, bool Enabled = true, Dictionary<string, string>? Headers = null);
|
||||
|
||||
public record SpeckleMetrics(bool Console = false, IEnumerable<SpeckleOtelMetrics>? Otel = null)
|
||||
{
|
||||
@@ -52,8 +44,4 @@ public record SpeckleMetrics(bool Console = false, IEnumerable<SpeckleOtelMetric
|
||||
: this(console, otel is null ? null : [otel]) { }
|
||||
}
|
||||
|
||||
public record SpeckleOtelMetrics(
|
||||
string? Endpoint = null,
|
||||
bool Enabled = true,
|
||||
Dictionary<string, string>? Headers = null
|
||||
);
|
||||
public record SpeckleOtelMetrics(Uri? Endpoint = null, bool Enabled = true, Dictionary<string, string>? Headers = null);
|
||||
|
||||
Reference in New Issue
Block a user