Skip to content

Commit 3b20705

Browse files
authored
Merge pull request #5666 from cloudflare/shrima/STOR-3398-3
Add tracing spans for input and output gates for hold and wait
2 parents 03ac4ad + 80aa26a commit 3b20705

16 files changed

+542
-384
lines changed

src/workerd/api/actor-state.c++

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,9 @@ jsg::Promise<void> DurableObjectStorageOperations::setAlarm(
499499
// they want immediate execution.
500500
kj::Date dateNowKjDate = static_cast<int64_t>(dateNow()) * kj::MILLISECONDS + kj::UNIX_EPOCH;
501501

502-
auto maybeBackpressure = transformMaybeBackpressure(
503-
js, options, getCache(OP_PUT_ALARM).setAlarm(kj::max(scheduledTime, dateNowKjDate), options));
502+
auto maybeBackpressure = transformMaybeBackpressure(js, options,
503+
getCache(OP_PUT_ALARM)
504+
.setAlarm(kj::max(scheduledTime, dateNowKjDate), options, context.getCurrentTraceSpan()));
504505

505506
// setAlarm() is billed as a single write unit.
506507
context.addTask(updateStorageWriteUnit(context, currentActorMetrics(), 1));
@@ -515,10 +516,11 @@ jsg::Promise<void> DurableObjectStorageOperations::putOne(
515516

516517
auto units = billingUnits(key.size() + buffer.size());
517518

518-
jsg::Promise<void> maybeBackpressure = transformMaybeBackpressure(
519-
js, options, getCache(OP_PUT).put(kj::mv(key), kj::mv(buffer), options));
520-
521519
auto& context = IoContext::current();
520+
521+
jsg::Promise<void> maybeBackpressure = transformMaybeBackpressure(js, options,
522+
getCache(OP_PUT).put(kj::mv(key), kj::mv(buffer), options, context.getCurrentTraceSpan()));
523+
522524
context.addTask(updateStorageWriteUnit(context, currentActorMetrics(), units));
523525
return maybeBackpressure;
524526
}
@@ -555,8 +557,8 @@ jsg::Promise<void> DurableObjectStorageOperations::deleteAlarm(
555557
}).orDefault(PutOptions{}));
556558

557559
return context.attachSpans(js,
558-
transformMaybeBackpressure(
559-
js, options, getCache(OP_DELETE_ALARM).setAlarm(kj::none, options)),
560+
transformMaybeBackpressure(js, options,
561+
getCache(OP_DELETE_ALARM).setAlarm(kj::none, options, context.getCurrentTraceSpan())),
560562
kj::mv(userSpan));
561563
}
562564

