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

docs(profiling): add new cont profiling page docs #11376

Merged
merged 16 commits into from
Sep 24, 2024
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: Transaction vs Continuous Profiling
sidebar_order: 140
description: "Continuous and transaction based profiling are two different modes with which you can profile the runtime of your application. This document serves as an explanation as to why we did it and what it enables."
JonasBa marked this conversation as resolved.
Show resolved Hide resolved
---

<Note>
We have released a new profiling mode called continuous profiling mode with fundamental differences from the previous transaction based profiling mode. This document serves as an explanation as to why we did so along with a couple of things that are helpful to know.
</Note>
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

## A bit of historical context first
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

Transaction based profiling was the first profiling mode supported at Sentry, it simply means that any code executed between Sentry.startTransaction and transaction.finish is subject to being profiled. In this mode, all profiles are attached to transactions (and are even sent as part of the same envelope). This has the benefit of automatically profiling parts of the application that are actually instrumented while requiring no extra effort. This approach however has drawback that continuous profiling aims to address, one of the most obvious ones being that profiles cannot exceed 30 second durations.

In theory, transactions can be infinitely long as their duration does not impact payload size as start and end are represented by two timestamps. Profiles however are different, each stack sample that is collected by the profiler increases the payload size, which is why all Sentry SDKs had enforced a max profile duration of 30s. This limitation helps us safeguard from large payload that could otherwise harm your application performance. This unfortunately comes at the expense of limiting profiling capabilities as it means profiling is now no longer able to profile long running tasks like machine learning pipelines or build workflows. This feedback was the major driving force why we've introduced continuous profiling.

The cap on max profile duration is however not the only drawback of transaction based profiling, another limitation of it is that the profiling data you collect, will only ever be as good as the instrumentation you have. In other words, if there are parts of your application that you did not instrument, the chance of you finding out that they are slowing down your application are near zero.

To address these limitations, we have worked on a different profiling mode, one that does not impose constraints on profile durations and can surface parts of your application that might be slowing down your application even though you may not have instrumented them.
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

## Continuous profiling mode

In countinuous profiling mode, the profiler runs continuously (no pun intended) and regularly flushes what we call profile "profile chunks" to the server, this enables us to extend profile durations and continuously profile your application.

Continuous profiling mode is suitable for profiling long running workflows or processes that you want full visibility into, while the transaction based profiling is largely suitable for workflows where you want to limit profiling to only a subset of your application.
JonasBa marked this conversation as resolved.
Show resolved Hide resolved


## SDK differences

Transaction based profiling was opaque from the SDK point of view with the SDK being in full control of when the profiler woulds start and stop based on the transactions it would generate. In continuous profiling mode, this is no longer true. Developers can now control when the profiler is started or stopped via new top level SDK methods. The exact method naming varies, but most SDKs that support continuous profiling now expose a top level Sentry.profiler that exposes a startProfiling and stopProfiling method (please see SDK docs for exact definitions).

It is advisable that you call the startProfiling method right after the Sentry SDK is initialized so that you gain visibility at the earliest point in your application lifecycle. From then on, the profiler will keep collecting profiles and sending chunks to Sentry until stopProfiling is called.
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

## Enabling transaction or continuous profiling mode
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

Unfortunately, it is currently not possible to use both profiling modes at the same time, as they are mutually exlusive. Since the mode you intend on using depend on the SDK initialization arguments, it means that the profiling mode will have to be selected at the time the Sentry SDK is initialized.

To enable continuous profiling mode, you should ensure that neither profileSampleRate or profilesSampler are set as the values to the Sentry.Init call. If either of those value are set, the SDK will default to transaction based profiling. When the SDK is configured for continuous profiling, the top level calls to start profiles will enable calls to the profiler. If the SDK is configured for transaction based profiling, then these calls will void and not trigger the profiler.

Example of enabling continuous profiling in NodeJS
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

```javascript
Sentry.Init({
dsn: "___PUBLIC_DSN___",
integrations: [nodeProfilingIntegration()]
})

Sentry.profiler.startProfiling();
```

If you wish to keep using transaction based profiling, then the options remain the same and you should either set profilesSampleRate or profilesSampler option on the SDK.


Example of enabling transaction based profiling in NodeJS
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

```javascript
Sentry.Init({
dsn: "___PUBLIC_DSN___",
profileSampleRate: 0.1 // profiles 10% of transactions
integrations: [nodeProfilingIntegration()]
})

const transaction = Sentry.startTransaction();
//code executed between these two calls is subject to profiling
transaction.finish();
```

Note that while the profiling mode cannot be changed at runtime, it is fine for different projects or applications to use different profiling modes, or to switch modes.
JonasBa marked this conversation as resolved.
Show resolved Hide resolved

## Differences in product experience

The major difference in product experience when using continuous profiling is that you will be able to visualize a flamegraph for your entire application, which means you can now take a step back from the previous transaction based view and look at your application's runtime as a whole. This makes it easier to for you to prioritize the functions that are slowing down your entire application and not just one particular transaction.

The product experience otherwise remains largely the same with entrypoints into profiling being supported from various parts of the performance product.
JonasBa marked this conversation as resolved.
Show resolved Hide resolved
Loading