Skip to content

Commit

Permalink
Merge branch 'main' into rm-otelmacaron
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Oct 4, 2024
2 parents 792f801 + 64a1336 commit 93787da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed

- The function signature of `NewLogProcessor` in `go.opentelemetry.io/contrib/processors/minsev` has changed to accept the added `Severitier` interface instead of a `log.Severity`. (#6116)
- `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a no-op SDK if `disabled` is set to `true`. (#6185)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ instrumentation/google.golang.org/grpc/otelgrpc/ @open-te
instrumentation/host/ @open-telemetry/go-approvers @dmathieu
instrumentation/net/http/httptrace/otelhttptrace/ @open-telemetry/go-approvers @dmathieu
instrumentation/net/http/otelhttp/ @open-telemetry/go-approvers @dmathieu
instrumentation/runtime/ @open-telemetry/go-approvers @dmathieu
instrumentation/runtime/ @open-telemetry/go-approvers @dmathieu @dashpole

processors/baggagecopy @open-telemetry/go-approvers @codeboten @MikeGoldsmith
processors/minsev @open-telemetry/go-approvers @MrAlias
Expand Down
21 changes: 17 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (
"gopkg.in/yaml.v3"

"go.opentelemetry.io/otel/log"
nooplog "go.opentelemetry.io/otel/log/noop"
"go.opentelemetry.io/otel/metric"
noopmetric "go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/trace"
nooptrace "go.opentelemetry.io/otel/trace/noop"
)

const (
Expand Down Expand Up @@ -62,31 +65,41 @@ func (s *SDK) Shutdown(ctx context.Context) error {
return s.shutdown(ctx)
}

var noopSDK = SDK{
loggerProvider: nooplog.LoggerProvider{},
meterProvider: noopmetric.MeterProvider{},
tracerProvider: nooptrace.TracerProvider{},
shutdown: func(ctx context.Context) error { return nil },
}

// NewSDK creates SDK providers based on the configuration model.
func NewSDK(opts ...ConfigurationOption) (SDK, error) {
o := configOptions{}
for _, opt := range opts {
o = opt.apply(o)
}
if o.opentelemetryConfig.Disabled != nil && *o.opentelemetryConfig.Disabled {
return noopSDK, nil
}

r, err := newResource(o.opentelemetryConfig.Resource)
if err != nil {
return SDK{}, err
return noopSDK, err
}

mp, mpShutdown, err := meterProvider(o, r)
if err != nil {
return SDK{}, err
return noopSDK, err
}

tp, tpShutdown, err := tracerProvider(o, r)
if err != nil {
return SDK{}, err
return noopSDK, err
}

lp, lpShutdown, err := loggerProvider(o, r)
if err != nil {
return SDK{}, err
return noopSDK, err
}

return SDK{
Expand Down
15 changes: 15 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ func TestNewSDK(t *testing.T) {
wantMeterProvider: &sdkmetric.MeterProvider{},
wantLoggerProvider: &sdklog.LoggerProvider{},
},
{
name: "with-sdk-disabled",
cfg: []ConfigurationOption{
WithContext(context.Background()),
WithOpenTelemetryConfiguration(OpenTelemetryConfiguration{
Disabled: ptr(true),
TracerProvider: &TracerProvider{},
MeterProvider: &MeterProvider{},
LoggerProvider: &LoggerProvider{},
}),
},
wantTracerProvider: tracenoop.NewTracerProvider(),
wantMeterProvider: metricnoop.NewMeterProvider(),
wantLoggerProvider: lognoop.NewLoggerProvider(),
},
}
for _, tt := range tests {
sdk, err := NewSDK(tt.cfg...)
Expand Down

0 comments on commit 93787da

Please sign in to comment.