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
Generator functions will not be traced for reasons explained [here](../advanced/generators.md).
26
26
27
+
## Only tracing functions above a minimum duration
28
+
29
+
In most situations you don't want to trace every single function call in your application.
30
+
The most convenient way to exclude functions from tracing is with the [`min_duration`][logfire.Logfire.install_auto_tracing(min_duration)] argument. For example, the code snippet above will only trace functions that take longer than 0.01 seconds.
31
+
This means you automatically get observability for the heavier parts of your application without too much overhead or data. Note that there are some caveats:
32
+
33
+
- A function will only start being traced after it runs longer than `min_duration` once. This means that:
34
+
- If it runs faster than `min_duration` the first few times, you won't get data about those first calls.
35
+
- The first time that it runs longer than `min_duration`, you also won't get data about that call.
36
+
- After a function runs longer than `min_duration` once, it will be traced every time it's called afterwards, regardless of how long it takes.
37
+
- Measuring the duration of a function call still adds a small overhead. For tiny functions that are called very frequently, it's best to still use the `@no_auto_trace` decorator to avoid any overhead. Auto-tracing with `min_duration` will still work for other undecorated functions.
38
+
39
+
If you want to trace all function calls from the beginning, set `min_duration=0`.
40
+
27
41
## Filtering modules to trace
28
42
29
43
The `modules` argument can be a list of module names.
@@ -89,20 +103,3 @@ Renaming/aliasing either the function or module won't work.
89
103
Neither will calling this indirectly via another function.
90
104
91
105
This decorator simply returns the argument unchanged, so there is zero runtime overhead.
92
-
93
-
## Only tracing functions above a minimum duration
94
-
95
-
A more convenient way to exclude functions from tracing is to set the [`min_duration`][logfire.Logfire.install_auto_tracing(min_duration)] argument, e.g:
96
-
97
-
```python
98
-
# Only trace functions that take longer than 0.1 seconds
This means you automatically get observability for the heavier parts of your application without too much overhead or data. Note that there are some caveats:
103
-
104
-
- A function will only start being traced after it runs longer than `min_duration` once. This means that:
105
-
- If it runs faster than `min_duration` the first few times, you won't get data about those first calls.
106
-
- The first time that it runs longer than `min_duration`, you also won't get data about that call.
107
-
- After a function runs longer than `min_duration` once, it will be traced every time it's called afterwards, regardless of how long it takes.
108
-
- Measuring the duration of a function call still adds a small overhead. For tiny functions that are called very frequently, it's best to still use the `@no_auto_trace` decorator to avoid any overhead. Auto-tracing with `min_duration` will still work for other undecorated functions.
0 commit comments