mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-11 02:47:05 +00:00
refactor(otel): move to observability package
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
_ "github.com/KimMachineGun/automemlimit"
|
||||
"github.com/nais/wonderwall/internal/observability"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.uber.org/automaxprocs"
|
||||
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
"github.com/nais/wonderwall/pkg/metrics"
|
||||
openidconfig "github.com/nais/wonderwall/pkg/openid/config"
|
||||
"github.com/nais/wonderwall/pkg/openid/provider"
|
||||
"github.com/nais/wonderwall/pkg/otel"
|
||||
"github.com/nais/wonderwall/pkg/router"
|
||||
"github.com/nais/wonderwall/pkg/server"
|
||||
)
|
||||
@@ -53,9 +53,9 @@ func run() error {
|
||||
}
|
||||
|
||||
if cfg.OpenTelemetry.Enabled {
|
||||
otelShutdown, err := otel.Setup(ctx, cfg)
|
||||
otelShutdown, err := observability.OpenTelemetry(ctx, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("initializing OpenTelemetry: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
log.Fatalf("fatal: otel shutdown error: %+v", otelShutdown(context.Background()))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package otel
|
||||
package observability
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,16 +6,17 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/nais/wonderwall/pkg/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
)
|
||||
|
||||
func Setup(ctx context.Context, cfg *config.Config) (shutdown func(context.Context) error, err error) {
|
||||
func OpenTelemetry(ctx context.Context, cfg *config.Config) (shutdown func(context.Context) error, err error) {
|
||||
var shutdownFuncs []func(context.Context) error
|
||||
|
||||
shutdown = func(ctx context.Context) error {
|
||||
@@ -47,6 +48,7 @@ func Setup(ctx context.Context, cfg *config.Config) (shutdown func(context.Conte
|
||||
shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown)
|
||||
otel.SetTracerProvider(tracerProvider)
|
||||
|
||||
log.Infof("opentelemetry: initialized configuration")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ const (
|
||||
)
|
||||
|
||||
func otelFlags() {
|
||||
// TODO: automatically enable if OTEL_EXPORTER_OTLP_ENDPOINT env var is set
|
||||
flag.Bool(OpenTelemetryEnabled, false, "Enable OpenTelemetry tracing.")
|
||||
flag.String(OpenTelemetryServiceName, "wonderwall", "Service name to use for OpenTelemetry.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user