You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Tracing enabled** | Enables or disables tracing. By default tracing is enabled when running in AWS Lambda. | `POWERTOOLS_TRACE_ENABLED` | `enabled`
58
58
**Service name** | Sets an annotation with the **name of the service** across all traces e.g. `serverlessAirline` | `POWERTOOLS_SERVICE_NAME` | `serviceName`
59
+
**Capture HTTPs Requests** | Defines whether HTTPs requests will be traced or not, enabled by default when tracing is also enabled. | `POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS` | `captureHTTPsRequests`
59
60
60
61
For a **complete list** of supported environment variables, refer to [this section](./../index.md#environment-variables).
61
62
@@ -137,13 +138,9 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
137
138
138
139
=== "Middy Middleware"
139
140
140
-
!!! tip "Using Middy for the first time?"
141
-
You can install Middy by running `npm i @middy/core`.
142
-
Learn more about [its usage and lifecycle in the official Middy documentation](https://github.com/middyjs/middy#usage){target="_blank"}.
143
-
144
141
```typescript hl_lines="1-2 11 13"
145
142
import { Tracer, captureLambdaHandler } from '@aws-lambda-powertools/tracer';
146
-
import middy from '@middy/core';
143
+
import middy from '@middy/core'; // (1)
147
144
148
145
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
149
146
@@ -157,6 +154,9 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
157
154
.use(captureLambdaHandler(tracer));
158
155
```
159
156
157
+
1. Using Middy for the first time? You can install Middy by running `npm i @middy/core`.
158
+
Learn more about [its usage and lifecycle in the official Middy documentation](https://github.com/middyjs/middy#usage){target="_blank"}.
159
+
160
160
=== "Decorator"
161
161
162
162
!!! info
@@ -326,13 +326,67 @@ If you're looking to shave a few microseconds, or milliseconds depending on your
326
326
=== "index.ts"
327
327
328
328
```typescript hl_lines="5"
329
-
import { S3 } from "aws-sdk";
329
+
import { S3 } from 'aws-sdk';
330
330
import { Tracer } from '@aws-lambda-powertools/tracer';
331
331
332
332
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
333
333
const s3 = tracer.captureAWSClient(new S3());
334
334
```
335
335
336
+
### Tracing HTTP requests
337
+
338
+
When your function makes calls to HTTP APIs, Tracer automatically traces those calls and add the API to the service graph as a downstream service.
339
+
340
+
You can opt-out from this feature by setting the **`POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS=false`** environment variable or by passing the `captureHTTPSRequests: false` option to the `Tracer` constructor.
341
+
342
+
!!! info
343
+
The following snippet shows how to trace [axios](https://www.npmjs.com/package/axios) requests, but you can use any HTTP client library built on top of [http](https://nodejs.org/api/http.html) or [https](https://nodejs.org/api/https.html).
344
+
Support to 3rd party HTTP clients is provided on a best effort basis.
345
+
346
+
=== "index.ts"
347
+
348
+
```typescript hl_lines="2 7"
349
+
import { Tracer } from '@aws-lambda-powertools/tracer';
350
+
import axios from 'axios'; // (1)
351
+
352
+
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
1. You can install the [axios](https://www.npmjs.com/package/axios) package using `npm i axios`
360
+
=== "Example Raw X-Ray Trace excerpt"
361
+
362
+
```json hl_lines="6 9 12-21"
363
+
{
364
+
"id": "22883fbc730e3a0b",
365
+
"name": "## index.handler",
366
+
"start_time": 1647956168.22749,
367
+
"end_time": 1647956169.0679862,
368
+
"subsegments": [
369
+
{
370
+
"id": "ab82ab2b7d525d8f",
371
+
"name": "httpbin.org",
372
+
"start_time": 1647956168.407,
373
+
"end_time": 1647956168.945,
374
+
"http": {
375
+
"request": {
376
+
"url": "https://httpbin.org/status/200",
377
+
"method": "GET"
378
+
},
379
+
"response": {
380
+
"status": 200,
381
+
"content_length": 0
382
+
}
383
+
},
384
+
"namespace": "remote"
385
+
}
386
+
]
387
+
}
388
+
```
389
+
336
390
## Advanced
337
391
338
392
### Disabling response auto-capture
@@ -361,7 +415,7 @@ This is useful when you need a feature available in X-Ray that is not available
361
415
362
416
=== "index.ts"
363
417
364
-
```typescript hl_lines="6"
418
+
```typescript hl_lines="7"
365
419
import { Logger } from '@aws-lambda-powertools/logger';
366
420
import { Tracer } from '@aws-lambda-powertools/tracer';
367
421
@@ -379,4 +433,4 @@ Tracer is disabled by default when not running in the AWS Lambda environment - T
379
433
380
434
* Use annotations on key operations to slice and dice traces, create unique views, and create metrics from it via Trace Groups
381
435
* Use a namespace when adding metadata to group data more easily
382
-
* Annotations and metadata are added to the current subsegment opened. If you want them in a specific subsegment, [create one](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-subsegments.html#xray-sdk-nodejs-subsegments-lambda) via the escape hatch mechanism
436
+
* Annotations and metadata are added to the currently open subsegment. If you want them in a specific subsegment, [create one](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-subsegments.html#xray-sdk-nodejs-subsegments-lambda) via the escape hatch mechanism
|**POWERTOOLS_LOG_DEDUPLICATION_DISABLED**| Disables log deduplication filter protection to use Pytest Live Log feature |[Logger](./core/logger)|`false`|
0 commit comments