Repository navigation
Conversation
Add a `telemetry` feature to `codspeed-criterion-compat`, as `codspeed-divan-compat` has. When `CODSPEED_OTEL_ENDPOINT` is set, the `main` of `criterion_main!` installs the `tracing` subscriber of `codspeed`, which exports spans as traces, and `tracing` events and `log` records as logs, and keeps it until the groups are done. The export is the one of the `codspeed` crate, so only the telemetry build of `cargo-codspeed` compiles it. The macro expands in the user's crate, where it can't check the feature of the compat crate, so it calls a hidden function that is a no-op without the feature. `criterion::telemetry` re-exports the module, for custom `main` functions and benchmarks installing their own subscriber. `benches/telemetry.rs` emits telemetry in each way the divan example does. It needs the feature, so builds without it skip it. Closes COD-4287 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Merging this PR will degrade performance by 4.78%4 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Export the traces and logs that Criterion.rs benchmarks emit with
tracingandlog, as #197 did for divan. Using it takes thetelemetryfeature ofcodspeed-criterion-compatand a telemetry build:cargo codspeed build -m telemetry # or with other modes, e.g. -m simulation,telemetry codspeed run -m telemetry -- cargo codspeed runWhen
CODSPEED_OTEL_ENDPOINTis set, themainofcriterion_main!installs thetracingsubscriber ofcodspeed, which exports spans as traces, andtracingevents andlogrecords as logs, and keeps it until the groups are done. The export, its filter (CODSPEED_TELEMETRY_FILTER) and its timing attributes are the ones ofcodspeed, unchanged: only the telemetry build ofcargo-codspeedcompiles them.Worth a careful look
criterion_main!expands in the user's crate, where#[cfg(feature = "telemetry")]would read the user's features, not ours. So the macro calls a hidden__init_telemetry()of the compat crate, which returns the guard with the feature andNonewithout it.cargo codspeed, is unchanged.main(theCriterion::new_instrumented()pattern) callscriterion::telemetry::init()itself and keeps the guard, as a divan benchmark with its own subscriber addsdivan::telemetry::layer(). This is for the docs, along with lifting their divan-only note.crates/criterion_compat/benches/telemetry.rsemits telemetry in each of the ways the divan example does. It needs the feature (required-features), socargo codspeed build -p codspeed-criterion-compatwithout--features telemetry, as in CI, skips it.Checked end to end with a telemetry build of that bench run against a local OTLP/HTTP receiver: the
infospans (parse_and_sum,parse,sum) arrive on/v1/traces, the events andlogrecords on/v1/logs, and thedebugones are filtered out. WithoutCODSPEED_OTEL_ENDPOINT, nothing is sent.Closes COD-4287