-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
52 lines (47 loc) · 2.06 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
52 lines (47 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
namespace VirtoCommerce.OpenTelemetry.Web;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddOpenTelemetryModule(this IServiceCollection services, IConfiguration configuration)
{
// Note: OpenTelemetry logging is integrated via Serilog sink (see OpenTelemetryLoggerConfigurationService)
// This avoids duplicate logging providers and follows VirtoCommerce Platform patterns
var otelBuilder = services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddProcessInstrumentation()
.AddEventCountersInstrumentation(options =>
{
options.AddEventSources("Microsoft.AspNetCore.Hosting", "Microsoft-AspNetCore-Server-Kestrel");
})
.AddMeter("Microsoft.EntityFrameworkCore", "Elastic.Transport");
})
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddHangfireInstrumentation()
.AddEntityFrameworkCoreInstrumentation()
.AddElasticsearchClientInstrumentation(options =>
{
options.SuppressDownstreamInstrumentation = true;
options.ParseAndFormatRequest = true;
})
.AddSource("Elastic.Transport")
.AddRedisInstrumentation();
});
// Add OTLP exporter if endpoint is configured
if (!string.IsNullOrWhiteSpace(configuration["OpenTelemetry:Endpoint"]))
{
otelBuilder.UseOtlpExporter();
}
return services;
}
}