opentelemetry-sdk-workers icon indicating copy to clipboard operation
opentelemetry-sdk-workers copied to clipboard

Instrument Durable Objects

Open BraunreutherA opened this issue 1 year ago • 6 comments

Hey there 👋

It would be nice if we can instrument the fetch call to durable objects.

BraunreutherA avatar Aug 16 '22 08:08 BraunreutherA

Like #11, an MVP should be the SDK taking the durable object stub, and returning a wrapper with the same fetch interface that makes sure the trace is propagated. I believe the "receive" end should just work as long as it's a normal fetch handler also.

RichiCoder1 avatar Aug 16 '22 18:08 RichiCoder1

This may be "done" via #21, but I haven't validated.

RichiCoder1 avatar Feb 05 '23 22:02 RichiCoder1

This is likely resolved with 0.6.0, however I'm not sure about the recieving end so keeping this open.

RichiCoder1 avatar Feb 06 '23 22:02 RichiCoder1

I'm afraid this won't work for Durable Objects because of slightly different syntax:

const id = env.DURABLE_OBJ.idFromName('xxx')
const stub = env.DURABLE_OBJ.get(id); // this method will fail with sdk
const response = await stub.fetch(request);

So, we canot just simply have sdk.env.DURABLE_OBJ.fetch or sdk.env.DURABLE_OBJ.get(id).fetch

oxcafedead avatar Apr 03 '23 15:04 oxcafedead

Maybe as an idea, it makes sense to make public methods to create spans so that Durable Object invocation can at least be manually 'wrapped':

sdk.createSpan();
durableObjects.get...fetch();
sdk.endSpan();

oxcafedead avatar Apr 03 '23 15:04 oxcafedead

Ah darn, I thought it had the same syntax. I forgot it stubbed out. It should still be possible to proxy the stub however 🤔.

I could definitely add support for creating spans directly, though it might be a little weird due to the way the SDK currently works. #26 might help make that "just work"

RichiCoder1 avatar Apr 03 '23 15:04 RichiCoder1