Skip to content

Commit

Permalink
Support ID generator
Browse files Browse the repository at this point in the history
  • Loading branch information
qiansheng91 committed May 11, 2022
1 parent f047ca0 commit 4c80236
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions provider/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ func WithSLSConfig(project, instanceID, accessKeyID, accessKeySecret string) Opt
}
}

func WithIDGenerator(generator sdktrace.IDGenerator) Option {
return func(config *Config) {
if generator != nil {
config.IDGenerator = generator
}
}
}

// Config configure for sls otel
type Config struct {
TraceExporterEndpoint string `env:"SLS_OTEL_TRACE_ENDPOINT,default=stdout"`
Expand All @@ -169,6 +177,7 @@ type Config struct {
AccessKeyID string `env:"SLS_OTEL_ACCESS_KEY_ID"`
AccessKeySecret string `env:"SLS_OTEL_ACCESS_KEY_SECRET"`
AttributesEnvKeys string `env:"SLS_OTEL_ATTRIBUTES_ENV_KEYS"`
IDGenerator sdktrace.IDGenerator

Resource *resource.Resource

Expand Down Expand Up @@ -330,7 +339,7 @@ func (c *Config) initMetric(metricsExporter metric.Exporter, stop func()) error
}

// 初始化Traces,默认全量上传
func (c *Config) initTracer(traceExporter trace.SpanExporter, stop func()) error {
func (c *Config) initTracer(traceExporter trace.SpanExporter, stop func(), config *Config) error {
if traceExporter == nil {
return nil
}
Expand All @@ -341,6 +350,7 @@ func (c *Config) initTracer(traceExporter trace.SpanExporter, stop func()) error
traceExporter,
sdktrace.WithMaxExportBatchSize(10),
),
sdktrace.WithIDGenerator(config.IDGenerator),
sdktrace.WithResource(c.Resource),
)
otel.SetTracerProvider(tp)
Expand Down Expand Up @@ -413,7 +423,7 @@ func Start(c *Config) error {
if err != nil {
return err
}
err = c.initTracer(traceExporter, traceExpStop)
err = c.initTracer(traceExporter, traceExpStop, c)
if err != nil {
return err
}
Expand Down

0 comments on commit 4c80236

Please sign in to comment.