@@ -566,7 +568,7 @@ jsg::Promise<void> DurableObjectStorage::deleteAll(
566568
auto userSpan = context.makeUserTraceSpan("durable_object_storage_deleteAll"_kjc);
567569
auto options = configureOptions(kj::mv(maybeOptions).orDefault(PutOptions{}));
568570

569-
auto deleteAll = cache->deleteAll(options);
571+
auto deleteAll = cache->deleteAll(options, context.getCurrentTraceSpan());
570572

571573
context.addTask(updateStorageDeletes(context, currentActorMetrics(), kj::mv(deleteAll.count)));
572574

@@ -580,8 +582,11 @@ void DurableObjectTransaction::deleteAll() {
580582

581583
jsg::Promise<bool> DurableObjectStorageOperations::deleteOne(
582584
jsg::Lock& js, kj::String key, const PutOptions& options) {
583-
return transformCacheResult(
584-
js, getCache(OP_DELETE).delete_(kj::mv(key), options), options, [](jsg::Lock&, bool value) {
585+
auto& context = IoContext::current();
586+
587+
return transformCacheResult(js,
588+
getCache(OP_DELETE).delete_(kj::mv(key), options, context.getCurrentTraceSpan()), options,
589+
[](jsg::Lock&, bool value) {
585590
currentActorMetrics().addStorageDeletes(1);
586591
return value;
587592
});
@@ -613,10 +618,11 @@ jsg::Promise<void> DurableObjectStorageOperations::putMultiple(
613618
kvs.add(ActorCacheOps::KeyValuePair{kj::mv(field.name), kj::mv(buffer)});
614619
}
615620

616-
jsg::Promise<void> maybeBackpressure =
617-
transformMaybeBackpressure(js, options, getCache(OP_PUT).put(kvs.releaseAsArray(), options));
618-
619621
auto& context = IoContext::current();
622+
623+
jsg::Promise<void> maybeBackpressure = transformMaybeBackpressure(js, options,
624+
getCache(OP_PUT).put(kvs.releaseAsArray(), options, context.getCurrentTraceSpan()));
625+
620626
context.addTask(updateStorageWriteUnit(context, currentActorMetrics(), units));
621627

622628
return maybeBackpressure;
@@ -626,7 +632,10 @@ jsg::Promise<int> DurableObjectStorageOperations::deleteMultiple(
626632
jsg::Lock& js, kj::Array<kj::String> keys, const PutOptions& options) {
627633
auto numKeys = keys.size();
628634

629-
return transformCacheResult(js, getCache(OP_DELETE).delete_(kj::mv(keys), options), options,
635+
auto& context = IoContext::current();
636+
637+
return transformCacheResult(js,
638+
getCache(OP_DELETE).delete_(kj::mv(keys), options, context.getCurrentTraceSpan()), options,
630639
[numKeys](jsg::Lock&, uint count) -> int {
631640
currentActorMetrics().addStorageDeletes(numKeys);
632641
return count;
@@ -743,14 +752,15 @@ jsg::JsRef<jsg::JsValue> DurableObjectStorage::transactionSync(
743752
jsg::Promise<void> DurableObjectStorage::sync(jsg::Lock& js) {
744753
auto& context = IoContext::current();
745754
auto userSpan = context.makeUserTraceSpan("durable_object_storage_sync"_kjc);
746-
KJ_IF_SOME(p, cache->onNoPendingFlush()) {
755+
auto span = context.makeTraceSpan("durable_object_storage_sync"_kjc);
756+
KJ_IF_SOME(p, cache->onNoPendingFlush(span)) {
747757
// Note that we're not actually flushing since that will happen anyway once we go async. We're
748758
// merely checking if we have any pending or in-flight operations, and providing a promise that
749759
// resolves when they succeed. This promise only covers operations that were scheduled before
750760
// this method was invoked. If the cache has to flush again later from future operations, this
751761
// promise will resolve before they complete. If this promise were to reject, then the actor's
752762
// output gate will be broken first and the isolate will not resume synchronous execution.
753-
return context.attachSpans(js, context.awaitIo(js, kj::mv(p)), kj::mv(userSpan));
763+
return context.attachSpans(js, context.awaitIo(js, kj::mv(p)), kj::mv(userSpan), kj::mv(span));
754764
} else {
755765
return js.resolvedPromise();
756766
}

src/workerd/api/global-scope.c++

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ kj::Promise<WorkerInterface::AlarmResult> ServiceWorkerGlobalScope::runAlarm(kj:
438438
}
439439
}
440440

441-
KJ_SWITCH_ONEOF(persistent.armAlarmHandler(scheduledTime, false, actorId)) {
441+
KJ_SWITCH_ONEOF(persistent.armAlarmHandler(
442+
scheduledTime, context.getCurrentTraceSpan(), false, actorId)) {
442443
KJ_CASE_ONEOF(armResult, ActorCacheInterface::RunAlarmHandler) {
443444
auto& handler = KJ_REQUIRE_NONNULL(exportedHandler);
444445
if (handler.alarm == kj::none) {

src/workerd/io/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ wd_cc_library(
271271
hdrs = ["io-gate.h"],
272272
visibility = ["//visibility:public"],
273273
deps = [
274+
":trace",
274275
"@capnp-cpp//src/kj",
275276
"@capnp-cpp//src/kj:kj-async",
276277
],

0 commit comments

Comments
 (0)