Refactor OpenTelemetry exporter configuration

This commit is contained in:
Simon Larsen
2023-12-30 12:29:35 +00:00
parent 3fe3bc06fa
commit 03a503b080
8 changed files with 8 additions and 33 deletions

View File

@@ -7,8 +7,6 @@ using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
const string endpoint = "http://localhost:4317";
Console.WriteLine($"Env var: {Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS")?.ToString()}");
@@ -30,15 +28,6 @@ builder.Logging.AddOpenTelemetry(logging =>
.AddConsoleExporter()
.AddOtlpExporter(opt =>
{
// If endpoint was not specified, the proper one will be selected according to the protocol.
if (!string.IsNullOrEmpty(endpoint))
{
opt.Endpoint = new Uri(endpoint);
// Set headers in OTLP exporter
// opt.Headers = "oneuptime-service-token=0a00ebc0-7f39-11ee-ac8c-3fb43926b224";
}
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
});
});
@@ -52,16 +41,6 @@ builder.Services.AddOpenTelemetry()
.AddConsoleExporter()
.AddOtlpExporter(opt =>
{
// If endpoint was not specified, the proper one will be selected according to the protocol.
if (!string.IsNullOrEmpty(endpoint))
{
opt.Endpoint = new Uri(endpoint);
// Set headers in OTLP exporter
// opt.Headers = "oneuptime-service-token=0a00ebc0-7f39-11ee-ac8c-3fb43926b224";
}
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
}));
@@ -82,14 +61,6 @@ builder.Services.AddOpenTelemetry()
})
.AddOtlpExporter(opt =>
{
// If endpoint was not specified, the proper one will be selected according to the protocol.
if (!string.IsNullOrEmpty(endpoint))
{
opt.Endpoint = new Uri(endpoint);
// Set headers in OTLP exporter
// opt.Headers = "oneuptime-service-token=0a00ebc0-7f39-11ee-ac8c-3fb43926b224";
}
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
}));

View File

@@ -5,5 +5,5 @@
Please use
```bash
export OTEL_EXPORTER_OTLP_HEADERS=x-oneuptime-service-token=9c8806e0-a4aa-11ee-be95-010d5967b068 && export OTEL_EXPORTER_OTLP_ENDPOINT=https://localhost/opentelemetry-collector dotnet run --urls=http://localhost:7856/
export OTEL_EXPORTER_OTLP_HEADERS="x-oneuptime-service-token=9c8806e0-a4aa-11ee-be95-010d5967b068" && export OTEL_EXPORTER_OTLP_ENDPOINT="https://localhost/opentelemetry-collector" && dotnet run --urls=http://localhost:7856/
```

View File

@@ -36,3 +36,7 @@
2.0
2.0
2.0
2.0
2.0
2.0
2.0

View File

@@ -45,7 +45,7 @@ server {
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;
listen 80 default_server;
listen 80;
server_name oneuptime-opentelemetry-collector ${OTEL_COLLECTOR_HOST};
@@ -81,7 +81,7 @@ server {
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;
listen 80 default_server;
listen 80;
server_name _; # All domains.
@@ -169,7 +169,7 @@ server {
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;
listen 443 default_server ssl; # Port HTTPS
listen 443 ssl; # Port HTTPS
ssl_certificate /etc/nginx/certs/StatusPageCerts/$ssl_server_name.crt;