mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-30 21:20:04 +02:00
Make ExportSpans for Jaeger Exporter honor deadline (#1773)
* Make ExportSpans for Jaeger honor deadline
* Make variable name more descriptive
* new commit
* Revert "new commit"
This reverts commit 06e24cc38d
.
* 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>
This commit is contained in:
parent
0786fe3250
commit
5bbfc22cbc
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user