Skip to content

Commit

Permalink
improve OTLP/gRPC connection errors (#1737)
Browse files Browse the repository at this point in the history
* improve OTLP/gRPC connection errors

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
paivagustavo and MrAlias authored Mar 31, 2021
1 parent d575865 commit bf180d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
The existing `ParentSpanID` and `HasRemoteParent` fields are removed in favor of this. (#1748)
- The `ParentContext` field of the `"go.opentelemetry.io/otel/sdk/trace".SamplingParameters` is updated to hold a `context.Context` containing the parent span.
This changes it to make `SamplingParameters` conform with the OpenTelemetry specification. (#1749)
- Improve OTLP/gRPC exporter connection errors. (#1737)

### Removed

Expand Down
7 changes: 3 additions & 4 deletions exporters/otlp/otlpgrpc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type driver struct {
}

var (
errNoClient = errors.New("no client")
errDisconnected = errors.New("exporter disconnected")
errNoClient = errors.New("no client")
)

// NewDriver creates a new gRPC protocol driver.
Expand Down Expand Up @@ -88,7 +87,7 @@ func (d *driver) Stop(ctx context.Context) error {
// to protobuf binary format and sends the result to the collector.
func (d *driver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error {
if !d.connection.connected() {
return errDisconnected
return fmt.Errorf("exporter disconnected: %w", d.connection.lastConnectError())
}
ctx, cancel := d.connection.contextWithStop(ctx)
defer cancel()
Expand Down Expand Up @@ -127,7 +126,7 @@ func (d *driver) uploadMetrics(ctx context.Context, protoMetrics []*metricpb.Res
// protobuf binary format and sends the result to the collector.
func (d *driver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
if !d.connection.connected() {
return errDisconnected
return fmt.Errorf("exporter disconnected: %w", d.connection.lastConnectError())
}
ctx, cancel := d.connection.contextWithStop(ctx)
defer cancel()
Expand Down
21 changes: 21 additions & 0 deletions exporters/otlp/otlpgrpc/otlp_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@ func TestNewExporter_withHeaders(t *testing.T) {
assert.Equal(t, "value1", headers.Get("header1")[0])
}

func TestNewExporter_withInvalidSecurityConfiguration(t *testing.T) {
mc := runMockCollector(t)
defer func() {
_ = mc.stop()
}()

ctx := context.Background()
driver := otlpgrpc.NewDriver(otlpgrpc.WithEndpoint(mc.endpoint))
exp, err := otlp.NewExporter(ctx, driver)
if err != nil {
t.Fatalf("failed to create a new collector exporter: %v", err)
}

err = exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "misconfiguration"}})
require.Equal(t, err.Error(), "exporter disconnected: grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)")

defer func() {
_ = exp.Shutdown(ctx)
}()
}

func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
mc := runMockCollector(t)

Expand Down

0 comments on commit bf180d0

Please sign in to comment.