Skip to content

First pass at instrumenting kv.list #4361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jmorrell-cloudflare
Copy link
Collaborator

@jmorrell-cloudflare jmorrell-cloudflare commented Jun 17, 2025

Note: depends on merging #4356 first

  • Modifies some of the plumbing around getting an HTTP client so that TraceContext can be passed along, and modifies kv.list to use the new path.
  • Adds more attributes for kv.list plus tests

@jmorrell-cloudflare jmorrell-cloudflare requested review from a team as code owners June 17, 2025 23:37
});
}

constexpr auto FLPROD_405_HEADER = "CF-KV-FLPROD-405"_kj;

kj::Own<kj::HttpClient> KvNamespace::getHttpClient(IoContext& context,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other KvNamespace::getHttpClient creates spans for every method all at once. This works only if you do not want to introspect the response or capture errors during execution.

This implementation allows us more flexibility with instrumentation. I will move each KV method over to it as I instrument them and then delete the other.

Base automatically changed from jmorrell/kv-instrumentation-1 to main June 18, 2025 00:37
@jmorrell-cloudflare jmorrell-cloudflare force-pushed the jmorrell/kv-instrumentation-2 branch 2 times, most recently from d484a38 to b71234d Compare June 18, 2025 15:38
url.query.add(kj::Url::QueryParam{kj::str("prefix"), kj::str(prefix)});
}
}
KJ_IF_SOME(maybeCursor, o.cursor) {
KJ_IF_SOME(cursor, maybeCursor) {
traceContext.userSpan.setTag("cloudflare.kv.query.cursor"_kjc, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this overlap with the existing cloudflare.kv.query.parameter.cursor tag? Same applies for some related tags.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment. The existing code trying to add all the instrumentation code in one place is less flexible given that it cannot observe anything about the response. The idea is to lift all of the instrumentation to live alongside the code it instruments.

auto userSpan = context.makeUserTraceSpan("kv.list"_kjc);
TraceContext traceContext(kj::mv(traceSpan), kj::mv(userSpan));

traceContext.userSpan.setTag("db.system"_kjc, kj::str("cloudflare.kv"_kjc));
Copy link
Contributor

@fhanau fhanau Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be set within list itself – see the existing getHttpClient(), where we set this attribute for a number of operations at once.
The value of the tag is not matching what we have there (cloudflare.kv vs. cloudflare-kv, for the operation name we have kv.list vs. kv_list)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this modifies the existing instrumentation and extends it quite a bit: https://wiki.cfdata.org/display/WOBS/June+2025%3A+Next+steps+for+Runtime+Instrumentation

There are no dependencies on this existing instrumentation that I'm aware of. Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming scheme should always be consistent, everything else is likely to cause confusion, especially when renaming things gets forgotten until code is used in production. I'm not opposed to changing the naming scheme per se, but this should be done for all KV operations, in a commit or PR either before or after adding new tags. Everything else is difficult to review.
We also need to be mindful of keeping a consistent source of truth for this – both the old source of truth and the new document you added use db.system:cloudflare-kv, the tag implementation needs to be consistent with its specification.


traceContext.userSpan.setTag("db.system"_kjc, kj::str("cloudflare.kv"_kjc));
traceContext.userSpan.setTag("db.operation.name"_kjc, kj::str("list"_kjc));
traceContext.userSpan.setTag("cloudflare.binding_type"_kjc, kj::str("KV"_kjc));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this we'd want to have it for each binding, right? Not opposed to adding it per se, but that's something that should be discussed internally first so that we agree that it's needed/what the right tag name is, and it should be added across bindings in a different change set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm certainly open to renaming it, but we absolutely want some equivalent of this attribute for all of our bindings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that this is a KV instrumentation PR – adding "global" tags is out of scope here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants