Skip to content

Commit

Permalink
Make writing to environments configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
danmux committed Oct 28, 2024
1 parent 6b108fb commit 4650e32
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions config/o11y/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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
Expand Down

0 comments on commit 4650e32

Please sign in to comment.