Skip to content

Commit 76fd8be

Browse files
committed
[nfc] Clean up r2GetClient(), removing getHttpClientWithSpans()
It turns out that the getHttpClient variant with trace context parameter is easier to use.
1 parent c766f38 commit 76fd8be

3 files changed

Lines changed: 10 additions & 48 deletions

File tree

src/workerd/api/r2-bucket.c++

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@
2525
namespace workerd::api::public_beta {
2626
kj::Own<kj::HttpClient> r2GetClient(
2727
IoContext& context, uint subrequestChannel, R2UserTracing user) {
28-
kj::Vector<Span::Tag> tags;
29-
tags.add("rpc.service"_kjc, kj::ConstString("r2"_kjc));
30-
tags.add(user.method.key, kj::ConstString(kj::str(user.method.value)));
28+
auto traceSpan = context.makeTraceSpan(user.op);
29+
auto userSpan = context.makeUserTraceSpan(user.op);
30+
TraceContext traceContext(kj::mv(traceSpan), kj::mv(userSpan));
31+
traceContext.userSpan.setTag("rpc.service"_kjc, "r2"_kjc);
32+
traceContext.userSpan.setTag(user.method.key, user.method.value);
3133
KJ_IF_SOME(b, user.bucket) {
32-
tags.add("cloudflare.r2.bucket"_kjc, kj::ConstString(kj::str(b)));
34+
traceContext.userSpan.setTag("cloudflare.r2.bucket"_kjc, b);
3335
}
3436
KJ_IF_SOME(tag, user.extraTag) {
35-
tags.add(tag.key, kj::ConstString(kj::str(tag.value)));
37+
traceContext.userSpan.setTag(tag.key, tag.value);
3638
}
3739

38-
return context.getHttpClientWithSpans(subrequestChannel, true, kj::none, user.op, kj::mv(tags));
40+
// TODO(o11y): Attach trace context to awaitIo call to match operation lifetime better?
41+
return context.getHttpClient(subrequestChannel, true, kj::none, traceContext)
42+
.attach(kj::mv(traceContext));
3943
}
4044

4145
static bool isWholeNumber(double x) {

src/workerd/io/io-context.c++

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -971,26 +971,6 @@ kj::Own<WorkerInterface> IoContext::getSubrequestChannel(
971971
});
972972
}
973973

974-
kj::Own<WorkerInterface> IoContext::getSubrequestChannelWithSpans(uint channel,
975-
bool isInHouse,
976-
kj::Maybe<kj::String> cfBlobJson,
977-
kj::ConstString operationName,
978-
kj::Vector<Span::Tag> tags) {
979-
return getSubrequest(
980-
[&](TraceContext& tracing, IoChannelFactory& channelFactory) {
981-
for (Span::Tag& tag: tags) {
982-
tracing.userSpan.setTag(kj::mv(tag.key), kj::mv(tag.value));
983-
}
984-
return getSubrequestChannelImpl(
985-
channel, isInHouse, kj::mv(cfBlobJson), tracing, channelFactory);
986-
},
987-
SubrequestOptions{
988-
.inHouse = isInHouse,
989-
.wrapMetrics = !isInHouse,
990-
.operationName = kj::mv(operationName),
991-
});
992-
}
993-
994974
kj::Own<WorkerInterface> IoContext::getSubrequestChannelNoChecks(uint channel,
995975
bool isInHouse,
996976
kj::Maybe<kj::String> cfBlobJson,
@@ -1029,15 +1009,6 @@ kj::Own<kj::HttpClient> IoContext::getHttpClient(
10291009
getSubrequestChannel(channel, isInHouse, kj::mv(cfBlobJson), kj::mv(operationName)));
10301010
}
10311011

1032-
kj::Own<kj::HttpClient> IoContext::getHttpClientWithSpans(uint channel,
1033-
bool isInHouse,
1034-
kj::Maybe<kj::String> cfBlobJson,
1035-
kj::ConstString operationName,
1036-
kj::Vector<Span::Tag> tags) {
1037-
return asHttpClient(getSubrequestChannelWithSpans(
1038-
channel, isInHouse, kj::mv(cfBlobJson), kj::mv(operationName), kj::mv(tags)));
1039-
}
1040-
10411012
kj::Own<kj::HttpClient> IoContext::getHttpClient(
10421013
uint channel, bool isInHouse, kj::Maybe<kj::String> cfBlobJson, TraceContext& traceContext) {
10431014
return asHttpClient(getSubrequestChannel(channel, isInHouse, kj::mv(cfBlobJson), traceContext));

src/workerd/io/io-context.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,6 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
855855
kj::Own<WorkerInterface> getSubrequestChannel(
856856
uint channel, bool isInHouse, kj::Maybe<kj::String> cfBlobJson, TraceContext& traceContext);
857857

858-
kj::Own<WorkerInterface> getSubrequestChannelWithSpans(uint channel,
859-
bool isInHouse,
860-
kj::Maybe<kj::String> cfBlobJson,
861-
kj::ConstString operationName,
862-
kj::Vector<Span::Tag> tags);
863-
864858
// Like getSubrequestChannel() but doesn't enforce limits. Use for trusted paths only.
865859
kj::Own<WorkerInterface> getSubrequestChannelNoChecks(uint channel,
866860
bool isInHouse,
@@ -877,13 +871,6 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
877871
kj::Own<kj::HttpClient> getHttpClient(
878872
uint channel, bool isInHouse, kj::Maybe<kj::String> cfBlobJson, TraceContext& traceContext);
879873

880-
// As above, but with list of span tags to add, analogous to getSubrequestChannelWithSpans().
881-
kj::Own<kj::HttpClient> getHttpClientWithSpans(uint channel,
882-
bool isInHouse,
883-
kj::Maybe<kj::String> cfBlobJson,
884-
kj::ConstString operationName,
885-
kj::Vector<Span::Tag> tags);
886-
887874
// Convenience methods that call getSubrequest*() and adapt the returned WorkerInterface objects
888875
// to HttpClient.
889876
kj::Own<kj::HttpClient> getHttpClientNoChecks(uint channel,

0 commit comments

Comments
 (0)