Skip to content
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

JSRPC: Fill in trace (tail) events better. #1895

Merged
merged 2 commits into from
Mar 27, 2024
Merged

Conversation

kentonv
Copy link
Member

@kentonv kentonv commented Mar 26, 2024

eventInfo was being left null, causing wrangler tail not to report the event at all. Let's fill it in and specify the top-level method name.

Also added entrypoint name, which seems highly relevant to JSRPC.

@kentonv kentonv requested a review from jclee March 26, 2024 02:14
@kentonv kentonv requested review from a team as code owners March 26, 2024 02:14
@kentonv kentonv requested review from dom96 and hoodmane March 26, 2024 02:14

// We call this `rpcMethod` to make clear this is an RPC event, since some tail workers rely
// on duck-typing EventInfo based on the properties present. (`methodName` might be ambiguous
// since HTTP also has methods.)
Copy link
Contributor

Choose a reason for hiding this comment

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

From the comment, I assume that if it weren't for these details of tail workers or the JS API, we'd prefer to call the property methodName as elsewhere in the code, such that it isn't worth propagating the rpcMethod name to the analogous Trace::JsRpcEventInfo::methodName field or beyond.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I had written all the code before I realized that the tail worker distinguishes event types based on what properties are present. At that point I decided only to change the JS API. The other places could be renamed in the future without breaking any kind of compatibility, but I think they are fine as-is.


switch (callParams.which()) {
case rpc::JsRpcTarget::CallParams::METHOD_NAME: {
kj::StringPtr methodName = callParams.getMethodName();
result = getProperty(methodName);
methodNameForErrors = methodName;
methodNameForTrace = methodName.attach();
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly, this StringPtr::attach() call produces a ConstString that does not own its own memory, but instead relies on the caller to keep callParams alive.

...which I assume is OK, since the only caller of tryGetProperty() uses the returned methodNameForTrace value synchronously in the same scope as the passed params value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right.

EmailEventInfo, TraceEventInfo, HibernatableWebSocketEventInfo, CustomEventInfo> EventInfo;
typedef kj::OneOf<FetchEventInfo, JsRpcEventInfo, ScheduledEventInfo, AlarmEventInfo,
QueueEventInfo, EmailEventInfo, TraceEventInfo, HibernatableWebSocketEventInfo,
CustomEventInfo> EventInfo;
kj::Maybe<EventInfo> eventInfo;
// TODO(someday): Support more event types.
Copy link
Contributor

Choose a reason for hiding this comment

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

Heh... Guess we can remove this comment, since we now support lots of event types.

@kentonv kentonv force-pushed the kenton/jsrpc-tracing branch 2 times, most recently from 1386762 to d0dd6d4 Compare March 27, 2024 17:54
eventInfo was being left null, causing wrangler tail not to report the event at all. Let's fill it in and specify the top-level method name.
Well, this isn't really specific to JSRPC, but JSRPC will use named entrypoints more.
@kentonv kentonv merged commit 7e6f215 into main Mar 27, 2024
10 checks passed
@kentonv kentonv deleted the kenton/jsrpc-tracing branch March 27, 2024 18:55
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.

None yet

2 participants