Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agents/grpc/proto/reconfigure.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ message ReconfigureBody {
optional uint32 tracingModulesBlacklist = 11;
optional bool contCpuProfile = 12;
optional bool assetsEnabled = 13;
optional double traceSampleRate = 14;
}

message ReconfigureEvent {
Expand Down
4 changes: 4 additions & 0 deletions agents/grpc/src/grpc_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,10 @@ void GrpcAgent::reconfigure(const grpcagent::CommandRequest& request) {
out["assetsEnabled"] = body.assetsenabled();
}

if (body.has_tracesamplerate()) {
out["traceSampleRate"] = body.tracesamplerate();
}
Comment on lines +1761 to +1763
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

traceSampleRate is accepted but not returned in reconfigure event body.

Lines 1761-1763 map inbound updates, but PopulateReconfigureEvent does not set body.traceSampleRate. This makes reconfigure responses incomplete even when the update is applied.

💡 Suggested fix
diff --git a/agents/grpc/src/grpc_agent.cc b/agents/grpc/src/grpc_agent.cc
@@ void PopulateReconfigureEvent(grpcagent::ReconfigureEvent* reconfigure_event,
   it = config.find("assetsEnabled");
   if (it != config.end()) {
     body->set_assetsenabled(*it);
   }
+  it = config.find("traceSampleRate");
+  if (it != config.end()) {
+    body->set_tracesamplerate(*it);
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@agents/grpc/src/grpc_agent.cc` around lines 1761 - 1763,
PopulateReconfigureEvent currently omits the traceSampleRate field when building
the outgoing reconfigure event body; update PopulateReconfigureEvent to set
body.traceSampleRate from the internal config so the outgoing event mirrors
inbound updates (i.e., when you previously read body.tracesamplerate() on
incoming updates, ensure PopulateReconfigureEvent calls the corresponding setter
to populate body.traceSampleRate in the event). Locate the
PopulateReconfigureEvent function in grpc_agent.cc and add the traceSampleRate
assignment using the same source/field used for other mapped settings so
reconfigure responses include traceSampleRate.


DebugJSON("Reconfigure out: \n%s\n", out);

UpdateConfig(out.dump());
Expand Down
83 changes: 52 additions & 31 deletions agents/grpc/src/proto/reconfigure.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 49 additions & 7 deletions agents/grpc/src/proto/reconfigure.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions lib/internal/otel/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
JSONStringify,
MathRandom,
SafeMap,
Uint8Array,
} = primordials;
Expand Down Expand Up @@ -278,10 +279,14 @@ class Tracer {
}

const internalId = newInternalSpanId();
// Follow parent, root always sampled.
let flags = api.TraceFlags.SAMPLED;
if (parentContext)
// Root spans make the sampling decision, child spans inherit parent flags.
let flags;
if (!parentContext) {
const sampled = MathRandom() < binding.trace_sample_rate[0];
flags = sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE;
} else {
flags = parentContext.traceFlags;
}
const spanContext = new SpanContext(internalId,
spanId,
flags,
Expand Down
Loading
Loading