Skip to content

Commit

Permalink
Make ExportSpans for Jaeger Exporter honor deadline (#1773)
Browse files Browse the repository at this point in the history
* Make ExportSpans for Jaeger honor deadline

* Make variable name more descriptive

* new commit

* Revert "new commit"

This reverts commit 06e24cc.

* Change PR number in changelog

* Take out separate goroutine and add back TODO

* Check error string

* Fix error assert

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
humivo and MrAlias authored Apr 5, 2021
1 parent 0786fe3 commit 5bbfc22
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
This changes it to make `SamplingParameters` conform with the OpenTelemetry specification. (#1749)
- Modify `BatchSpanProcessor.ForceFlush` to abort after timeout/cancellation. (#1757)
- Improve OTLP/gRPC exporter connection errors. (#1737)
- Make `ExportSpans` in Jaeger Exporter honor context deadline. (#1773)

### Removed

Expand Down
8 changes: 7 additions & 1 deletion exporters/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,17 @@ func (e *Exporter) ExportSpans(ctx context.Context, ss []*export.SpanSnapshot) e

for _, span := range ss {
// TODO(jbd): Handle oversized bundlers.
err := e.bundler.Add(span, 1)
err := e.bundler.AddWait(ctx, span, 1)
if err != nil {
return fmt.Errorf("failed to bundle %q: %w", span.Name, err)
}
select {
case <-ctx.Done():
return ctx.Err()
default:
}
}

return nil
}

Expand Down
61 changes: 61 additions & 0 deletions exporters/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,67 @@ func TestErrorOnExportShutdownExporter(t *testing.T) {
assert.NoError(t, e.ExportSpans(context.Background(), nil))
}

func TestExporterExportSpansHonorsCancel(t *testing.T) {
e, err := NewRawExporter(withTestCollectorEndpoint())
require.NoError(t, err)
now := time.Now()
ss := []*export.SpanSnapshot{
{
Name: "s1",
Resource: resource.NewWithAttributes(
semconv.ServiceNameKey.String("name"),
attribute.Key("r1").String("v1"),
),
StartTime: now,
EndTime: now,
},
{
Name: "s2",
Resource: resource.NewWithAttributes(
semconv.ServiceNameKey.String("name"),
attribute.Key("r2").String("v2"),
),
StartTime: now,
EndTime: now,
},
}
ctx, cancel := context.WithCancel(context.Background())
cancel()

assert.EqualError(t, e.ExportSpans(ctx, ss), context.Canceled.Error())
}

func TestExporterExportSpansHonorsTimeout(t *testing.T) {
e, err := NewRawExporter(withTestCollectorEndpoint())
require.NoError(t, err)
now := time.Now()
ss := []*export.SpanSnapshot{
{
Name: "s1",
Resource: resource.NewWithAttributes(
semconv.ServiceNameKey.String("name"),
attribute.Key("r1").String("v1"),
),
StartTime: now,
EndTime: now,
},
{
Name: "s2",
Resource: resource.NewWithAttributes(
semconv.ServiceNameKey.String("name"),
attribute.Key("r2").String("v2"),
),
StartTime: now,
EndTime: now,
},
}
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
defer cancel()
<-ctx.Done()

assert.EqualError(t, e.ExportSpans(ctx, ss), context.DeadlineExceeded.Error())
}

func TestJaegerBatchList(t *testing.T) {
newString := func(value string) *string {
return &value
Expand Down

0 comments on commit 5bbfc22

Please sign in to comment.