mirror of
https://github.com/hanzoai/gateway.git
synced 2026-10-30 15:04:44 +00:00
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]>
43 lines
1.1 KiB
Go
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")
|