-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: or-2583 add observability for kbo sync lambda
- Loading branch information
Showing
5 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/AssociationRegistry.KboMutations.SyncLambda/OpenTelemetrySetup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
namespace AssociationRegistry.KboMutations.SyncLambda; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Exporter; | ||
using OpenTelemetry.Logs; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Trace; | ||
|
||
public class OpenTelemetrySetup | ||
{ | ||
private const string OtelAuthHeader = "OTEL_AUTH_HEADER"; | ||
|
||
public static MeterProvider SetupMeter(string otlpMetricsUri) | ||
{ | ||
return Sdk.CreateMeterProviderBuilder() | ||
.AddMeter("KboMutations.SyncLambda.Metrics") | ||
.AddRuntimeInstrumentation() | ||
.AddHttpClientInstrumentation() | ||
.AddConsoleExporter() | ||
.AddOtlpExporter(options => | ||
{ | ||
options.Endpoint = | ||
new Uri(otlpMetricsUri); | ||
|
||
AddAuth(options); | ||
}) | ||
.Build(); | ||
} | ||
|
||
private static void AddAuth(OtlpExporterOptions options) | ||
{ | ||
var authHeader = Environment.GetEnvironmentVariable(OtelAuthHeader); | ||
|
||
if (!string.IsNullOrEmpty(authHeader)) | ||
options.Headers = $"Authorization={authHeader}"; | ||
} | ||
|
||
public static TracerProvider SetUpTracing(string otlpTracingUri) | ||
{ | ||
return Sdk.CreateTracerProviderBuilder() | ||
.AddSource("KboMutations.SyncLambda.Tracing") | ||
.AddAWSInstrumentation()// Optional: if Lambda is triggered by HTTP | ||
.AddConsoleExporter() // Replace with a production exporter | ||
.AddOtlpExporter(options => | ||
{ | ||
options.Endpoint = | ||
new Uri(otlpTracingUri); | ||
|
||
AddAuth(options); | ||
}) | ||
.Build(); | ||
} | ||
|
||
public static void SetUpLogging(string? otlpLogssUri, ILoggingBuilder builder) | ||
{ | ||
if (!string.IsNullOrEmpty(otlpLogssUri)) | ||
builder.AddOpenTelemetry(options => | ||
{ | ||
options.AddConsoleExporter() | ||
.AddOtlpExporter(options => | ||
{ | ||
options.Endpoint = new Uri(otlpLogssUri); | ||
|
||
AddAuth(options); | ||
}); | ||
}); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/AssociationRegistry.KboMutations.SyncLambda/paket.references
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
Amazon.Lambda.SQSEvents | ||
AWSSDK.Core | ||
NodaTime | ||
|
||
OpenTelemetry | ||
OpenTelemetry.Extensions.Hosting | ||
OpenTelemetry.Instrumentation.Runtime | ||
OpenTelemetry.Contrib.Instrumentation.AWS | ||
OpenTelemetry.Exporter.OpenTelemetryProtocol | ||
OpenTelemetry.Exporter.Console | ||
OpenTelemetry.Instrumentation.Http | ||
Npgsql.OpenTelemetry |