Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/provider config #78

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions providerconfig/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/log/global"
"go.opentelemetry.io/otel/propagation"
sdklog "go.opentelemetry.io/otel/sdk/log"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

// initializing through main and manually setting the providers.
Expand Down Expand Up @@ -81,6 +84,24 @@ func ExampleWithResourceOptions() {
)
}

func ExampleWithTraceProviderOptions() {
providerconfig.New(
providerconfig.WithTraceProviderOptions(sdktrace.WithSampler(sdktrace.AlwaysSample())),
)
}

func ExampleWithLogProviderOptions() {
providerconfig.New(
providerconfig.WithLogProviderOptions(sdklog.WithAttributeCountLimit(15)),
)
}

func ExampleWithMetricProviderOptions() {
providerconfig.New(
providerconfig.WithMetricProviderOptions(sdkmetric.WithReader(sdkmetric.NewManualReader())),
)
}

func ExampleWithDisabledSignals() {
providerconfig.New(
providerconfig.WithDisabledSignals(
Expand Down
49 changes: 35 additions & 14 deletions providerconfig/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ type Option func(*config)
type Options []Option

type config struct {
applicationName string
applicationVersion string
resourceOptions []resource.Option
prometheusBridge bool
metricInit bool
traceInit bool
logInit bool
disableTraces bool
disableMetrics bool
disableLogs bool
signalProcessor SignalProcessor
tracePropagator propagation.TextMapPropagator
executionType Execution
applicationName string
applicationVersion string
resourceOptions []resource.Option
prometheusBridge bool
metricInit bool
traceInit bool
logInit bool
disableTraces bool
disableMetrics bool
disableLogs bool
signalProcessor SignalProcessor
tracePropagator propagation.TextMapPropagator
executionType Execution
traceProviderOptions []sdktrace.TracerProviderOption
logProviderOptions []sdklog.LoggerProviderOption
metricProviderOptions []sdkmetric.Option
}

func WithApplicationName(applicationName string) Option {
Expand All @@ -73,6 +76,24 @@ func WithResourceOptions(resourceOptions ...resource.Option) Option {
}
}

func WithTraceProviderOptions(options ...sdktrace.TracerProviderOption) Option {
return func(c *config) {
c.traceProviderOptions = options
}
}

func WithMetricProviderOptions(options ...sdkmetric.Option) Option {
return func(c *config) {
c.metricProviderOptions = options
}
}

func WithLogProviderOptions(options ...sdklog.LoggerProviderOption) Option {
return func(c *config) {
c.logProviderOptions = options
}
}

// WithPrometheusBridge enables the Prometheus bridge in the configuration.
// The Prometheus bridge allows exporting metrics from the Prometheus instrumentation
// and forward them over OTLP to an endpoint.
Expand Down Expand Up @@ -212,7 +233,7 @@ func initConfig(options Options) *config {
}

func newResource(applicationName, applicationVersion string, resources ...resource.Option) *resource.Resource {
resList := make([]resource.Option, len(resources))
resList := make([]resource.Option, 0, len(resources))
resList = append(resList, resources...)
resList = append(resList, resource.WithAttributes(
semconv.ServiceNameKey.String(applicationName),
Expand Down
Loading