elastic / elastic/apm-agent-python

Transaction: Context Manager & Decorator

Offen
#959 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
agent-python
Vorherrschende Sprache
Python
Sterne
431
Forks
239
Ø Merge
5 T. 10 Std.
Gemergte PRs (30 T.)
7

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.