Skip to content

Commit ce95ce9

Browse files
committed
feat: add sentry to learn
1 parent 15cc5da commit ce95ce9

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

src/learn/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ With that in mind, we've created a few paths to help you get started with Leaf.
141141

142142
After building your app, you'll want to deploy it to the web so that others can access it. We've got you covered with our [deployment guides](/learn/deployment/) that walk you through deploying your app to various platforms.
143143

144+
## Monitor your app
145+
146+
Once your app is live, you'll want to monitor it to ensure it's running smoothly. For now, we have a guide on [monitoring your Leaf app with Sentry](/learn/monitoring/sentry/) to help you get started. We'll be adding guides for other monitoring tools like New Relic, Datadog, and more in the future.
147+
144148
## Contributing
145149

146150
If you've written a tutorial that you think would be a great addition to our Learn section, feel free to submit a PR to our [GitHub repository](https://github.com/leafsphp/docs) with your tutorial. For our readers' benefit, be sure to follow the [contribution guide](/learn/contributing) when submitting your tutorial. Thank you for your contribution!

src/learn/monitoring/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# App Monitoring
2+
3+
This guide will help you set up monitoring for your Leaf application, ensuring you can track its health and performance effectively.
4+
5+
## Guides
6+
7+
| Provider | Description |
8+
| :-------------------------------------------------------------- | :--------------------------------------------------------- |
9+
| [Sentry](/learn/monitoring/sentry/) | Monitoring your Leaf application with Sentry for error tracking and performance monitoring. |
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Monitoring with Sentry
2+
3+
::: warning Sentry
4+
You will need a Sentry account to follow this guide.
5+
If you do not have one, you can sign up for free at [Sentry.io](https://sentry.io/).
6+
Sentry requires PHP 7.2 or higher, so ensure your Leaf MVC application is running on a compatible version.
7+
:::
8+
9+
## What Are We Building
10+
11+
This experiment will guide you through setting up Sentry to monitor your Leaf MVC application. Sentry is a developer-first application monitoring platform that helps you identify and fix software problems before they impact your users.
12+
13+
::: details (New to Sentry?)
14+
Sentry provides insights into application performance, user interactions, and error occurrences, allowing developers to quickly identify and resolve issues.
15+
:::
16+
17+
## 1. Create a Sentry Project
18+
19+
You can create a new project in Sentry by following these steps:
20+
21+
1. Navigate to the insights section of your Sentry dashboard and click on "all projects".
22+
2. Click on the "Create Project" button.
23+
3. Select "PHP" as the platform.
24+
4. Enter a name for your project and click "Create Project".
25+
5. After creating the project, you will be provided with a DSN (Data Source Name). This DSN is essential for configuring your Leaf MVC application to send data to Sentry.
26+
27+
## 2. Install the Sentry SDK
28+
29+
Navigate to your application's root directory and run the following command:
30+
31+
::: code-group
32+
33+
```bash:no-line-numbers [Leaf CLI]
34+
leaf install sentry/sentry
35+
```
36+
37+
```bash:no-line-numbers [Composer]
38+
composer require sentry/sentry
39+
```
40+
41+
:::
42+
43+
## 3. Plug-in Sentry to Your Application
44+
45+
Open up `public/index.php` and add wrap the Leaf execution code with Sentry's initialization and error handling:
46+
47+
```php
48+
/*
49+
|-----------------------------------------------------------------------
50+
| Load Sentry
51+
|-----------------------------------------------------------------------
52+
|
53+
| Sentry is a powerful error tracking and performance monitoring tool.
54+
| It helps you identify and fix issues in your application.
55+
| This configuration initializes Sentry with your DSN.
56+
|
57+
*/
58+
\Sentry\init([ // [!code ++]
59+
'dsn' => '...', // [!code ++]
60+
]); // [!code ++]
61+
62+
/*
63+
|-----------------------------------------------------------------------
64+
| Run your Leaf MVC application
65+
|-----------------------------------------------------------------------
66+
|
67+
| This line brings in all your routes and starts your application
68+
|
69+
*/
70+
\Leaf\Core::runApplication(); // [!code --]
71+
try { // [!code ++]
72+
\Leaf\Core::runApplication(); // [!code ++]
73+
} catch (\Throwable $exception) { // [!code ++]
74+
\Sentry\captureException($exception); // [!code ++]
75+
} // [!code ++]
76+
```
77+
78+
## Conclusion
79+
80+
From there, any errors should be automatically captured and sent to your Sentry dashboard. You can test this by intentionally causing an error in your application, such as by throwing an exception or accessing an undefined variable.
81+
82+
There are other options you can try out to customize Sentry's behavior, such as setting up environment variables, configuring release tracking, and more. You can find more information in the [Sentry PHP SDK documentation](https://docs.sentry.io/platforms/php/).

0 commit comments

Comments
 (0)