diff --git a/config/o11y/otel.go b/config/o11y/otel.go index 6e012b13e..c74cac383 100644 --- a/config/o11y/otel.go +++ b/config/o11y/otel.go @@ -28,6 +28,8 @@ type OtelConfig struct { HTTPAuthorization secret.String Dataset string + // UseEnvironments will cause spans to be sent to the new honeycomb environments + UseEnvironments bool // DisableText prevents output to stdout for noisy services. Ignored if no other no hosts are supplied DisableText bool @@ -60,11 +62,41 @@ type OtelConfig struct { func Otel(ctx context.Context, o OtelConfig) (context.Context, func(context.Context), error) { hostname, _ := os.Hostname() + cfg := o.otel() + mProv, err := metricsProvider(ctx, o, hostname) if err != nil { return ctx, nil, fmt.Errorf("metrics provider failed: %w", err) } + cfg.Metrics = mProv + + o11yProvider, err := otel.New(cfg) + if err != nil { + return ctx, nil, err + } + + o11yProvider.AddGlobalField("service", o.Service) + o11yProvider.AddGlobalField("version", o.Version) + if o.Mode != "" { + o11yProvider.AddGlobalField("mode", o.Mode) + } + + if o.RollbarToken != "" { + client := rollbar.NewAsync(o.RollbarToken.Raw(), o.RollbarEnv, o.Version, hostname, o.RollbarServerRoot) + client.SetEnabled(!o.RollbarDisabled) + client.Message(rollbar.INFO, "Deployment") + o11yProvider = rollbarOtelProvider{ + Provider: o11yProvider, + rollBarClient: client, + } + } + + ctx = o11y.WithProvider(ctx, o11yProvider) + + return ctx, o11yProvider.Close, nil +} +func (o *OtelConfig) otel() otel.Config { cfg := otel.Config{ GrpcHostAndPort: o.GrpcHostAndPort, HTTPTracesURL: o.HTTPTracesURL, @@ -75,7 +107,6 @@ func Otel(ctx context.Context, o OtelConfig) (context.Context, func(context.Cont semconv.ServiceVersionKey.String(o.Version), // Other Config specific fields attribute.String("service.mode", o.Mode), - attribute.Bool("meta.environments", true), // HC Backwards compatible fields - can remove once boards are updated attribute.String("service", o.Service), @@ -90,34 +121,11 @@ func Otel(ctx context.Context, o OtelConfig) (context.Context, func(context.Cont SampleRates: o.SampleRates, Test: o.Test, - - Metrics: mProv, - } - - o11yProvider, err := otel.New(cfg) - if err != nil { - return ctx, nil, err - } - - o11yProvider.AddGlobalField("service", o.Service) - o11yProvider.AddGlobalField("version", o.Version) - if o.Mode != "" { - o11yProvider.AddGlobalField("mode", o.Mode) } - - if o.RollbarToken != "" { - client := rollbar.NewAsync(o.RollbarToken.Raw(), o.RollbarEnv, o.Version, hostname, o.RollbarServerRoot) - client.SetEnabled(!o.RollbarDisabled) - client.Message(rollbar.INFO, "Deployment") - o11yProvider = rollbarOtelProvider{ - Provider: o11yProvider, - rollBarClient: client, - } + if o.UseEnvironments { + cfg.ResourceAttributes = append(cfg.ResourceAttributes, attribute.Bool("meta.environments", true)) } - - ctx = o11y.WithProvider(ctx, o11yProvider) - - return ctx, o11yProvider.Close, nil + return cfg } // N.B this copies the block from Setup, but don't factor that out since the HC stuff will be removed soon