elastic / elastic/apm-agent-python

Transaction: Context Manager & Decorator

Open
#959 3 comments 1 reaction 0 assignees View on GitHub
agent-python
Dominant language
Python
Stars
431
Forks
239
Avg merge
5d 10h
Merged PRs (30d)
7

Description

**Is your feature request related to a problem? Please describe.**
No, it is not.

**Describe the solution you'd like**
Just for increasing the convenience of using Transactions, it would be nice to have an option for using them as a context manager and/or decorator, instead of calling `start_transaction` and `end_transaction` every time. It would be something like this:

```
with transaction('my_transaction_type'):
calling_my_transaction()
```
as a decorator it would look like this
```
@elasticapm.transaction('my_transaction_type', 'my_transaction_name')
def this_is_my_view_method():
pass
```

**Describe alternatives you've considered**
The alternative is use what is already provided (`start_transaction` and `end_transaction`)

**Additional context**
Just to illustrate, the context manager implementation would be similar to the following code
```
def transaction(self, transaction_type, transaction_name=None, trace_parent=None, start=None):
transaction = self.begin_transaction(
transaction_type,
transaction_name=transaction_name,
trace_parent=trace_parent,
start=start
)
yield
self.tracer.end_transaction(transaction.name)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.