Repository navigation
Conversation
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryAdds a telemetry mode that exports benchmark spans and Python logs over OTLP/HTTP.
The previous trace-ID finding is fixed. Exporter logger names are also rejected before user filter directives are applied.
|
Merging this PR will improve performance by 11.23%2 warnings, 2 notes
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
17e57f4 to
e7f93a7
Compare
f9c9294 to
153d42a
Compare
153d42a to
7b40c83
Compare
Add a `telemetry` mode, which the runner selects with `CODSPEED_RUNNER_MODE=telemetry`. It runs each benchmark once, sends the start and end of each round to the runner, and skips the perf map warm-up. When `CODSPEED_OTEL_ENDPOINT` is set, the plugin exports the spans of the global tracer provider and the `logging` records over OTLP/HTTP, and flushes them when pytest exits. `CODSPEED_TELEMETRY_FILTER` selects the records (`info` by default). Spans and records also get their times on the clock of the benchmark markers, so that the runner can find the benchmark of each one. The trace and span ids come from a random generator of their own: the plugin reseeds the global one before each benchmark. The OpenTelemetry SDK and exporter come with a new `telemetry` extra. Add an example benchmark that emits telemetry, and install the extra in the benchmarks workflow. Closes COD-4148 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7b40c83 to
54e8003
Compare
Export the spans and logs emitted by the benchmarked code to the CodSpeed runner, so that they can be shown next to each benchmark.
Add a
telemetrymode, selected when the runner setsCODSPEED_RUNNER_MODE=telemetry. It runs each benchmark once, like the other analysis modes, and skips the perf map warm-up, which would emit telemetry outside the benchmark.When
CODSPEED_OTEL_ENDPOINTis set, the plugin exports over OTLP/HTTP, with batch processors flushed when pytest exits:TracerProvider, the export is added to it;loggingrecords, filtered byCODSPEED_TELEMETRY_FILTER(infoby default, e.g.info,my_package=debug). The root logger level is lowered for the run so that the selected records reach the handler. The records of the exporter's own loggers (opentelemetry,urllib3,requests) are never exported.Spans get
codspeed.monotonic_start_ns/codspeed.monotonic_end_nsand log recordscodspeed.monotonic_time_ns, read from the instrument-hooks clock that the benchmark markers use.The OpenTelemetry SDK and exporter come with a new
telemetryextra (>=1.28.0). Without the extra, the plugin warns and exports nothing.Round markers in all analysis modes
The analysis instrument now sends the start and end of each round (
add_benchmark_timestamps) in every mode, not only in telemetry mode. The sample markers sent bystart_benchmark/stop_benchmarkreach the runner tens of microseconds away from the benchmarked code, so the rounds bound it more tightly. The walltime instrument already sends them.add_markerdoes nothing.Things worth a look
random.seed(0)before each benchmark, and the SDK's default id generator draws from the globalrandom. Every benchmark got the same trace and span ids, and the SDK's draws changed the random numbers the benchmarks get. The ids now come from a generator with its ownrandom.Random(). If the benchmarked code installed its ownTracerProvider, the plugin patches its id generator in place, so that tracers created before the plugin starts also use it.LoggerProvider. Onlyloggingrecords are exported, through alogging.Filteron the SDKLoggingHandler. The SDK log processor API changed between 1.28 and 1.45, so stamping records emitted through the OpenTelemetry logs API would need version-specific code.LoggingHandleris deprecated in recent SDK versions; its warning is silenced.service.nameis the name of the pytest rootdir.Example and CI
tests/benchmarks/test_bench_telemetry.pyadds benchmarks that emit spans and logs. The benchmarks workflow installs thetelemetryextra only in the newtelemetrymatrix entry, so the simulation, walltime and memory jobs run without it and check that the plugin works without the extra. Without the extra, these example benchmarks are skipped.The
telemetryjobs currently fail at upload (400 Invalid profile metadata): the CodSpeed API doesn't accept telemetry runs yet.Verification
Checked end to end with a local build of the runner (
codspeed run -m telemetry --skip-upload): it collects 3 spans and 3 logs from the example, thedebugrecord is filtered out, each span and log falls within the round markers of its benchmark, and each benchmark has its own trace id.Round markers in memory mode: ran 73 benchmarks in memory mode with runner v5.8.0, with and without the markers, twice each, and parsed the profiles with the CodSpeed parser.
test_multiprocessing_map,test_threadpool_map) also differ between two runs of the same code, by the same amount.test_iterative_fibo_10goes from 135 B to 0 B. In the local runs,test_sum_squares_fastno longer fails with a missing root frame: these allocations were what caused it.Closes COD-4148