DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
506 stars 397 forks source link

fix(tracing): do not raise exception if partial flush is triggered without any spans [backport 2.7] #9587

Closed romainkomorndatadog closed 1 week ago

romainkomorndatadog commented 2 weeks ago

Backport fffab017cb2de72d10b35585350c7fa65756e785 from #9349 to 2.7.

Adds a guard against on_span_finish() with partial flushing on running into an IndexError because there are no spans to flush (which may happen if tracer.configure() was called between the time a span was created and the time it was finished).

In practice, this turns into:

>>> import ddtrace
>>> with ddtrace.tracer.trace("regression"):
...     ddtrace.tracer.configure(partial_flush_min_spans=1)
...
Partial flush triggered but no spans to flush (was tracer reconfigured?)

This also refactors the test for our os.fork() wrapper to have the child process unpatch coverage (just in case, since it occasionally causes exceptions on exit) and exit cleanly (otherwise it would continue running other tests which is not what we want).

Checklist

Reviewer Checklist

datadog-dd-trace-py-rkomorn[bot] commented 2 weeks ago

Datadog Report

Branch report: backport-9349-to-2.7 Commit report: 1181227 Test service: dd-trace-py

:x: 1 Failed (0 Known Flaky), 54742 Passed, 115761 Skipped, 10h 31m 32.23s Total duration (2h 20m 29.71s time saved)

:x: Failed Tests (1)

pr-commenter[bot] commented 2 weeks ago

Benchmarks

Benchmark execution time: 2024-06-18 18:22:06

Comparing candidate commit 1181227a5acb89eaadd3fa425e5dc15339375fe6 in PR branch backport-9349-to-2.7 with baseline commit ece781c9e8d76d8c2b734654c083c09045187f56 in branch 2.7.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 193 metrics, 9 unstable metrics.