getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.87k stars 1.55k forks source link

[Profiling] Add Continuous Profiling mode #12330

Open JonasBa opened 3 months ago

JonasBa commented 3 months ago

Problem Statement

We want to decouple profiles from the current transaction model and expose a way for users to profile code that is longer than 30s (current max profile duration )

Solution Brainstorm

Introduce a continuous profiling mode.

The continuous profiling mode is exclusive from the current profiling mode. We want to allow developers to start and stop the profiler as they please, yielding full control over what is profiled. The current API design docs are here and have not been finalized.

An implementation details of the continuous profiling mode is that each span that is started during a profiling session has a profile context that includes the thread id, name and the profiler id that was currently active (we need this so we can stitch back the profile chunks back together.

Fwiw, the product is currently not handling this yet as we do not have a way to visualize continuous profiles yet. The plan is to implement the functionality and keep it hidden while we work on the in-product support for this.

kennethtruong commented 1 month ago

Before Continuous Profiling gets added, does Sentry allow programmatically creating a Profile? i.e if a User clicks on a button in our application would we be able to create a Profile that tracks what happens for the next 5 seconds?

JonasBa commented 1 month ago

@kennethtruong we do, but since profiles are currently tied to the transaction model, it means you need to start a span and then take care of stopping it at some point in time. You should be able to do this using inactive spans and then calling span.end() using a timeout.

kennethtruong commented 1 month ago

@kennethtruong we do, but since profiles are currently tied to the transaction model, it means you need to start a span and then take care of stopping it at some point in time. You should be able to do this using inactive spans and then calling span.end() using a timeout.

Ah nice let me try that out! Thank you