Skip to content

Commit f239f2d

Browse files
authored
Merge pull request #5498 from cloudflare/jmp/getCurrentBookmark-traces
Add tracing for `DurableObjectStorage::getCurrentBookmark()`
2 parents 3d93e23 + 903f530 commit f239f2d

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

.github/workflows/_bazel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
# dependencies of header targets properly).
130130
if: inputs.parse_headers
131131
run: |
132-
bazel build --config=parse_headers --remote_cache=https://bazel:${{ secrets.BAZEL_CACHE_KEY }}@bazel-remote-cache.devprod.cloudflare.dev --config=ci ${{ inputs.extra_bazel_args }} //src/workerd/util //src/workerd/io:actor
132+
bazel build --config=parse_headers --remote_cache=https://bazel:${{ secrets.BAZEL_CACHE_KEY }}@bazel-remote-cache.devprod.cloudflare.dev --config=ci ${{ inputs.extra_bazel_args }} //src/workerd/util
133133
- name: Upload test logs
134134
if: inputs.upload_test_logs
135135
uses: actions/upload-artifact@v4

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,10 @@ jsg::Ref<SyncKvStorage> DurableObjectStorage::getKv(jsg::Lock& js) {
839839
}
840840

841841
kj::Promise<kj::String> DurableObjectStorage::getCurrentBookmark() {
842-
return cache->getCurrentBookmark();
842+
auto& context = IoContext::current();
843+
auto span = context.makeTraceSpan("durable_object_storage_getCurrentBookmark"_kjc);
844+
845+
return cache->getCurrentBookmark(span).attach(kj::mv(span));
843846
}
844847

845848
kj::Promise<kj::String> DurableObjectStorage::getBookmarkForTime(kj::Date timestamp) {

src/workerd/io/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,11 @@ wd_cc_library(
199199
"actor-sqlite.h",
200200
"actor-storage.h",
201201
],
202-
implementation_deps = [
203-
"@sqlite3",
204-
],
205202
visibility = ["//visibility:public"],
206203
deps = [
207204
":actor-storage_capnp",
208205
":io-gate",
206+
":trace",
209207
"//src/workerd/jsg:exception",
210208
"//src/workerd/util:autogate",
211209
"//src/workerd/util:duration-exceeded-logger",

src/workerd/io/actor-cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <workerd/io/actor-storage.capnp.h>
8+
#include <workerd/io/trace.h>
89
#include <workerd/jsg/exception.h>
910

1011
#include <kj/async.h>
@@ -242,7 +243,7 @@ class ActorCacheInterface: public ActorCacheOps {
242243

243244
// Implements the respective PITR API calls. The default implementations throw JSG errors saying
244245
// PITR is not implemented. These methods are meant to be implemented internally.
245-
virtual kj::Promise<kj::String> getCurrentBookmark() {
246+
virtual kj::Promise<kj::String> getCurrentBookmark(SpanParent parentSpan) {
246247
JSG_FAIL_REQUIRE(
247248
Error, "This Durable Object's storage back-end does not implement point-in-time recovery.");
248249
}

src/workerd/io/actor-sqlite.c++

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <workerd/util/autogate.h>
1111
#include <workerd/util/sentry.h>
1212

13-
#include <sqlite3.h>
14-
1513
#include <kj/exception.h>
1614
#include <kj/function.h>
1715

@@ -826,7 +824,7 @@ kj::Maybe<kj::Promise<void>> ActorSqlite::onNoPendingFlush() {
826824
return kj::joinPromisesFailFast(kj::arr(lastCommit.addBranch(), outputGate.wait()));
827825
}
828826

829-
kj::Promise<kj::String> ActorSqlite::getCurrentBookmark() {
827+
kj::Promise<kj::String> ActorSqlite::getCurrentBookmark(SpanParent parentSpan) {
830828
// This is an ersatz implementation that's good enough for local dev with D1's Session API.
831829
//
832830
// The returned bookmark satisfies the properties that D1 cares about:
@@ -873,6 +871,10 @@ kj::Promise<void> ActorSqlite::waitForBookmark(kj::StringPtr bookmark) {
873871
void ActorSqlite::TxnCommitRegulator::onError(
874872
kj::Maybe<int> sqliteErrorCode, kj::StringPtr message) const {
875873
KJ_IF_SOME(c, sqliteErrorCode) {
874+
// We cannot `#include <sqlite3.h>` in the same compilation unit as `#include
875+
// <workerd/io/trace.h>` because the latter includes v8 and v8 seems to conflict with sqlite.
876+
// So we copy the value of SQLITE_CONSTRAINT from sqlite3.h
877+
constexpr int SQLITE_CONSTRAINT = 19;
876878
if (c == SQLITE_CONSTRAINT) {
877879
JSG_ASSERT(false, Error,
878880
"Durable Object was reset and rolled back to its last known good state because the "

src/workerd/io/actor-sqlite.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "actor-cache.h"
88

9+
#include <workerd/io/trace.h>
910
#include <workerd/util/sqlite-kv.h>
1011
#include <workerd/util/sqlite-metadata.h>
1112

@@ -92,7 +93,7 @@ class ActorSqlite final: public ActorCacheInterface, private kj::TaskSet::ErrorH
9293
kj::Date scheduledTime, bool noCache = false, kj::StringPtr actorId = "") override;
9394
void cancelDeferredAlarmDeletion() override;
9495
kj::Maybe<kj::Promise<void>> onNoPendingFlush() override;
95-
kj::Promise<kj::String> getCurrentBookmark() override;
96+
kj::Promise<kj::String> getCurrentBookmark(SpanParent parentSpan) override;
9697
kj::Promise<void> waitForBookmark(kj::StringPtr bookmark) override;
9798
// See ActorCacheInterface
9899

0 commit comments

Comments
 (0)