Skip to content

Commit 083cb38

Browse files
authored
Merge pull request #2170 from brefphp/improve-monitoring-docs
Monitoring docs: mention the new "Performance" page and various improvements
2 parents ed92cd0 + 0e67d90 commit 083cb38

6 files changed

Lines changed: 139 additions & 30 deletions

File tree

docs/cloud.mdx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,42 @@ import Image from 'next/image';
88

99
# Bref Cloud documentation
1010

11-
Bref Cloud makes it easy to deploy and monitor serverless PHP applications on AWS Lambda. Learn more about it [on the Bref Cloud homepage](https://bref.sh/cloud).
11+
[Bref Cloud](/cloud) is the service that complements the open-source Bref project. It deploys, monitors and operates serverless PHP applications on AWS Lambda, in your own AWS account, without the AWS complexity.
1212

13-
To get started, [create a free Bref Cloud account](https://bref.cloud/register).
14-
15-
Bref Cloud is a service that complements the open-source Bref project. It connects to all your AWS accounts to simplify permissions and access management, and provides a dashboard to manage your serverless applications.
13+
To get started, [create a Bref Cloud account](https://bref.cloud/register). There is a free plan for personal projects, and paid plans come with a free trial. See the [pricing](/cloud#pricing).
1614

1715
<Cards num={2}>
1816
<Cards.Card icon={<Image src={brefIcon} className="size-6" />} title="Learn more about Bref Cloud" href="/cloud" />
1917
<Cards.Card icon={<Image src={brefIcon} className="size-6" />} arrow={true} title="Get started with Bref Cloud" href="https://bref.cloud/register" />
2018
</Cards>
19+
20+
## What Bref Cloud does
21+
22+
### Deploy
23+
24+
- **One command**: `bref deploy` from your machine or [from GitHub Actions](./cloud-deploy.mdx). No AWS credentials to create, distribute or rotate: Bref Cloud generates [short-lived credentials](./cloud-security.mdx) for every deployment.
25+
- **Databases and networks**: create MySQL or PostgreSQL databases (fixed instances, or serverless databases that scale and pause on their own) and private networks in a few clicks.
26+
- **Environments**: manage dev, staging and production across AWS accounts and regions from one dashboard, with the history of every deployment.
27+
28+
### Monitor
29+
30+
- **Overview**: a diagram of each environment's architecture with live metrics on every component.
31+
- **Logs**: search logs or tail them in real time.
32+
- **Metrics**: Lambda invocations, concurrency, duration and errors, API Gateway, queues and dead-letter queues.
33+
- **Traces**: a trace explorer optimized for PHP applications, with a free [Bref X-Ray](/xray) license included. See database queries, HTTP calls and AWS calls inside each invocation, and filter traces by route, job, command, cold start, or your own annotations, over up to 30 days.
34+
- **Performance**: the slowest database queries, the latency of every route, and the slowest jobs of your application, computed from the last 30 days of traces.
35+
- **Health checks**: verify that the database, the cache and the Lambda configuration of a deployed application are healthy (Laravel only for now).
36+
37+
[Learn more about monitoring with Bref Cloud](/docs/monitoring#bref-cloud).
38+
39+
### Operate
40+
41+
- **Queues**: watch queues and dead-letter queues, and retry, delete or flush failed Laravel jobs.
42+
- **Commands**: run console commands (Artisan, Symfony console…) on a deployed environment from the dashboard.
43+
- **Secrets**: create and manage secrets for all your applications.
44+
- **Files**: browse, upload, rename and delete files in S3 buckets.
45+
46+
### Team and security
47+
48+
- **Team members**: invite teammates with read-only, write or admin access. They never need AWS access.
49+
- **AWS access**: Bref Cloud connects to your AWS accounts through IAM roles and temporary credentials, never long-lived access keys. [Learn more](./cloud-security.mdx).

docs/monitoring/cloud-metrics.png

404 KB
Loading
366 KB
Loading

docs/monitoring/cloud-traces.png

368 KB
Loading

docs/monitoring/index.mdx

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ asIndexPage: true
44

55
import Image from 'next/image';
66
import cloudXrayTrace from './cloud-xray-trace.png';
7-
import cloudXrayFiltersGeneral from './cloud-xray-filters-general.png';
8-
import cloudXrayFiltersAnnotations from './cloud-xray-filters-annotations.png';
97
import cloudOverview from './cloud-overview.png';
108
import cloudLogs from './cloud-logs.png';
9+
import cloudMetrics from './cloud-metrics.png';
10+
import cloudTraces from './cloud-traces.png';
11+
import cloudPerformance from './cloud-performance.png';
1112

1213
# Monitoring
1314

@@ -17,7 +18,7 @@ Here is a summary of recommended tools for monitoring Bref applications:
1718

1819
- **Logs and metrics**: CloudWatch (built-in), [Bref Cloud](/cloud)
1920
- **Error tracking**: [Sentry](https://sentry.io) and similar services
20-
- **Performance tracing**: [Bref Cloud](/cloud) with [X-Ray](/xray)
21+
- **Tracing and performance insights**: [Bref Cloud](/cloud) with [X-Ray](/xray)
2122

2223
Let's dive into the details of each of them.
2324

@@ -29,27 +30,59 @@ For more advanced use cases, such as tracking Lambda errors outside of PHP-FPM (
2930

3031
## Bref Cloud
3132

32-
[Bref Cloud](/cloud) provides an all-in-one monitoring experience for serverless PHP applications:
33+
[Bref Cloud](/cloud) monitors serverless PHP applications. It reads logs, metrics and traces from your AWS account. There is no agent to install.
34+
35+
### Overview
36+
37+
The overview page shows a diagram of the environment: Lambda functions, API Gateway, CloudFront, SQS queues, S3 buckets and databases. Each component shows live metrics: requests, invocations, errors, queue size, storage.
3338

3439
<Image className="mt-3 rounded-lg shadow-md border" src={cloudOverview} alt="Bref Cloud application overview" />
3540

36-
- **Logs**: view and search CloudWatch logs in a simplified UI.
41+
### Logs
42+
43+
View, search and tail CloudWatch logs. Laravel and Symfony logs are [structured](/docs/environment/logs): you can filter them by log level or exception class.
3744

3845
<Image className="mt-3 rounded-lg shadow-md border" src={cloudLogs} alt="Log viewer in Bref Cloud" />
3946

40-
- **Metrics**: monitor Lambda invocations, duration, errors, and more.
41-
- **Traces**: visualize X-Ray traces to understand the performance of your application, including database queries, HTTP calls, and AWS SDK calls.
47+
### Metrics
48+
49+
The metrics page shows Lambda invocations, duration and errors, as well as API Gateway requests and latency. Queue metrics can also be found in the "Queues" page. You can add graphs to compare metrics over up to 30 days.
50+
51+
<Image className="mt-3 rounded-lg shadow-md border" src={cloudMetrics} alt="Metrics in Bref Cloud" />
52+
53+
### Traces
54+
55+
A trace shows what happens inside an invocation: PHP code, database queries, HTTP calls, and AWS SDK calls. For each AWS call, the trace shows the queue, table, or topic it used.
4256

4357
<Image className="mt-3 rounded-lg shadow-md border" src={cloudXrayTrace} alt="X-Ray trace in Bref Cloud" />
4458

45-
With the [Bref X-Ray](/xray) package, traces are enriched with annotations that you can use to filter and search. For example, you can filter traces by specific controller, route, CLI command, or job class:
59+
The [Bref X-Ray package](/xray) adds annotations to traces: route, controller, job class, CLI command, cold start. You can add [your own annotations](/xray/docs#custom-annotations), for example the tenant or the plan of the user. The trace explorer uses annotations as filters. For example, you can list all the traces of one route, of one job, of one tenant, or all the invocations with a cold start.
60+
61+
<Image className="mt-3 rounded-lg shadow-md border" src={cloudTraces} alt="Trace explorer in Bref Cloud" />
62+
63+
Enable [AWS Transaction Search](/xray/docs#enabling-aws-transaction-search) on your AWS account, and the trace explorer searches up to 30 days of traces instead of 6 hours. It is a one-time switch in the AWS console.
64+
65+
### Performance
66+
67+
The Performance page aggregates the traces of the last 30 days. It shows the slowest database queries, the latency of each route, and the slowest jobs.
68+
69+
<Image className="mt-3 rounded-lg shadow-md border" src={cloudPerformance} alt="Performance page in Bref Cloud" />
70+
71+
- **Slowest database queries**: SQL queries grouped by statement, with the number of calls, the average duration and the p95 duration.
72+
- **Routes**: server-side processing time per route, sorted by number of requests or by latency. Click a route to open its traces.
73+
- **Slowest jobs**: queue worker invocations grouped by job class. Click a job to open its traces.
74+
75+
The page requires the [Bref X-Ray package](/xray) in the application and [Transaction Search](/xray/docs#enabling-aws-transaction-search) on the AWS account. After that, there is nothing else to configure. Bref Cloud computes the statistics when you open the page, caches them for 24 hours, and lets you recompute them at any time. The statistics only include traced invocations (see the [X-Ray sampling rate](/xray/docs#costs)).
76+
77+
### Failed jobs and health checks
78+
79+
Laravel applications have a "Failed jobs" tab next to their queues. It shows the exception of each failed job. You can retry, delete or flush jobs from there.
80+
81+
Health checks check that a deployed application works: the database is reachable, the cache works, the Lambda functions use the recommended settings. Laravel only for now.
4682

47-
<div className="flex gap-4 mt-3 items-start">
48-
<Image className="rounded-lg shadow-md border h-auto" style={{maxHeight: 350, width: 'auto'}} src={cloudXrayFiltersGeneral} alt="X-Ray trace filters in Bref Cloud" />
49-
<Image className="rounded-lg shadow-md border h-auto" style={{maxHeight: 350, width: 'auto'}} src={cloudXrayFiltersAnnotations} alt="X-Ray trace annotation filters in Bref Cloud" />
50-
</div>
83+
### X-Ray license
5184

52-
Bref Cloud users get a **free [Bref X-Ray](/xray) license** included in their plan to enable performance tracing. To activate it, contact support via [bref.cloud/support](https://bref.cloud/support) or [Slack](https://bref.sh/slack).
85+
Bref Cloud paid plans include a free [Bref X-Ray](/xray) license. To activate it, contact support via [bref.cloud/support](https://bref.cloud/support) or [Slack](https://bref.sh/slack).
5386

5487
[Learn more about Bref Cloud](/cloud).
5588

website/content/xray/docs.mdx

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ Send me a Slack message or an email (matthieu@bref.sh) if you have any trouble,
104104

105105
## Enabling AWS Transaction Search
106106

107-
[AWS Transaction Search](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Transaction-Search.html) is an AWS service that indexes X-Ray traces and replaces "X-Ray classic" search.
107+
[AWS Transaction Search](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Transaction-Search.html) is an AWS service that indexes X-Ray traces and replaces "X-Ray classic" search. It is opt-in, and **we recommend enabling it**, whether you explore traces in Bref Cloud or in the AWS console:
108108

109-
**Enable it** and Bref Cloud tracing gets much better:
109+
- search up to 30 days of traces instead of only 6 hours
110+
- filter traces by route, job, command, cold start, or [any custom annotation](#custom-annotations)
111+
- spans are stored in CloudWatch Logs (the `aws/spans` log group), so you can also query them with CloudWatch Logs Insights, for example to aggregate durations by route or by SQL query
110112

111-
- up to 30 days of traces instead of only 6 hours
112-
- filter traces by route, job, command, cold start, etc.
113-
- search all spans rather than only the percentage indexed by "classic X-Ray"
113+
In Bref Cloud, Transaction Search also unlocks the [Performance page](/docs/monitoring#performance): slowest database queries, latency per route, slowest jobs.
114+
115+
If you don't use Bref Cloud, explore traces from the **Transaction Search** page of the CloudWatch console. The classic X-Ray console keeps working but only sees the indexed percentage (see below).
114116

115117
Downsides:
116118

@@ -127,9 +129,9 @@ The change is reversible. To enable Transaction Search ([official guide](https:/
127129

128130
<Image className="mt-3 rounded-lg shadow-md border" src={transactionSearchSettings} alt="Transaction Search settings for X-Ray users" />
129131

130-
The indexing percentage does _not_ impact Bref Cloud (it is **not** the Lambda sampling rate mentioned in [Costs](#costs) below), leave it at 1% by default. Increase it only if you still use classic X-Ray.
132+
**Leave the indexing percentage at 1%** unless you know what you are doing. It only affects the classic X-Ray console and APIs. It is not the Lambda sampling rate (see [Costs](#costs)), and it has no effect on Bref Cloud or on the Transaction Search page.
131133

132-
It can take up to 10 minutes to activate Transaction Search and see it in Bref Cloud.
134+
It can take up to 10 minutes to activate Transaction Search and see spans show up, in Bref Cloud or in the CloudWatch console.
133135

134136
## Costs
135137

@@ -150,11 +152,11 @@ This is quite useful: when an application has low traffic, most requests/invocat
150152

151153
### Laravel
152154

153-
If you are using Laravel, the package automatically integrates with the Laravel service provider. You can see the traces in the AWS X-Ray console.
155+
If you are using Laravel, the package automatically integrates with the Laravel service provider. You can see the traces in [Bref Cloud](/docs/monitoring#bref-cloud) or in the AWS console.
154156

155157
#### Request tracing
156158

157-
The package automatically traces all requests to your application. You can see the traces in the AWS X-Ray console.
159+
The package automatically traces all requests to your application.
158160

159161
#### Database queries
160162

@@ -164,7 +166,7 @@ Eloquent queries are automatically traced and the SQL queries are added to metad
164166

165167
#### Jobs
166168

167-
The package automatically traces all jobs dispatched via the Laravel queue. You can see the traces in the AWS X-Ray console, and filter them by job name.
169+
The package automatically traces all jobs dispatched via the Laravel queue. Traces can be filtered by job name.
168170

169171
![](./laravel-jobs.png)
170172

@@ -178,7 +180,7 @@ The package automatically traces all HTTP requests made via the Laravel HTTP cli
178180

179181
### Symfony
180182

181-
If you are using Symfony, the package automatically integrates with the Symfony service provider. You can see the traces in the AWS X-Ray console.
183+
If you are using Symfony, the package automatically integrates with the Symfony service provider. You can see the traces in [Bref Cloud](/docs/monitoring#bref-cloud) or in the AWS console.
182184

183185
#### Symfony Messenger
184186

@@ -282,6 +284,51 @@ XRay::subSegment('doSomething', function () {
282284
});
283285
```
284286

287+
### Custom annotations
288+
289+
Annotations are indexed key-value pairs attached to a trace. Bref adds `Route`, `Controller`, `Job`, `Command`, and cold start annotations automatically. You can add your own, for example the tenant or the plan of the current user:
290+
291+
```php
292+
use Bref\Apm\XRay\XRay;
293+
294+
XRay::trace()->addAnnotation('tenant', $tenant->slug);
295+
```
296+
297+
Call it during the request or the job, for example from a middleware or an event listener. Do not call it at boot time (for example in the `boot()` method of a service provider): the trace is reset after every invocation, so an annotation added at boot is only attached to the first invocation of the Lambda instance.
298+
299+
For example, with a Laravel middleware registered in the `web` middleware group:
300+
301+
```php
302+
namespace App\Http\Middleware;
303+
304+
use Bref\Apm\XRay\XRay;
305+
use Closure;
306+
use Illuminate\Http\Request;
307+
308+
class AnnotateTrace
309+
{
310+
public function handle(Request $request, Closure $next)
311+
{
312+
$tenant = $request->user()?->tenant;
313+
if ($tenant) {
314+
XRay::trace()->addAnnotation('tenant', $tenant->slug);
315+
}
316+
317+
return $next($request);
318+
}
319+
}
320+
```
321+
322+
X-Ray has [constraints on annotations](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-annotations):
323+
324+
- keys can only contain letters, numbers and underscores (`feature_flag` is valid, `feature-flag` is not)
325+
- values are strings
326+
- a trace can have at most 50 annotations
327+
328+
The package does not validate these constraints, and AWS does not report invalid annotations back to your application.
329+
330+
In Bref Cloud, every annotation becomes a filter in the trace explorer (with [Transaction Search](#enabling-aws-transaction-search) enabled). For example, you can list all the traces of a given tenant over the last 30 days. Keep the number of possible values limited (an identifier or a category, not free text).
331+
285332
### Tracing AWS SDK calls
286333

287334
Trace AWS SDK calls with the `AwsSdkTracer::trace($client)` method.
@@ -297,7 +344,7 @@ AwsSdkTracer::trace($client);
297344

298345
![](./sdk-tracing.png)
299346

300-
All calls will be traced and appear in the X-Ray console. However, only the first 10 requests will be sampled (i.e. will result in propagating tracing to the target AWS service). This is to avoid oversampling and hitting the X-Ray limit of 100 linked traces. For example, if a Lambda function sends 100 messages to SQS, only the first 10 Lambda invocations triggered by the SQS messages will create sub-traces. The other 90 invocations will appear as segments in the original trace, but will not create sub-traces.
347+
All calls will be traced and appear in the trace. However, only the first 10 requests will be sampled (i.e. will result in propagating tracing to the target AWS service). This is to avoid oversampling and hitting the X-Ray limit of 100 linked traces. For example, if a Lambda function sends 100 messages to SQS, only the first 10 Lambda invocations triggered by the SQS messages will create sub-traces. The other 90 invocations will appear as segments in the original trace, but will not create sub-traces.
301348

302349
### Tracing Async-AWS SDK calls
303350

@@ -326,7 +373,7 @@ $httpClient = new TracedAsyncAwsHttpClient(HttpClient::create([
326373
$sqs = new SqsClient([ /* config */ ], null, $httpClient);
327374
```
328375

329-
All calls will be traced and appear in the X-Ray console. However, only the first 10 requests will be sampled (i.e. will result in propagating tracing to the target AWS service). This is to avoid oversampling and hitting the X-Ray limit of 100 linked traces. For example, if a Lambda function sends 100 messages to SQS, only the first 10 Lambda invocations triggered by the SQS messages will create sub-traces. The other 90 invocations will appear as segments in the original trace, but will not create sub-traces.
376+
All calls will be traced and appear in the trace. However, only the first 10 requests will be sampled (i.e. will result in propagating tracing to the target AWS service). This is to avoid oversampling and hitting the X-Ray limit of 100 linked traces. For example, if a Lambda function sends 100 messages to SQS, only the first 10 Lambda invocations triggered by the SQS messages will create sub-traces. The other 90 invocations will appear as segments in the original trace, but will not create sub-traces.
330377

331378
### Tracing Guzzle calls
332379

0 commit comments

Comments
 (0)