Skip to content

Commit f74bece

Browse files
committed
Add tracing spans for input gate hold
1 parent 8e4431e commit f74bece

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/workerd/io/io-context.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace workerd {
3131
class WorkerTracer;
3232
class BaseTracer;
33+
class Worker;
3334
} // namespace workerd
3435

3536
namespace workerd {
@@ -176,6 +177,14 @@ class IoContext_IncomingRequest final {
176177

177178
SpanParent getCurrentUserTraceSpan();
178179

180+
void startInputGateHoldSpan() {
181+
inputGateHoldSpan = getMetrics().getSpan().newChild("actor_input_gate_hold"_kjc);
182+
}
183+
184+
void stopInputGateHoldSpan() {
185+
inputGateHoldSpan = kj::none;
186+
}
187+
179188
// The invocation span context is a unique identifier for a specific
180189
// worker invocation.
181190
tracing::InvocationSpanContext& getInvocationSpanContext();
@@ -211,6 +220,8 @@ class IoContext_IncomingRequest final {
211220
// Tracks the location where delivered() was called for debugging.
212221
kj::Maybe<kj::SourceLocation> deliveredLocation;
213222

223+
kj::Maybe<SpanBuilder> inputGateHoldSpan;
224+
214225
friend class IoContext;
215226
};
216227

@@ -1141,6 +1152,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
11411152

11421153
friend class Finalizeable;
11431154
friend class DeleteQueue;
1155+
friend class Worker;
11441156
template <typename T>
11451157
friend kj::Promise<ExceptionOr<T>> promiseForExceptionOrT(kj::Promise<T> promise);
11461158
template <typename Result>

src/workerd/io/worker.c++

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,9 +3441,15 @@ struct Worker::Actor::Impl {
34413441

34423442
void inputGateLocked() override {
34433443
metrics.inputGateLocked();
3444+
KJ_IF_SOME(ctx, getIoContext()) {
3445+
ctx.getCurrentIncomingRequest().startInputGateHoldSpan();
3446+
}
34443447
}
34453448
void inputGateReleased() override {
34463449
metrics.inputGateReleased();
3450+
KJ_IF_SOME(ctx, getIoContext()) {
3451+
ctx.getCurrentIncomingRequest().stopInputGateHoldSpan();
3452+
}
34473453
}
34483454
void inputGateWaiterAdded() override {
34493455
metrics.inputGateWaiterAdded();
@@ -3490,12 +3496,17 @@ struct Worker::Actor::Impl {
34903496
metrics.storageWriteCompleted(latency);
34913497
}
34923498

3499+
void setIoContext(IoContext& ctx) { ioContext = ctx; }
3500+
kj::Maybe<IoContext&> getIoContext() { return ioContext; }
3501+
34933502
private:
34943503
kj::Own<Loopback> loopback; // only for updateAlarmInMemory()
34953504
TimerChannel& timerChannel; // only for afterLimitTimeout() and updateAlarmInMemory()
34963505
ActorObserver& metrics;
34973506

34983507
kj::Maybe<kj::Promise<void>> maybeAlarmPreviewTask;
3508+
3509+
kj::Maybe<IoContext&> ioContext = kj::none;
34993510
};
35003511

35013512
HooksImpl hooks;
@@ -4053,6 +4064,7 @@ void Worker::Actor::setIoContext(kj::Own<IoContext> context) {
40534064
impl->abortFulfiller = kj::none;
40544065
}
40554066
auto& limitEnforcer = context->getLimitEnforcer();
4067+
impl->hooks.setIoContext(*context);
40564068
impl->ioContext = kj::mv(context);
40574069
impl->metricsFlushLoopTask =
40584070
impl->metrics->flushLoop(impl->timerChannel, limitEnforcer)

0 commit comments

Comments
 (0)