|
|
@ -10,6 +10,7 @@ using Google.Cloud.Diagnostics.Common; |
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using OpenTelemetry.Trace; |
|
|
using OpenTelemetry.Trace; |
|
|
|
|
|
using Squidex.Infrastructure; |
|
|
using Squidex.Infrastructure.Plugins; |
|
|
using Squidex.Infrastructure.Plugins; |
|
|
using Squidex.Log; |
|
|
using Squidex.Log; |
|
|
|
|
|
|
|
|
@ -17,29 +18,45 @@ namespace Squidex.Extensions.APM.Stackdriver |
|
|
{ |
|
|
{ |
|
|
public sealed class StackdriverPlugin : IPlugin |
|
|
public sealed class StackdriverPlugin : IPlugin |
|
|
{ |
|
|
{ |
|
|
public void ConfigureServices(IServiceCollection services, IConfiguration config) |
|
|
private class Configurator : ITelemetryConfigurator |
|
|
{ |
|
|
{ |
|
|
var projectId = config.GetValue<string>("logging:stackdriver:projectId"); |
|
|
private readonly string projectId; |
|
|
var projectName = config.GetValue<string>("logging:stackdriver:projectName") ?? "Squidex"; |
|
|
|
|
|
|
|
|
public Configurator(string projectId) |
|
|
|
|
|
{ |
|
|
|
|
|
this.projectId = projectId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Configure(TracerProviderBuilder builder) |
|
|
|
|
|
{ |
|
|
|
|
|
builder.UseStackdriverExporter(projectId); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services, IConfiguration config) |
|
|
|
|
|
{ |
|
|
var isEnabled = config.GetValue<bool>("logging:stackdriver:enabled"); |
|
|
var isEnabled = config.GetValue<bool>("logging:stackdriver:enabled"); |
|
|
|
|
|
|
|
|
if (isEnabled && !string.IsNullOrWhiteSpace(projectId)) |
|
|
if (isEnabled) |
|
|
{ |
|
|
{ |
|
|
services.AddOpenTelemetryTracing(builder => |
|
|
var projectId = config.GetValue<string>("logging:stackdriver:projectId"); |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(projectId)) |
|
|
{ |
|
|
{ |
|
|
builder.UseStackdriverExporter(projectId); |
|
|
services.AddSingleton<ITelemetryConfigurator>( |
|
|
}); |
|
|
new Configurator(projectId)); |
|
|
|
|
|
|
|
|
services.AddSingleton<ILogAppender, |
|
|
services.AddSingleton<ILogAppender, |
|
|
StackdriverSeverityLogAppender>(); |
|
|
StackdriverSeverityLogAppender>(); |
|
|
|
|
|
|
|
|
services.AddSingleton<ILogAppender, |
|
|
services.AddSingleton<ILogAppender, |
|
|
StackdriverExceptionHandler>(); |
|
|
StackdriverExceptionHandler>(); |
|
|
|
|
|
|
|
|
var version = Assembly.GetEntryAssembly().GetName().Version?.ToString(); |
|
|
var serviceName = config.GetValue<string>("logging:name") ?? "Squidex"; |
|
|
|
|
|
var serviceVersion = Assembly.GetEntryAssembly().GetName().Version?.ToString(); |
|
|
|
|
|
|
|
|
services.AddSingleton(c => ContextExceptionLogger.Create(projectId, projectName, version, null)); |
|
|
services.AddSingleton(c => ContextExceptionLogger.Create(projectId, serviceVersion, serviceVersion, null)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|