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
14 changes: 14 additions & 0 deletions docs/platforms/php/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ This function is called with an SDK-specific check-in event object, and can retu

</SdkOption>

## Logs Options

<SdkOption name="enable_logs" type='bool' defaultValue='false'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL! We should swap everything to use SdkOption


This option enables the logging integration, which allows the SDK to capture logs and send them to Sentry. This is disabled by default.

</SdkOption>

<SdkOption name="before_send_log" type='function (\Sentry\Logs\Log $log): ?\Sentry\Logs\Log'>

This function is called with an SDK-specific log object, and can return a modified log event object, or `null` to skip reporting the event.

</SdkOption>

## Transport Options

Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.
Expand Down
32 changes: 32 additions & 0 deletions docs/platforms/php/common/logs/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Set Up Logs
sidebar_title: Logs
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
sidebar_order: 5600
---

<Include name="feature-stage-beta-logs.mdx" />

With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

<Alert title="Looking for Laravel or Symfony?">

Let us know what you would like to see on GitHub: [Laravel Logs](https://github.com/getsentry/sentry-php/issues/999) or [Symfony Logs](https://github.com/getsentry/sentry-symfony/issues/925).

</Alert>

## Requirements

<PlatformContent includePath="logs/requirements" />

## Setup

<PlatformContent includePath="logs/setup" />

## Usage

<PlatformContent includePath="logs/usage" />

## Options

<PlatformContent includePath="logs/options" />
13 changes: 8 additions & 5 deletions docs/product/explore/logs/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
url="/platforms/dart/guides/flutter/logs/"
/>

### PHP

- <LinkWithPlatformIcon
platform="php"
label="PHP"
url="/platforms/dart/guides/php/logs/"
/>

### Python

- <LinkWithPlatformIcon
Expand All @@ -218,11 +226,6 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s

We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates:

- <LinkWithPlatformIcon
platform="php"
label="PHP"
url="https://github.com/getsentry/sentry-php/issues/1824"
/>
- <LinkWithPlatformIcon
platform="cocoa"
label="Cocoa (iOS)"
Expand Down
21 changes: 21 additions & 0 deletions platform-includes/logs/options/php.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#### before_send_log

To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` option.

```php
\Sentry\init([
'dsn' => '___PUBLIC_DSN___',
// Enable logs to be sent to Sentry
'enable_logs' => true,
'before_send_log' => function (\Sentry\Logs\Log $log): ?\Sentry\Logs\Log {
if ($log->getLevel() === \Sentry\Logs\LogLevel::info()) {
// Filter out all info logs
return null;
}

return $log;
},
]);
```

The `before_send_log` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it.
1 change: 1 addition & 0 deletions platform-includes/logs/requirements/php.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Logs for PHP are supported in Sentry PHP SDK version `4.12.0` and above.
12 changes: 12 additions & 0 deletions platform-includes/logs/setup/php.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`.

```php
\Sentry\init([
'dsn' => '___PUBLIC_DSN___',
// Enable logs to be sent to Sentry
'enable_logs' => true,
]);

// Somewhere at the end of you execution, you should flush the logger to send pending logs to Sentry.
\Sentry\logger()->flush();
```
19 changes: 19 additions & 0 deletions platform-includes/logs/usage/php.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `logger()` function.

The `logger()` function exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.

You can pass additional attributes directly to the logging functions. These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

```php
\Sentry\logger()->info('A simple log message');
\Sentry\logger()->info('A message with a parameter that says %s', values: ['hello']);
\Sentry\logger()->warn('This is a warning log with attributes.', attributes: [
'attribute1' => 'string',
'attribute2' => 1,
'attribute3' => 1.0,
'attribute4' => true,
]);

// Somewhere at the end of you execution, you should flush the logger to send pending logs to Sentry.
\Sentry\logger()->flush();
```