Files
zeekayandHanzo Dev a5c5cc019e Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 22:42:15 -07:00

43 lines
1.1 KiB
Go

package datadog
import (
"context"
"errors"
datadog "github.com/DataDog/opencensus-go-exporter-datadog"
opencensus "github.com/hanzoai/gateway/v2/internal/plugin/opencensus"
)
func init() {
opencensus.RegisterExporterFactories(func(ctx context.Context, cfg opencensus.Config) (any, error) {
return Exporter(ctx, cfg)
})
}
func Exporter(ctx context.Context, cfg opencensus.Config) (*datadog.Exporter, error) {
if cfg.Exporters.DataDog == nil {
return nil, errDisabled
}
e, err := datadog.NewExporter(datadog.Options{
Namespace: cfg.Exporters.DataDog.Namespace,
Service: cfg.Exporters.DataDog.Service,
TraceAddr: cfg.Exporters.DataDog.TraceAddr,
StatsAddr: cfg.Exporters.DataDog.StatsAddr,
Tags: cfg.Exporters.DataDog.Tags,
GlobalTags: cfg.Exporters.DataDog.GlobalTags,
DisableCountPerBuckets: cfg.Exporters.DataDog.DisableCountPerBuckets,
})
if err != nil {
return e, err
}
go func() {
<-ctx.Done()
e.Stop()
}()
return e, nil
}
var errDisabled = errors.New("opencensus datadog exporter disabled")