Skip to content

Commit

Permalink
Fix nil panic from otlp exporter (open-telemetry#6633)
Browse files Browse the repository at this point in the history
* fix nil panic from otlp exporter.

* fix nil panic from otlp exporter.

* fix nil panic from otlp exporter.
  • Loading branch information
pavankrish123 authored and jaronoff97 committed Dec 14, 2022
1 parent d1f4f6d commit e378147
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .chloggen/authpanic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: otlpexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix nil panic from otlp exporter in case of errors during Start.

# One or more tracking issues or pull requests related to the change
issues: [6633]

5 changes: 3 additions & 2 deletions exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ func TestCreateTracesExporter(t *testing.T) {
err = consumer.Start(context.Background(), componenttest.NewNopHost())
if tt.mustFailOnStart {
assert.Error(t, err)
return
} else {
assert.NoError(t, err)
}
assert.NoError(t, err)
// Shutdown is called even when Start fails
err = consumer.Shutdown(context.Background())
if err != nil {
// Since the endpoint of OTLP exporter doesn't actually exist,
Expand Down
6 changes: 4 additions & 2 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (e *exporter) start(ctx context.Context, host component.Host) (err error) {
if e.clientConn, err = e.config.GRPCClientSettings.ToClientConn(ctx, host, e.settings, grpc.WithUserAgent(e.userAgent)); err != nil {
return err
}

e.traceExporter = ptraceotlp.NewGRPCClient(e.clientConn)
e.metricExporter = pmetricotlp.NewGRPCClient(e.clientConn)
e.logExporter = plogotlp.NewGRPCClient(e.clientConn)
Expand All @@ -90,7 +89,10 @@ func (e *exporter) start(ctx context.Context, host component.Host) (err error) {
}

func (e *exporter) shutdown(context.Context) error {
return e.clientConn.Close()
if e.clientConn != nil {
return e.clientConn.Close()
}
return nil
}

func (e *exporter) pushTraces(ctx context.Context, td ptrace.Traces) error {
Expand Down

0 comments on commit e378147

Please sign in to comment.