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

38 lines
1.0 KiB
Go

package influxdb
import (
"context"
"errors"
"time"
opencensus "github.com/hanzoai/gateway/v2/internal/plugin/opencensus"
"github.com/kpacha/opencensus-influxdb"
)
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) (*influxdb.Exporter, error) {
if cfg.Exporters.InfluxDB == nil {
return nil, errDisabled
}
timeout, err := time.ParseDuration(cfg.Exporters.InfluxDB.Timeout)
if err != nil {
timeout = 0
}
return influxdb.NewExporter(ctx, influxdb.Options{
Address: cfg.Exporters.InfluxDB.Address,
Username: cfg.Exporters.InfluxDB.Username,
Password: cfg.Exporters.InfluxDB.Password,
Database: cfg.Exporters.InfluxDB.Database,
Timeout: timeout,
InstanceName: cfg.Exporters.InfluxDB.InstanceName,
ReportingPeriod: time.Duration(cfg.ReportingPeriod) * time.Second,
})
}
var errDisabled = errors.New("opencensus influxdb exporter disabled")