Skip to content

Commit

Permalink
Added docs for "functions_to_trace" option. (#6520)
Browse files Browse the repository at this point in the history
Co-authored-by: Liza Mock <liza.mock@sentry.io>
antonpirker and lizokm authored Mar 28, 2023

Verified

This commit was signed with the committer’s verified signature.
amimart Arnaud Mimart
1 parent 3dc9afe commit 4989f44
Showing 2 changed files with 41 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/platforms/common/configuration/options.mdx
Original file line number Diff line number Diff line change
@@ -775,6 +775,17 @@ If <PlatformIdentifier name="trace-propagation-targets" /> is not provided, trac

</ConfigKey>

<ConfigKey name="functions-to-trace" supported={["python"]}>

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.
Functions in the list are represented as strings containing the fully qualified name of the fuction.

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.

To learn more, see the [Custom Instrumentation](/platforms/python/performance/instrumentation/custom-instrumentation/#define-span-creation-in-a-central-place) documentation.

</ConfigKey>

<ConfigKey name="trace-options-requests" supported={["java"]}>

<PlatformSection supported={["java"]}>
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ The Sentry SDK for Python does a very good job of auto instrumenting your applic

## Add a Transaction

Adding transactions will allow you to instrument and capture certain regions of your code.
Adding transactions will allow you to instrument and capture certain regions of your code.

<Note>

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

## Define Span Creation in a Central Place

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.

```python
import sentry_sdk

functions_to_trace = [
"myrootmodule.eat_slice",
"myrootmodule.swallow",
"myrootmodule.chew",
"myrootmodule.someothermodule.another.some_function",
"myrootmodule.SomePizzaClass.some_method",
]

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
functions_to_trace=functions_to_trace,
)
```

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.

<Alert level="warning" title="Important">

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.

</Alert>

## Accessing the Current Transaction

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`.

1 comment on commit 4989f44

@vercel
Copy link

@vercel vercel bot commented on 4989f44 Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

sentry-docs.sentry.dev
sentry-docs-git-master.sentry.dev
docs.sentry.io

Please sign in to comment.