-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(cloudflare): export the init method #17657
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
Conversation
Signed-off-by: Marc MacLeod <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @marbemac thanks for opening this PR! Before we merge this, can you elaborate a bit on your use case? The reason I'm a bit hesitant still is because afaik the SDK must be initialized in each request handler (as opposed to once globally like in Node or other platforms). Though admittedly my knowledge on Cloudflare is a bit limited. I asked some other team members to take a look as well.
Sure - tldr I am initializing the sdk on every request (this is why I needed access to the init method :)).
const { callTraceableRPC, continueTraceableRPC } = makeTraceableRPCHelpers({ serviceName: 'MyDurableObject' });
export { callTraceableRPC };
export class MyDurableObject extends DurableObject<Env> {
async sayHello(props: WithTrace<ExampleProps>) {
return continueTraceableRPC('sayHello', this.#sayHello, this.ctx.waitUntil.bind(this.ctx), props);
}
#sayHello = async (_: ExampleProps) => {
return { hello: 'from durable object' };
};
}
https://github.com/marbemac/cloudflare-sentry-effect-tracing/blob/main/worker/router.ts#L126-L128 const stub = env.MY_DURABLE_OBJECT.getByName('xyz');
const res = await callTraceableRPC(stub, 'sayHello'); It's all nice and type safe, and you can't do things like accidentally call a durable object method w |
In general if this is a pattern you guys think could be interesting as first class in sentry sdk, I can certainly clean it up and open a PR. It's just overall a little awkward to get the DO rpc calls instrumented correctly - I'm sure there are many ways, so I wasn't sure if this kind of thing belonged in the sdk itself. |
Thanks for outlining! IMHO we should, instead of exporting
I guess the tricky part is that the RPC consumer apparently has to forward the trace data to the RPC method, so we likely need a counter part here as well. Before we do any of this, I'll tag @AbhiPrasad, @s1gr1d and @andreiborza -- thoughts? (if anyone of you thinks we should rather go with exporting Last thought: I'm wondering if there's a lower-level primitive we could instrument for trace propagation/continuation on DOs so that this is taken care of for requests in general. |
This is mostly about continuing the trace, right? In your code example, the We could get the needed SDK users would need to call it like this (with const { ['sentry-trace']: sentryTrace, baggage } = Sentry.getTraceData();
await stub.sayHello({ name: 'World', trace: { sentryTrace, baggage } }); |
Hi folks - yes that's exactly what this util is doing - https://github.com/marbemac/cloudflare-sentry-effect-tracing/blob/main/worker/rpc-tracing-helpers.ts. It returns a type safe |
Hey @marbemac thanks for sticking with us! We discussed this internally and decided that for the time being, we'll not export the However, if you're still up for it, we'd happily review a PR that enables wrapping RPC calls (on both ends) similarly to what you showed us in https://github.com/marbemac/cloudflare-sentry-effect-tracing/blob/main/worker/rpc-tracing-helpers.ts. Some thoughts around this:
Again, thanks for contributing and for starting the conversation! |
Np! Using a patch file for the moment, and the patch is tiny (just adding that init to the index export), so should do fine for us for a while. Adding to my todo list - can't promise anything but I'd love to help out here. |
Agree on this btw - we already have some extra stuff in our version that handles things like serializing exceptions over the rpc call (for cases where the exception reporter is in the worker making the call to the DO - like in router middleware). otherwise things like the original stack trace get lost |
I'm creating little helpers to handle trace propagation on regular durable object rpc calls. To do this I needed access to the
init
method to initialize a new sdk instance (just like sentry/cloudflare does for the methods it auto-instruments). So, if you guys are open to it, hoping to get access to the init method.Example of how I'm using it here -> https://github.com/marbemac/cloudflare-sentry-effect-tracing/blob/main/worker/rpc-tracing-helpers.ts#L112.