|
| 1 | + |
| 2 | +### Enabling Trace Lifecycle Profiling |
| 3 | + |
| 4 | +To enable trace profiling, set the lifecycle to `TRACE`. Trace profiling requires tracing to be enabled. |
| 5 | + |
| 6 | +Check out the <PlatformLink to="/tracing/">tracing setup documentation</PlatformLink> for more detailed information on how to configure sampling. Setting the sample rate to 1.0 means all transactions will be captured. |
| 7 | + |
| 8 | +```properties {filename:application.properties} |
| 9 | +sentry.traces-sample-rate=1.0 |
| 10 | +sentry.profile-session-sample-rate=1.0 |
| 11 | +sentry.profile-lifecycle=TRACE |
| 12 | +``` |
| 13 | + |
| 14 | +```yaml {filename:application.yml} |
| 15 | +sentry: |
| 16 | + traces-sample-rate: 1.0 |
| 17 | + profile-session-sample-rate: 1.0 |
| 18 | + profile-lifecycle: TRACE |
| 19 | +``` |
| 20 | +
|
| 21 | +### Enabling Manual Lifecycle Profiling |
| 22 | +
|
| 23 | +To enable manual profiling, set the lifecycle to `MANUAL`. Manual profiling does not require tracing to be enabled. |
| 24 | + |
| 25 | +```properties {filename:application.properties} |
| 26 | +sentry.profile-session-sample-rate=1.0 |
| 27 | +sentry.profile-lifecycle=MANUAL |
| 28 | +``` |
| 29 | + |
| 30 | +```yaml {filename:application.yml} |
| 31 | +sentry: |
| 32 | + profile-session-sample-rate: 1.0 |
| 33 | + profile-lifecycle: MANUAL |
| 34 | +``` |
| 35 | + |
| 36 | +Then use the `startProfiler` and `stopProfiler` methods to start and stop profiling respectively. |
| 37 | + |
| 38 | + |
| 39 | +```java |
| 40 | +import io.sentry.Sentry; |
| 41 | +
|
| 42 | +// Start profiling |
| 43 | +Sentry.startProfiler(); |
| 44 | +
|
| 45 | +// run some code here |
| 46 | +
|
| 47 | +// Stop profiling |
| 48 | +Sentry.stopProfiler(); |
| 49 | +``` |
| 50 | + |
| 51 | +```kotlin |
| 52 | +import io.sentry.Sentry |
| 53 | +
|
| 54 | +// Start profiling |
| 55 | +Sentry.startProfiler() |
| 56 | +
|
| 57 | +// run some code here |
| 58 | +
|
| 59 | +// Stop profiling |
| 60 | +Sentry.stopProfiler() |
| 61 | +``` |
| 62 | + |
| 63 | +### Profiling with OpenTelemetry |
| 64 | +When running our OpenTelemetry Agent in <PlatformLink to="/opentelemetry/setup/agent/auto-init">Agent Auto-Init</PlatformLink> mode. The `SentryProfilerConfiguration` needs to be setup. This is due to the fact that the profiler is not yet on the classpath when the agent initializes `Sentry`. Therefore the profiler needs to be initialized when `Spring` starts. |
| 65 | + |
| 66 | +<Alert level="warning"> |
| 67 | +If you are using our OpenTelemetry Agent, profiling when running in the <PlatformLink to="/opentelemetry/setup/agent/auto-init">Agent Auto-Init</PlatformLink> mode is supported from version `8.26.0` onwards. |
| 68 | +</Alert> |
| 69 | + |
| 70 | +In order to set this up, import `SentryProfilerConfiguration` in one of your `@Configuration` classes: |
| 71 | + |
| 72 | +```java {tabTitle:Java (Spring 5)} {diff} |
| 73 | +import org.springframework.context.annotation.Bean; |
| 74 | +import org.springframework.context.annotation.Import; |
| 75 | ++import io.sentry.spring.SentryProfilerConfiguration; |
| 76 | +
|
| 77 | ++@Import(SentryProfilerConfiguration.class) |
| 78 | +class SentryConfig { |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +```java {tabTitle:Java (Spring 6)} {diff} |
| 83 | +import org.springframework.context.annotation.Bean; |
| 84 | +import org.springframework.context.annotation.Import; |
| 85 | ++import io.sentry.spring.jakarta.SentryProfilerConfiguration; |
| 86 | +
|
| 87 | ++@Import(SentryProfilerConfiguration.class) |
| 88 | +class SentryConfig { |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +```kotlin {tabTitle:Kotlin (Spring 5)} {diff} |
| 93 | +import org.springframework.context.annotation.Bean |
| 94 | +import org.springframework.context.annotation.Import |
| 95 | ++import io.sentry.spring.SentryProfilerConfiguration; |
| 96 | +
|
| 97 | ++@Import(SentryProfilerConfiguration::class) |
| 98 | +class SentryConfig { |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +```kotlin {tabTitle:Kotlin (Spring 6)} {diff} |
| 103 | +import org.springframework.context.annotation.Bean |
| 104 | +import org.springframework.context.annotation.Import |
| 105 | ++import io.sentry.spring.jakarta.SentryProfilerConfiguration; |
| 106 | +
|
| 107 | ++@Import(SentryProfilerConfiguration::class) |
| 108 | +class SentryConfig { |
| 109 | +} |
| 110 | +``` |
| 111 | + |
0 commit comments