Skip to content

Commit 8bc967d

Browse files
authored
Merge branch 'main' into 1618-ForceFlushAborts
2 parents 776fb17 + bf180d0 commit 8bc967d

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2525
- The `ParentContext` field of the `"go.opentelemetry.io/otel/sdk/trace".SamplingParameters` is updated to hold a `context.Context` containing the parent span.
2626
This changes it to make `SamplingParameters` conform with the OpenTelemetry specification. (#1749)
2727
- Modify `BatchSpanProcessor.ForceFlush` to abort after timeout/cancellation. (#1757)
28+
- Improve OTLP/gRPC exporter connection errors. (#1737)
2829

2930
### Removed
3031

exporters/otlp/otlpgrpc/driver.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ type driver struct {
4141
}
4242

4343
var (
44-
errNoClient = errors.New("no client")
45-
errDisconnected = errors.New("exporter disconnected")
44+
errNoClient = errors.New("no client")
4645
)
4746

4847
// NewDriver creates a new gRPC protocol driver.
@@ -88,7 +87,7 @@ func (d *driver) Stop(ctx context.Context) error {
8887
// to protobuf binary format and sends the result to the collector.
8988
func (d *driver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error {
9089
if !d.connection.connected() {
91-
return errDisconnected
90+
return fmt.Errorf("exporter disconnected: %w", d.connection.lastConnectError())
9291
}
9392
ctx, cancel := d.connection.contextWithStop(ctx)
9493
defer cancel()
@@ -127,7 +126,7 @@ func (d *driver) uploadMetrics(ctx context.Context, protoMetrics []*metricpb.Res
127126
// protobuf binary format and sends the result to the collector.
128127
func (d *driver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
129128
if !d.connection.connected() {
130-
return errDisconnected
129+
return fmt.Errorf("exporter disconnected: %w", d.connection.lastConnectError())
131130
}
132131
ctx, cancel := d.connection.contextWithStop(ctx)
133132
defer cancel()

exporters/otlp/otlpgrpc/otlp_integration_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,27 @@ func TestNewExporter_withHeaders(t *testing.T) {
316316
assert.Equal(t, "value1", headers.Get("header1")[0])
317317
}
318318

319+
func TestNewExporter_withInvalidSecurityConfiguration(t *testing.T) {
320+
mc := runMockCollector(t)
321+
defer func() {
322+
_ = mc.stop()
323+
}()
324+
325+
ctx := context.Background()
326+
driver := otlpgrpc.NewDriver(otlpgrpc.WithEndpoint(mc.endpoint))
327+
exp, err := otlp.NewExporter(ctx, driver)
328+
if err != nil {
329+
t.Fatalf("failed to create a new collector exporter: %v", err)
330+
}
331+
332+
err = exp.ExportSpans(ctx, []*exporttrace.SpanSnapshot{{Name: "misconfiguration"}})
333+
require.Equal(t, err.Error(), "exporter disconnected: grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)")
334+
335+
defer func() {
336+
_ = exp.Shutdown(ctx)
337+
}()
338+
}
339+
319340
func TestNewExporter_withMultipleAttributeTypes(t *testing.T) {
320341
mc := runMockCollector(t)
321342

0 commit comments

Comments
 (0)