aws / aws/aws-xray-sdk-python

Xray not capturing stack traces in latest version of Flask

Offen
#269 2 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @srprash Auf GitHub ansehen
bug pending release
Vorherrschende Sprache
Python
Sterne
338
Forks
147
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

The `after_request` handler is closing the segment before the `teardown_request` handler is called so the stack trace isn't captured.

It looks like this behavior changed as of Flask v1.1.0 (specifically https://github.com/pallets/flask/pull/3266)

Currently using:
- aws-xray-sdk v2.6.0
- flask v1.1.2

Here is our current work around:

```python
app = Flask(__name__)

def wrap_exception_handler(handler):
def wrapped_function(exp):
if not isinstance(exp, HTTPException) or exp.code >= 500:
try:
stack = stacktrace.get_stacktrace(
limit=xray_recorder.max_trace_back,
)

xray_recorder.current_segment().add_exception(exp, stack)
except Exception:
app.logger.error('Failed to add stack trace to xray segment')

return handler(exp)
return wrapped_function

app.handle_user_exception = wrap_exception_handler(app.handle_user_exception)
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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