Skip to content

Commit 1bf2f83

Browse files
committed
Add tracing spans for input and output gates hold and wait
1 parent 8e4431e commit 1bf2f83

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ archive_override(
8181
)
8282

8383
include("//build/deps:deps.MODULE.bazel")
84+
8485
include("//build/deps:nodejs.MODULE.bazel")
86+
8587
include("//build/deps:python.MODULE.bazel")
88+
8689
include("//build/deps:v8.MODULE.bazel")

src/workerd/io/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ wd_cc_library(
268268
hdrs = ["io-gate.h"],
269269
visibility = ["//visibility:public"],
270270
deps = [
271+
":trace",
271272
"@capnp-cpp//src/kj",
272273
"@capnp-cpp//src/kj:kj-async",
273274
],

src/workerd/io/io-gate.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
// to the application are still being flushed to disk. If the flush fails, these messages will
2121
// never be sent, so that the rest of the world cannot observe a prematurely-confirmed write.
2222

23+
#include <workerd/io/trace.h>
24+
2325
#include <kj/async.h>
2426
#include <kj/list.h>
2527
#include <kj/one-of.h>
@@ -50,6 +52,10 @@ class InputGate {
5052
virtual void inputGateWaiterRemoved() {}
5153

5254
static const Hooks DEFAULT;
55+
56+
protected:
57+
kj::Maybe<SpanBuilder> inputGateWaitSpan;
58+
kj::Maybe<SpanBuilder> inputGateHoldSpan;
5359
};
5460

5561
// Hooks has no member variables, so const_cast is acceptable.
@@ -245,6 +251,10 @@ class OutputGate {
245251
virtual void outputGateWaiterRemoved() {}
246252

247253
static const Hooks DEFAULT;
254+
255+
protected:
256+
kj::Maybe<SpanBuilder> outputGateWaitSpan;
257+
kj::Maybe<SpanBuilder> outputGateHoldSpan;
248258
};
249259

250260
// Hooks has no member variables, so const_cast is acceptable.

src/workerd/io/worker.c++

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://opensource.org/licenses/Apache-2.0
44

55
#include "actor-cache.h"
6+
#include "workerd/io/io-gate.h"
67

78
#include <workerd/api/actor-state.h>
89
#include <workerd/api/global-scope.h>
@@ -3441,15 +3442,25 @@ struct Worker::Actor::Impl {
34413442

34423443
void inputGateLocked() override {
34433444
metrics.inputGateLocked();
3445+
if (IoContext::hasCurrent()) {
3446+
auto& ioContext = IoContext::current();
3447+
inputGateHoldSpan = ioContext.makeTraceSpan("actor_input_gate_hold"_kjc);
3448+
}
34443449
}
34453450
void inputGateReleased() override {
34463451
metrics.inputGateReleased();
3452+
inputGateHoldSpan = kj::none;
34473453
}
34483454
void inputGateWaiterAdded() override {
34493455
metrics.inputGateWaiterAdded();
3456+
if (IoContext::hasCurrent()) {
3457+
auto& ioContext = IoContext::current();
3458+
inputGateWaitSpan = ioContext.makeTraceSpan("actor_input_gate_wait"_kjc);
3459+
}
34503460
}
34513461
void inputGateWaiterRemoved() override {
34523462
metrics.inputGateWaiterRemoved();
3463+
inputGateWaitSpan = kj::none;
34533464
}
34543465
// Implements InputGate::Hooks.
34553466

@@ -3469,15 +3480,25 @@ struct Worker::Actor::Impl {
34693480

34703481
void outputGateLocked() override {
34713482
metrics.outputGateLocked();
3483+
if (IoContext::hasCurrent()) {
3484+
auto& ioContext = IoContext::current();
3485+
outputGateHoldSpan = ioContext.makeTraceSpan("actor_output_gate_hold"_kjc);
3486+
}
34723487
}
34733488
void outputGateReleased() override {
34743489
metrics.outputGateReleased();
3490+
outputGateHoldSpan = kj::none;
34753491
}
34763492
void outputGateWaiterAdded() override {
34773493
metrics.outputGateWaiterAdded();
3494+
if (IoContext::hasCurrent()) {
3495+
auto& ioContext = IoContext::current();
3496+
outputGateWaitSpan = ioContext.makeTraceSpan("actor_output_gate_wait"_kjc);
3497+
}
34783498
}
34793499
void outputGateWaiterRemoved() override {
34803500
metrics.outputGateWaiterRemoved();
3501+
outputGateWaitSpan = kj::none;
34813502
}
34823503

34833504
// Implements ActorCache::Hooks

0 commit comments

Comments
 (0)