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]>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package xray
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
ocAws "contrib.go.opencensus.io/exporter/aws"
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
"github.com/aws/aws-sdk-go/service/xray"
|
|
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(_ context.Context, cfg opencensus.Config) (*ocAws.Exporter, error) {
|
|
if cfg.Exporters.Xray == nil {
|
|
return nil, errors.New("xray exporter disabled")
|
|
}
|
|
if cfg.Exporters.Xray.Version == "" {
|
|
cfg.Exporters.Xray.Version = "KrakenD-opencensus"
|
|
}
|
|
|
|
if !cfg.Exporters.Xray.UseEnv {
|
|
mySession := setupAWSSession(cfg.Exporters.Xray.AccessKey, cfg.Exporters.Xray.SecretKey, cfg.Exporters.Xray.Region)
|
|
return ocAws.NewExporter(
|
|
ocAws.WithAPI(xray.New(mySession, aws.NewConfig().WithRegion(cfg.Exporters.Xray.Region))),
|
|
ocAws.WithRegion(cfg.Exporters.Xray.Region),
|
|
ocAws.WithInterval(time.Duration(cfg.ReportingPeriod)),
|
|
ocAws.WithBufferSize(cfg.SampleRate),
|
|
ocAws.WithVersion(cfg.Exporters.Xray.Version),
|
|
)
|
|
}
|
|
|
|
return ocAws.NewExporter(
|
|
ocAws.WithRegion(cfg.Exporters.Xray.Region),
|
|
ocAws.WithInterval(time.Duration(cfg.ReportingPeriod)),
|
|
ocAws.WithBufferSize(cfg.SampleRate),
|
|
ocAws.WithVersion(cfg.Exporters.Xray.Version),
|
|
)
|
|
}
|
|
|
|
func setupAWSSession(id, secret, region string) *session.Session {
|
|
return session.Must(session.NewSession(&aws.Config{
|
|
Credentials: credentials.NewStaticCredentials(id, secret, ""),
|
|
Region: new(region),
|
|
}))
|
|
}
|