2025-01-03 16:21:03 +00:00
|
|
|
|
using Autofac;
|
2025-02-05 18:38:29 +01:00
|
|
|
|
using Microsoft.ApplicationInsights.Channel;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
2025-01-03 16:21:03 +00:00
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
namespace PlanTempus.Core.ModuleRegistry
|
2025-01-03 16:21:03 +00:00
|
|
|
|
{
|
2025-02-20 00:23:13 +01:00
|
|
|
|
public class TelemetryModule : Module
|
|
|
|
|
|
{
|
2025-02-21 23:34:06 +01:00
|
|
|
|
public required TelemetryConfig TelemetryConfig { get; set; }
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
var configuration = TelemetryConfiguration.CreateDefault();
|
|
|
|
|
|
configuration.ConnectionString = TelemetryConfig.ConnectionString;
|
|
|
|
|
|
configuration.TelemetryChannel.DeveloperMode = true;
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-02-22 20:14:56 +01:00
|
|
|
|
var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration);
|
2025-03-10 15:56:22 +01:00
|
|
|
|
client.Context.GlobalProperties["Application"] = GetType().Namespace?.Split('.')[0];
|
2025-02-22 20:14:56 +01:00
|
|
|
|
client.Context.GlobalProperties["MachineName"] = Environment.MachineName;
|
|
|
|
|
|
client.Context.GlobalProperties["Version"] = Environment.Version.ToString();
|
|
|
|
|
|
client.Context.GlobalProperties["ProcessorCount"] = Environment.ProcessorCount.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
builder.Register(c => client).InstancePerLifetimeScope();
|
|
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
if (TelemetryConfig.UseSeqLoggingTelemetryChannel)
|
2025-02-21 23:34:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
var messageChannel = new Telemetry.MessageChannel();
|
|
|
|
|
|
|
|
|
|
|
|
builder.RegisterInstance(messageChannel)
|
|
|
|
|
|
.As<Telemetry.IMessageChannel<ITelemetry>>()
|
|
|
|
|
|
.SingleInstance();
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-02-22 20:14:56 +01:00
|
|
|
|
configuration.TelemetryChannel = new Telemetry.SeqTelemetryChannel(messageChannel, client);
|
2025-02-21 23:34:06 +01:00
|
|
|
|
}
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-03-10 15:56:22 +01:00
|
|
|
|
var telemetryProcessorChain =
|
|
|
|
|
|
new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(
|
|
|
|
|
|
configuration);
|
2025-02-21 23:34:06 +01:00
|
|
|
|
telemetryProcessorChain.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next));
|
|
|
|
|
|
telemetryProcessorChain.Build();
|
2025-02-20 00:23:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-05 18:38:29 +01:00
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
public class TelemetryConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public string ConnectionString { get; set; }
|
|
|
|
|
|
public bool UseSeqLoggingTelemetryChannel { get; set; }
|
|
|
|
|
|
}
|
2025-03-10 15:56:22 +01:00
|
|
|
|
}
|