-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Document the Logs integration for PHP #13916
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| ``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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