sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Instrument the Promise object to create spans

Open AbhiPrasad opened this issue 4 years ago • 2 comments

Let's explore instrumenting the promise object, so we can "auto-instrument" async/await calls.

some thoughts gathered:

you perhaps could use a millisecond boundary to omit instantly resolving promises

Promise is an interesting way of generically capture long running js tasks

if you instrument the promise how do you figure out what’s being called?

AbhiPrasad avatar Nov 11 '21 16:11 AbhiPrasad

On the subject of monkey patching Promise...

How about optionally recording stack traces as they pass through promises to work around "zero-cost async stack traces"?

The number of times I've got almost useless stack traces due to this!

timfish avatar Jul 28 '22 17:07 timfish

@timfish It's great you bring this up - since we've been looking at async stacktraces with https://github.com/getsentry/sentry-javascript/discussions/5334.

If you got some bandwidth, feel free to explore and investigate here, any improvements we can make would be amazing.

AbhiPrasad avatar Jul 28 '22 17:07 AbhiPrasad

It's worth noting that while we can instrument global.Promise, we cannot instrument the internal [[Promise]] that's used for async function.

timfish avatar Jan 25 '23 18:01 timfish