Skip to content

Commit d4333fe

Browse files
committed
agents,lib,src,test: add traceSampleRate support
Add end-to-end traceSampleRate handling across config, runtime propagation, tracing decisions, and regression tests. Why: - Enable configurable probabilistic trace sampling with predictable behavior. - Ensure consistent semantics across all config entry points. - Prevent invalid updates from corrupting current sampling behavior. - Keep transaction consistency by deciding sampling at the root span only. What changed: - Added traceSampleRate parsing and normalization in JS config paths with explicit default fallback and finite/range validation in [0, 1]. - Added native config sanitization for traceSampleRate to reject invalid values before merge, preserving previous valid configuration. - Ensured runtime sampling state is synchronized from effective current config after updates to avoid stale shared-memory sample rates. - Added gRPC reconfigure support for traceSampleRate in proto and agent mapping, including generated protobuf updates. - Updated tracing logic so root spans perform the sampling decision and child spans inherit parent traceFlags. - Extended tests for: - invalid value handling (including NaN/Infinity) - env/package bootstrap behavior - partial updates preserving existing traceSampleRate - gRPC invalid-update fallback behavior - sampling behavior at 0%, 50% (tolerance), and 100% - worker-thread sampling behavior - explicit parent/child trace consistency assertions
1 parent a7ffd74 commit d4333fe

15 files changed

Lines changed: 540 additions & 43 deletions

agents/grpc/proto/reconfigure.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ message ReconfigureBody {
1818
optional uint32 tracingModulesBlacklist = 11;
1919
optional bool contCpuProfile = 12;
2020
optional bool assetsEnabled = 13;
21+
optional double traceSampleRate = 14;
2122
}
2223

2324
message ReconfigureEvent {

agents/grpc/src/grpc_agent.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ void PopulateReconfigureEvent(grpcagent::ReconfigureEvent* reconfigure_event,
385385
if (it != config.end()) {
386386
body->set_assetsenabled(*it);
387387
}
388+
389+
it = config.find("traceSampleRate");
390+
if (it != config.end()) {
391+
body->set_tracesamplerate(*it);
392+
}
388393
}
389394

390395
void PopulateStartupTimesEvent(grpcagent::StartupTimesEvent* st_events,
@@ -1758,6 +1763,10 @@ void GrpcAgent::reconfigure(const grpcagent::CommandRequest& request) {
17581763
out["assetsEnabled"] = body.assetsenabled();
17591764
}
17601765

1766+
if (body.has_tracesamplerate()) {
1767+
out["traceSampleRate"] = body.tracesamplerate();
1768+
}
1769+
17611770
DebugJSON("Reconfigure out: \n%s\n", out);
17621771

17631772
UpdateConfig(out.dump());

agents/grpc/src/proto/reconfigure.pb.cc

Lines changed: 52 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agents/grpc/src/proto/reconfigure.pb.h

Lines changed: 49 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)