From 6ea435c3d3e8fe4a4fae3c9514584836f2835811 Mon Sep 17 00:00:00 2001 From: Asger Noer <55031664+asger-noer@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:39:57 +1300 Subject: [PATCH] feat: overwrite with environment variable --- docs/configuration.md | 2 +- telemetry.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index a66c8f94..094c9dc1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -98,7 +98,7 @@ Sample configuration: - Default: `false` - Supports hot-reload: No - `endpoint`: OpenTelemetry collector endpoint. - - Default: If no endpoint is specified, telemetry is disabled. + - Default: If no endpoint is specified, telemetry is disabled. Bramble will check for `BRAMBLE_OTEL_ENDPOINT` environment variable and use it if set. - Supports hot-reload: No - `serviceName`: Service name to use for OpenTelemetry. - Default: `bramble` diff --git a/telemetry.go b/telemetry.go index f14ea6c7..a40caf63 100644 --- a/telemetry.go +++ b/telemetry.go @@ -3,6 +3,7 @@ package bramble import ( "context" "errors" + "os" "github.com/sirupsen/logrus" "go.opentelemetry.io/otel" @@ -41,6 +42,11 @@ func (e *TelemetryErrHandler) Handle(err error) { // returns a shutdown function that should be called when the application // terminates. func InitTelemetry(ctx context.Context, cfg TelemetryConfig) (func(context.Context) error, error) { + endpoint := os.Getenv("BRAMBLE_OTEL_ENDPOINT") + if endpoint != "" { + cfg.Endpoint = endpoint + } + // If telemetry is disabled, return a no-op shutdown function. The standard // behaviour of the application will not be affected, since a // `NoopTracerProvider` is used by default.