Skip to content

Commit

Permalink
feat: add transport compression option (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarisW committed Feb 6, 2023
1 parent 68d0df9 commit 0fc86f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions provider/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type config struct {
enableTracing bool
enableMetrics bool

exportInsecure bool
exportEndpoint string
exportHeaders map[string]string
exportInsecure bool
exportEnableCompression bool
exportEndpoint string
exportHeaders map[string]string

resource *resource.Resource
sdkTracerProvider *sdktrace.TracerProvider
Expand Down Expand Up @@ -171,6 +172,13 @@ func WithInsecure() Option {
})
}

// WithEnableCompression enable gzip transport compression
func WithEnableCompression() Option {
return option(func(cfg *config) {
cfg.exportEnableCompression = true
})
}

// WithSampler configures sampler
func WithSampler(sampler sdktrace.Sampler) Option {
return option(func(cfg *config) {
Expand Down
6 changes: 6 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func NewOpenTelemetryProvider(opts ...Option) *otelProvider {
if cfg.exportInsecure {
traceClientOpts = append(traceClientOpts, otlptracegrpc.WithInsecure())
}
if cfg.exportEnableCompression {
traceClientOpts = append(traceClientOpts, otlptracegrpc.WithCompressor("gzip"))
}

traceClient := otlptracegrpc.NewClient(traceClientOpts...)

Expand Down Expand Up @@ -136,6 +139,9 @@ func NewOpenTelemetryProvider(opts ...Option) *otelProvider {
if cfg.exportInsecure {
metricsClientOpts = append(metricsClientOpts, otlpmetricgrpc.WithInsecure())
}
if cfg.exportEnableCompression {
metricsClientOpts = append(metricsClientOpts, otlpmetricgrpc.WithCompressor("gzip"))
}

// metrics client
metricClient := otlpmetricgrpc.NewClient(metricsClientOpts...)
Expand Down

0 comments on commit 0fc86f9

Please sign in to comment.