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
Copy file name to clipboardExpand all lines: docs/core/tracer.md
+35-167
Original file line number
Diff line number
Diff line change
@@ -42,39 +42,22 @@ You can quickly start by initializing `Tracer` and use `capture_lambda_handler`
42
42
43
43
**Annotations** are key-values associated with traces and indexed by AWS X-Ray. You can use them to filter traces and to create [Trace Groups](https://aws.amazon.com/about-aws/whats-new/2018/11/aws-xray-adds-the-ability-to-group-traces/) to slice and dice your transactions.
44
44
45
-
```python hl_lines="7" title="Adding annotations with put_annotation method"
**Metadata** are key-values also associated with traces but not indexed by AWS X-Ray. You can use them to add additional context for an operation using any native object.
56
50
57
-
```python hl_lines="8" title="Adding arbitrary metadata with put_metadata method"
@@ -144,14 +100,8 @@ Tracer automatically patches all [supported libraries by X-Ray](https://docs.aws
144
100
145
101
If you're looking to shave a few microseconds, or milliseconds depending on your function memory configuration, you can patch specific modules using `patch_modules` param:
146
102
147
-
```python hl_lines="7" title="Example of explicitly patching boto3 and requests only"
```python hl_lines="12-13" title="Ignoring certain HTTP endpoints from being traced"
146
+
--8<--"examples/tracer/src/ignore_endpoints.py"
229
147
```
230
148
231
149
### Tracing aiohttp requests
232
150
233
151
???+ info
234
152
This snippet assumes you have aiohttp as a dependency
235
153
236
-
You can use `aiohttp_trace_config` function to create a valid [aiohttp trace_config object](https://docs.aiohttp.org/en/stable/tracing_reference.html). This is necessary since X-Ray utilizes aiohttp trace hooks to capture requests end-to-end.
from aws_lambda_powertools.tracing import aiohttp_trace_config
244
-
245
-
tracer = Tracer()
154
+
You can use `aiohttp_trace_config` function to create a valid [aiohttp trace_config object](https://docs.aiohttp.org/en/stable/tracing_reference.html){target="_blank"}. This is necessary since X-Ray utilizes [aiohttp](https://docs.aiohttp.org/en/stable/){target="_blank"} trace hooks to capture requests end-to-end.
246
155
247
-
asyncdefaiohttp_task():
248
-
asyncwith aiohttp.ClientSession(trace_configs=[aiohttp_trace_config()]) as session:
249
-
asyncwith session.get("https://httpbin.org/json") as resp:
@@ -257,16 +163,8 @@ You can use `tracer.provider` attribute to access all methods provided by AWS X-
257
163
258
164
This is useful when you need a feature available in X-Ray that is not available in the Tracer utility, for example [thread-safe](https://github.com/aws/aws-xray-sdk-python/#user-content-trace-threadpoolexecutor), or [context managers](https://github.com/aws/aws-xray-sdk-python/#user-content-start-a-custom-segmentsubsegment).
259
165
260
-
```python hl_lines="7" title="Tracing a code block with in_subsegment escape hatch"
261
-
from aws_lambda_powertools import Tracer
262
-
263
-
tracer = Tracer()
264
-
265
-
@tracer.capture_lambda_handler
266
-
defhandler(event, context):
267
-
with tracer.provider.in_subsegment('## custom subsegment') as subsegment:
268
-
ret = some_work()
269
-
subsegment.put_metadata('response', ret)
166
+
```python hl_lines="14" title="Tracing a code block with in_subsegment escape hatch"
167
+
--8<--"examples/tracer/src/sdk_escape_hatch.py"
270
168
```
271
169
272
170
### Concurrent asynchronous functions
@@ -276,25 +174,8 @@ def handler(event, context):
276
174
277
175
A safe workaround mechanism is to use `in_subsegment_async` available via Tracer escape hatch (`tracer.provider`).
0 commit comments