1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

sdk/metric: Record measurements when context is done (#4671)

This commit is contained in:
Robert Pająk
2023-12-15 19:14:16 +01:00
committed by GitHub
parent 057f897096
commit 8e756513a6
5 changed files with 44 additions and 12 deletions
+12
View File
@@ -1133,6 +1133,18 @@ func TestNilSpanEnd(t *testing.T) {
span.End()
}
func TestSpanWithCanceledContext(t *testing.T) {
te := NewTestExporter()
tp := NewTracerProvider(WithSyncer(te))
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, span := tp.Tracer(t.Name()).Start(ctx, "span")
span.End()
assert.Equal(t, 1, te.Len(), "span recording must ignore context cancelation")
}
func TestNonRecordingSpanDoesNotTrackRuntimeTracerTask(t *testing.T) {
tp := NewTracerProvider(WithSampler(NeverSample()))
tr := tp.Tracer("TestNonRecordingSpanDoesNotTrackRuntimeTracerTask")