elastic / elastic/apm-agent-python

Transaction: Context Manager & Decorator

Aperta
#959 3 commenti 1 reazione 0 assegnatari Vedi su GitHub
agent-python
Lingua principale
Python
Stelle
431
Fork
239
Merge medio
5g 10h
PR unite (30g)
7

Descrizione

**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)
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.