Skip to content

Commit

Permalink
[o11y] Expand user tracing span tags
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanau committed Sep 27, 2024
1 parent 8af02a4 commit 9301352
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/workerd/api/kv.c++
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ kj::Own<kj::HttpClient> KvNamespace::getHttpClient(IoContext& context,
KJ_UNREACHABLE;
}();

auto client = context.getHttpClient(subrequestChannel, true, kj::none, operationName);
auto client = context.getHttpClientSpans(
subrequestChannel, true, kj::none, operationName, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("db.system"_kjc, kj::str("cloudflare-kv"_kj));
});
headers.add(FLPROD_405_HEADER, urlStr);
for (const auto& header: additionalHeaders) {
headers.add(header.name.asPtr(), header.value.asPtr());
Expand Down
20 changes: 17 additions & 3 deletions src/workerd/api/r2-admin.c++
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ jsg::Ref<R2Bucket> R2Admin::get(jsg::Lock& js, kj::String bucketName) {
jsg::Promise<jsg::Ref<R2Bucket>> R2Admin::create(
jsg::Lock& js, kj::String name, const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
auto& context = IoContext::current();
auto client = context.getHttpClient(subrequestChannel, true, kj::none, "r2_delete"_kjc);
auto client = context.getHttpClientSpans(
subrequestChannel, true, kj::none, "r2_create"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("CreateBucket"_kj));
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(name));
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -57,7 +62,11 @@ jsg::Promise<R2Admin::ListResult> R2Admin::list(jsg::Lock& js,
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType,
CompatibilityFlags::Reader flags) {
auto& context = IoContext::current();
auto client = context.getHttpClient(subrequestChannel, true, kj::none, "r2_delete"_kjc);
auto client = context.getHttpClientSpans(
subrequestChannel, true, kj::none, "r2_list"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("ListObjects"_kj));
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -113,7 +122,12 @@ jsg::Promise<R2Admin::ListResult> R2Admin::list(jsg::Lock& js,
jsg::Promise<void> R2Admin::delete_(
jsg::Lock& js, kj::String name, const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
auto& context = IoContext::current();
auto client = context.getHttpClient(subrequestChannel, true, kj::none, "r2_delete"_kjc);
auto client = context.getHttpClientSpans(
subrequestChannel, true, kj::none, "r2_delete"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("DeleteBucket"_kj));
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(name));
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down
66 changes: 59 additions & 7 deletions src/workerd/api/r2-bucket.c++
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,15 @@ jsg::Promise<kj::Maybe<jsg::Ref<R2Bucket::HeadResult>>> R2Bucket::head(jsg::Lock
return js.evalNow([&] {
auto& context = IoContext::current();

auto client = context.getHttpClient(clientIndex, true, kj::none, "r2_get"_kjc);
auto client = context.getHttpClientSpans(
clientIndex, true, kj::none, "r2_get"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("GetObject"_kj));
tracing.limeSpan.setTag("cloudflare.r2.key"_kjc, kj::str(name));
KJ_IF_SOME(b, this->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -345,7 +353,15 @@ R2Bucket::get(jsg::Lock& js,
return js.evalNow([&] {
auto& context = IoContext::current();

auto client = context.getHttpClient(clientIndex, true, kj::none, "r2_get"_kjc);
auto client = context.getHttpClientSpans(
clientIndex, true, kj::none, "r2_get"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("GetObject"_kj));
tracing.limeSpan.setTag("cloudflare.r2.key"_kjc, kj::str(name));
KJ_IF_SOME(b, this->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -407,7 +423,15 @@ jsg::Promise<kj::Maybe<jsg::Ref<R2Bucket::HeadResult>>> R2Bucket::put(jsg::Lock&
});

auto& context = IoContext::current();
auto client = context.getHttpClient(clientIndex, true, kj::none, "r2_put"_kjc);
auto client = context.getHttpClientSpans(
clientIndex, true, kj::none, "r2_put"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("PutObject"_kj));
tracing.limeSpan.setTag("cloudflare.r2.key"_kjc, kj::str(name));
KJ_IF_SOME(b, this->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -593,8 +617,14 @@ jsg::Promise<jsg::Ref<R2MultipartUpload>> R2Bucket::createMultipartUpload(jsg::L
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
return js.evalNow([&] {
auto& context = IoContext::current();
auto client =
context.getHttpClient(clientIndex, true, kj::none, "r2_createMultipartUpload"_kjc);
auto client = context.getHttpClientSpans(
clientIndex, true, kj::none, "r2_createMultipartUpload"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("CreateMultipartUpload"_kj));
KJ_IF_SOME(b, adminBucket) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -687,7 +717,22 @@ jsg::Promise<void> R2Bucket::delete_(jsg::Lock& js,
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
return js.evalNow([&] {
auto& context = IoContext::current();
auto client = context.getHttpClient(clientIndex, true, kj::none, "r2_delete"_kjc);
auto client = context.getHttpClientSpans(
clientIndex, true, kj::none, "r2_delete"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("DeleteObject"_kj));
KJ_SWITCH_ONEOF(keys) {
KJ_CASE_ONEOF(ks, kj::Array<kj::String>) {
tracing.limeSpan.setTag("cloudflare.r2.delete"_kjc, kj::str(ks));
}
KJ_CASE_ONEOF(k, kj::String) {
tracing.limeSpan.setTag("cloudflare.r2.delete"_kjc, kj::str(k));
}
}
KJ_IF_SOME(b, this->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -732,7 +777,14 @@ jsg::Promise<R2Bucket::ListResult> R2Bucket::list(jsg::Lock& js,
CompatibilityFlags::Reader flags) {
return js.evalNow([&] {
auto& context = IoContext::current();
auto client = context.getHttpClient(clientIndex, true, kj::none, "r2_list"_kjc);
auto client = context.getHttpClientSpans(
clientIndex, true, kj::none, "r2_list"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("ListObjects"_kj));
KJ_IF_SOME(b, this->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down
33 changes: 27 additions & 6 deletions src/workerd/api/r2-multipart.c++
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ jsg::Promise<R2MultipartUpload::UploadedPart> R2MultipartUpload::uploadPart(jsg:
"Part number must be between 1 and 10000 (inclusive). Actual value was: ", partNumber);

auto& context = IoContext::current();
auto client =
context.getHttpClient(this->bucket->clientIndex, true, kj::none, "r2_uploadPart"_kjc);
auto client = context.getHttpClientSpans(
this->bucket->clientIndex, true, kj::none, "r2_uploadPart"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("UploadPart"_kj));
tracing.limeSpan.setTag("cloudflare.r2.upload_id"_kjc, kj::str(uploadId));
KJ_IF_SOME(b, this->bucket->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -75,8 +82,15 @@ jsg::Promise<jsg::Ref<R2Bucket::HeadResult>> R2MultipartUpload::complete(jsg::Lo
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
return js.evalNow([&] {
auto& context = IoContext::current();
auto client = context.getHttpClient(
this->bucket->clientIndex, true, kj::none, "r2_completeMultipartUpload"_kjc);
auto client = context.getHttpClientSpans(this->bucket->clientIndex, true, kj::none,
"r2_completeMultipartUpload"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("CompleteMultipartUpload"_kj));
tracing.limeSpan.setTag("cloudflare.r2.upload_id"_kjc, kj::str(uploadId));
KJ_IF_SOME(b, this->bucket->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down Expand Up @@ -125,8 +139,15 @@ jsg::Promise<void> R2MultipartUpload::abort(
jsg::Lock& js, const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
return js.evalNow([&] {
auto& context = IoContext::current();
auto client = context.getHttpClient(
this->bucket->clientIndex, true, kj::none, "r2_abortMultipartUpload"_kjc);
auto client = context.getHttpClientSpans(this->bucket->clientIndex, true, kj::none,
"r2_abortMultipartUpload"_kjc, [&](TraceContext& tracing) {
tracing.limeSpan.setTag("rpc.service"_kjc, kj::str("r2"_kj));
tracing.limeSpan.setTag("rpc.method"_kjc, kj::str("AbortMultipartUpload"_kj));
tracing.limeSpan.setTag("cloudflare.r2.upload_id"_kjc, kj::str(uploadId));
KJ_IF_SOME(b, this->bucket->adminBucketName()) {
tracing.limeSpan.setTag("cloudflare.r2.bucket"_kjc, kj::str(b));
}
});

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand Down

0 comments on commit 9301352

Please sign in to comment.