Skip to content

Commit 4989f44

Browse files
antonpirkerlizokm
andauthored
Added docs for "functions_to_trace" option. (#6520)
Co-authored-by: Liza Mock <[email protected]>
1 parent 3dc9afe commit 4989f44

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/platforms/common/configuration/options.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,17 @@ If <PlatformIdentifier name="trace-propagation-targets" /> is not provided, trac
775775

776776
</ConfigKey>
777777

778+
<ConfigKey name="functions-to-trace" supported={["python"]}>
779+
780+
An optional list of functions that should be set up for performance monitoring. For each function in the list, a span will be created when the function is executed.
781+
Functions in the list are represented as strings containing the fully qualified name of the fuction.
782+
783+
This is a convenient option, making it possible to have one central place for configuring what functions to trace, instead of having manual instrumentation scattered all over your code base.
784+
785+
To learn more, see the [Custom Instrumentation](/platforms/python/performance/instrumentation/custom-instrumentation/#define-span-creation-in-a-central-place) documentation.
786+
787+
</ConfigKey>
788+
778789
<ConfigKey name="trace-options-requests" supported={["java"]}>
779790

780791
<PlatformSection supported={["java"]}>

src/platforms/python/common/performance/instrumentation/custom-instrumentation.mdx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Sentry SDK for Python does a very good job of auto instrumenting your applic
88

99
## Add a Transaction
1010

11-
Adding transactions will allow you to instrument and capture certain regions of your code.
11+
Adding transactions will allow you to instrument and capture certain regions of your code.
1212

1313
<Note>
1414

@@ -106,6 +106,35 @@ def eat_slice(slice):
106106
swallow()
107107
```
108108

109+
## Define Span Creation in a Central Place
110+
111+
To avoid having custom performance instrumentation code scattered all over your code base, pass a parameter <PlatformIdentifier name="functions-to-trace" /> to your `sentry_sdk.init()` call.
112+
113+
```python
114+
import sentry_sdk
115+
116+
functions_to_trace = [
117+
"myrootmodule.eat_slice",
118+
"myrootmodule.swallow",
119+
"myrootmodule.chew",
120+
"myrootmodule.someothermodule.another.some_function",
121+
"myrootmodule.SomePizzaClass.some_method",
122+
]
123+
124+
sentry_sdk.init(
125+
dsn="___PUBLIC_DSN___",
126+
functions_to_trace=functions_to_trace,
127+
)
128+
```
129+
130+
Now, whenever a function specified in `functions_to_trace` will be executed, a span will be created and attached as a child to the currently running span.
131+
132+
<Alert level="warning" title="Important">
133+
134+
To enable performance monitoring for the functions specified in `functions_to_trace`, the SDK needs to load the function modules. Be aware, there may be code being executed in modules during module loading. To avoid this, use the method described above to trace your functions.
135+
136+
</Alert>
137+
109138
## Accessing the Current Transaction
110139

111140
To change data in an already ongoing transaction, use `Hub.current.scope.transaction`. This property will return a transaction if there's one running, otherwise it will return `None`.

0 commit comments

Comments
 (0)