Skip to content

Commit

Permalink
Added config flag to enable OTEL (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
csharpfritz committed Mar 21, 2024
1 parent cc7b50c commit 9a7c858
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/TagzApp.Blazor/OpenTelemetryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public static class OpenTelemetryExtensions

public static IServiceCollection AddOpenTelemetryObservability(this IServiceCollection services, IConfiguration configuration)
{

if (!bool.Parse(configuration["EnableTelemetry"] ?? "true")) return services;

services.AddOpenTelemetry()
.ConfigureResource(_ConfigureResource)
.WithTracing(builder =>
Expand Down Expand Up @@ -57,6 +60,9 @@ public static IServiceCollection AddOpenTelemetryObservability(this IServiceColl

public static void AddOpenTelemetryLogging(this ILoggingBuilder builder, IConfiguration configuration)
{

if (!bool.Parse(configuration["EnableTelemetry"] ?? "true")) return;

var logExporter = configuration.GetValue("UseLogExporter", defaultValue: "console")!.ToLowerInvariant();

builder.ClearProviders();
Expand Down
7 changes: 4 additions & 3 deletions src/TagzApp.Blazor/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"UseTracingExporter": "otlp",
"UseMetricsExporter": "otlp",
"UseLogExporter": "otlp",
"EnableTelemetry": false,
"UseTracingExporter": "console",
"UseMetricsExporter": "console",
"UseLogExporter": "console",
"HistogramAggregation": "explicit",
"AspNetCoreInstrumentation": {
"RecordException": "true"
Expand Down

0 comments on commit 9a7c858

Please sign in to comment.