Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions docs/platforms/php/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,19 @@ Leave this enabled if you want to reduce connection setup overhead for frequent
A number between `0` and `1`, controlling the percentage chance a given profile will be sent to Sentry. (`0` represents 0% while `1` represents 100%.) Setting this to a non null value will enable profiling.

</SdkOption>

<PlatformSection notSupported={["php.symfony"]}>

<SdkOption name="profile_session_sample_rate" type="float" defaultValue="null">

A number between `0` and `1`, controlling the percentage chance a profiling session is sampled for continuous profiling. It has no effect if `profiles_sample_rate` is set. Available in `sentry/sentry` `4.36.0` and later.

</SdkOption>

<SdkOption name="profile_lifecycle" type="string" defaultValue="manual">

Controls when the continuous profiler runs. With `manual`, you start and stop it with `\Sentry\profiler()`. With `trace`, it runs while a sampled transaction is active.

</SdkOption>

</PlatformSection>
56 changes: 51 additions & 5 deletions docs/platforms/php/common/profiling/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,68 @@ phpenmod -s fpm excimer
phpenmod -s apache2 excimer
```

## Enable Tracing
## Enable Continuous Profiling

Sentry's tracing product has to be enabled in order for Profiling to work.
To begin capturing profiling data, you first need to start a transaction.
Check out the <PlatformLink to="/tracing/">tracing setup</PlatformLink> and <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">custom instrumentation</PlatformLink> documentation for more detailed information.
<Alert>

Continuous profiling is available in Sentry PHP SDK version `4.36.0` and above.

</Alert>

The continuous profiler samples your code for as long as it runs. Enable it with <PlatformLink to="/configuration/options/#profile-session-sample-rate">`profile_session_sample_rate`</PlatformLink>. The sampling decision is made once per profiling session.

### Manual Lifecycle

By default, you start and stop the profiler yourself. This doesn't require tracing.
Comment thread
sentry-junior[bot] marked this conversation as resolved.
Resolved

```php
\Sentry\init([
'dsn' => '___PUBLIC_DSN___',
'profile_session_sample_rate' => 1.0,
]);

\Sentry\profiler()->start();

// Run some code here

\Sentry\profiler()->stop();
```

You can also start the profiler before calling `\Sentry\init()`, for example to profile the bootstrap of your application.

In long-running workers, such as FrankenPHP, RoadRunner, or Swoole, start the profiler once and pause it between requests:

```php
\Sentry\profiler()->start();

$handler = static function (): void {
\Sentry\profiler()->resume();

// Handle the request

\Sentry\profiler()->pause();
};

while (frankenphp_handle_request($handler)) {
}
```

### Trace Lifecycle

Set <PlatformLink to="/configuration/options/#profile-lifecycle">`profile_lifecycle`</PlatformLink> to `trace` to run the profiler automatically while a sampled transaction is active:

```php
\Sentry\init([
'dsn' => '___PUBLIC_DSN___',
'traces_sample_rate' => 1.0,
'profile_session_sample_rate' => 1.0,
'profile_lifecycle' => 'trace',
]);
```

## Enabling Profiling
## Enable Transaction-Based Profiling

Transaction-based profiling captures a profile for each sampled transaction, so tracing has to be enabled. Check out the <PlatformLink to="/tracing/">tracing setup</PlatformLink> and <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">custom instrumentation</PlatformLink> documentation for more detailed information.

```php
\Sentry\init([
Expand Down
37 changes: 33 additions & 4 deletions docs/platforms/php/guides/laravel/profiling/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,45 @@ phpenmod -s fpm excimer
phpenmod -s apache2 excimer
```

## Enable Tracing
## Enable Continuous Profiling

Sentry's tracing product has to be enabled in order for Profiling to work.
Check out the <PlatformLink to="/tracing/">tracing setup</PlatformLink> documentation for more detailed information.
<Alert>

Continuous profiling requires `sentry/sentry` version `4.36.0` and above.

</Alert>

The continuous profiler samples your code for as long as it runs. Enable it with <PlatformLink to="/configuration/options/#profile-session-sample-rate">`profile_session_sample_rate`</PlatformLink>. The sampling decision is made once per profiling session.

### Manual Lifecycle

By default, you start and stop the profiler yourself. This doesn't require tracing.

```php {filename:config/sentry.php}
'profile_session_sample_rate' => 1.0,
```

```php
\Sentry\profiler()->start();

// Run some code here

\Sentry\profiler()->stop();
```

### Trace Lifecycle

Set <PlatformLink to="/configuration/options/#profile-lifecycle">`profile_lifecycle`</PlatformLink> to `trace` to run the profiler automatically while a sampled transaction is active:

```php {filename:config/sentry.php}
'traces_sample_rate' => 1.0,
'profile_session_sample_rate' => 1.0,
'profile_lifecycle' => 'trace',
```

## Enable Profiling
## Enable Transaction-Based Profiling

Transaction-based profiling captures a profile for each sampled transaction, so tracing has to be enabled. Check out the <PlatformLink to="/tracing/">tracing setup</PlatformLink> documentation for more detailed information.

```php {filename:config/sentry.php}
'traces_sample_rate' => 1.0,
Expand Down
Loading