Skip to content

Commit

Permalink
Do not error on "none" trace exporter value
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jan 26, 2022
1 parent a7fafc5 commit c283a31
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions distro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ a batch span processor.
The environment variable values are restricted to the following.
- `"otlp"`: OTLP gRPC exporter.
- `"jaeger-thrift-splunk"`: Jaeger thrift exporter.
- `"none"`: None, explicitly do not set an exporter. An error is raised by
the SDK if no other exporter option is defined.
- `"none"`: None, explicitly do not set an exporter.

Any other value will be ignored and the default used instead.

Expand Down
2 changes: 1 addition & 1 deletion distro/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func WithAccessToken(accessToken string) Option {
// is not provided. Valid values for this environment variable are "otlp" for
// an OTLP exporter, and "jaeger-thrift-splunk" for a Splunk specific Jaeger
// thrift exporter. If this environment variable is set to "none", no exporter
// is registered and Run will return an error stating this.
// is registered.
//
// By default, an OTLP exporter is used if this is not provided or the
// OTEL_TRACES_EXPORTER environment variable is not set.
Expand Down
17 changes: 10 additions & 7 deletions distro/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package distro

import (
"context"
"errors"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/trace"
Expand All @@ -39,7 +38,10 @@ type SDK struct {

// Shutdown stops the SDK and releases any used resources.
func (s SDK) Shutdown(ctx context.Context) error {
return s.shutdownFunc(ctx)
if s.shutdownFunc != nil {
return s.shutdownFunc(ctx)
}
return nil
}

// Run configures the default OpenTelemetry SDK and installs it globally.
Expand All @@ -50,8 +52,13 @@ func (s SDK) Shutdown(ctx context.Context) error {
func Run(opts ...Option) (SDK, error) {
c := newConfig(opts...)

if c.Propagator != nil && c.Propagator != nonePropagator {
otel.SetTextMapPropagator(c.Propagator)
}

if c.TraceExporterFunc == nil {
return SDK{}, errors.New(`"none" exporter set`)
// "none" exporter configured.
return SDK{}, nil
}
exp, err := c.TraceExporterFunc(c.ExportConfig)
if err != nil {
Expand All @@ -65,10 +72,6 @@ func Run(opts ...Option) (SDK, error) {
)
otel.SetTracerProvider(traceProvider)

if c.Propagator != nil && c.Propagator != nonePropagator {
otel.SetTextMapPropagator(c.Propagator)
}

return SDK{
config: *c,
shutdownFunc: func(ctx context.Context) error {
Expand Down
6 changes: 0 additions & 6 deletions distro/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,3 @@ func TestInvalidTraceExporter(t *testing.T) {
got := <-coll.traceService.requests
assert.Equal(t, []string{"application/grpc"}, got.Header.Get("Content-type"))
}

func TestNoneExporterErrors(t *testing.T) {
t.Cleanup(distro.Setenv("OTEL_TRACES_EXPORTER", "none"))
_, err := distro.Run()
require.Error(t, err, "setting traces exporter to none should error")
}

0 comments on commit c283a31

Please sign in to comment.