Skip to content

Commit

Permalink
add meter and activitysource
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsonax committed May 25, 2024
1 parent 21e1d85 commit 7649542
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions CleanAspCore/Telemetry/AppConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ internal static void AddOpenTelemetryServices(this WebApplicationBuilder builder
{
options.IncludeScopes = true;
options.AddProcessor(new EnrichLogsProcessor());
options
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(builder.Environment.ApplicationName))
.AddOtlpExporter();
options.AddOtlpExporter();
});
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(builder.Environment.ApplicationName))
.ConfigureResource(resource => resource.AddService(
builder.Environment.ApplicationName,
serviceInstanceId: builder.Environment.IsDevelopment() ? builder.Environment.ApplicationName : null))
.WithTracing(tracing => tracing
.AddSource(Instrumentation.ActivitySource.Name)
.AddProcessor(new EnrichSpanProcessor())
.AddAspNetCoreInstrumentation()
.AddEntityFrameworkCoreInstrumentation()
.AddOtlpExporter())
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddMeter(Instrumentation.Meter.Name)
.AddOtlpExporter());
}
}
10 changes: 10 additions & 0 deletions CleanAspCore/Telemetry/Instrumentation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Diagnostics;
using System.Diagnostics.Metrics;

namespace CleanAspCore.Telemetry;

internal static class Instrumentation
{
internal static readonly Meter Meter = new("CleanAspCore", "1.0.0");
internal static readonly ActivitySource ActivitySource = new("CleanAspCore", "1.0.0");
}

0 comments on commit 7649542

Please sign in to comment.