<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe" -->

---
title: Tracing Flask with wrapture | daily.dev
description: Instrumenting a Flask application with wrapture to trace each HTTP request as a single tree, capturing the view, template renders, and nested service calls...
canonical: https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Tracing Flask with wrapture | daily.dev
og:description: Instrumenting a Flask application with wrapture to trace each HTTP request as a single tree, capturing the view, template renders, and nested service calls...
og:url: https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe
og:image: https://api.daily.dev/og/posts/GfrmLfkFe.png
og:image:alt: Tracing Flask with wrapture
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracing Flask with wrapture

**[Planet Python](https://daily.dev/sources/planetpython)** · 8 min read · 0 upvotes · 0 comments

## Summary

Instrumenting a Flask application with wrapture to trace each HTTP request as a single tree, capturing the view, template renders, and nested service calls beneath the request event. Because Flask routes status and body through start_response and an iterable rather than a return value, and swallows exceptions into 500 responses via handle_exception, a plain call-based binding on the WSGI app would miss the real failure reason. The wrapture-instrumentation package adds a single [[instrument]] entry for Flask that installs bindings at three points: the WSGI middleware on wsgi_app, an observed wrapper around registered view functions, and a binding on handle_exception that attaches the causing exception back to the enclosing request event. Additional settings, ignore_paths and lifecycle, let health checks and before/after_request callbacks be silenced to cut noise, while the request event itself exposes result, duration, method, path, route pattern and endpoint for sinks or tests to consume.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://grahamdumpleton.me/posts/2026/09/tracing-flask-with-wrapture>

## Questions this post answers

### How can I capture the exception that caused a Flask 500 response when a view's exception is caught internally by Flask?

Bind to Flask's handle_exception function rather than the view or WSGI application, since Flask catches the exception on its way out of the view and hands it to handle_exception before building the 500 response. A binding there can note the exception against the nearest enclosing request event using a note_exception call aimed at the current request-kind event, so both the view and request show the KeyError even though the WSGI layer sees only a normal return.

_Anyone debugging silent 500s in Flask can compare tracing approaches surfaced on daily.dev._

### How do I stop health check requests from flooding my Flask request tracing logs?

Configure ignore_paths on the Flask instrumentation entry, listing paths like /health, so matching requests run and respond normally but record nothing at all rather than just suppressing the top-level request event. This matters because silencing only the request event would leave the view, lifecycle callbacks, and template renders as orphaned anonymous roots with no parent request above them.

_Developers tuning noisy observability output can find practical fixes like this via daily.dev._

### How does wrapture instrument a Flask application without modifying its code?

An Instrumentation class runs hooks when Flask is imported, patching three points: constructing a Flask instance installs a recording WSGI middleware on wsgi_app so every app instance is covered including those made by application factories, registering a route substitutes an observed version of the view function, and handle_exception gets a binding that notes escaped exceptions.

_Teams evaluating zero-code tracing options for Python frameworks can track approaches like this on daily.dev._

## Similar posts on daily.dev

- [Introducing wrapture](https://daily.dev/posts/introducing-wrapture-ohj3cvcws) · Planet Python · 1 upvotes · 1 comments
- [Finding slow code with wrapture](https://daily.dev/posts/finding-slow-code-with-wrapture-shmedg3wu) · Planet Python · 0 upvotes · 0 comments
- [Zero-code tracing with wrapture](https://daily.dev/posts/zero-code-tracing-with-wrapture-yy6qgb3me) · Planet Python · 1 upvotes · 0 comments
- [Invisible Failures: The Python Server Mistake We Made in Production](https://daily.dev/posts/invisible-failures-the-python-server-mistake-we-made-in-production-ujme9h4jg) · ITNEXT · 1 upvotes · 0 comments
- [Beyond callables in wrapture](https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi) · Planet Python · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#devops](https://daily.dev/tags/devops), [#observability](https://daily.dev/tags/observability), [#flask](https://daily.dev/tags/flask)

[View this post on daily.dev](https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Tracing Flask with wrapture","url":"https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe"},"datePublished":"2026-09-09T01:49:50.721Z","dateModified":"2026-09-14T07:33:37.916Z","description":"Instrumenting a Flask application with wrapture to trace each HTTP request as a single tree, capturing the view, template renders, and nested service calls...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bd17f0f3224a098f01e1b7916a0812dc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bd17f0f3224a098f01e1b7916a0812dc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet Python","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet Python","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/eac3cc584cb043b5a242d13752bd3d0c","url":"https://daily.dev/sources/planetpython"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,devops,observability,flask","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet Python","item":"https://daily.dev/sources/planetpython"},{"@type":"ListItem","position":3,"name":"Tracing Flask with wrapture"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/tracing-flask-with-wrapture-gfrmlfkfe#faq","mainEntity":[{"@type":"Question","name":"How can I capture the exception that caused a Flask 500 response when a view's exception is caught internally by Flask?","acceptedAnswer":{"@type":"Answer","text":"Bind to Flask's handle_exception function rather than the view or WSGI application, since Flask catches the exception on its way out of the view and hands it to handle_exception before building the 500 response. A binding there can note the exception against the nearest enclosing request event using a note_exception call aimed at the current request-kind event, so both the view and request show the KeyError even though the WSGI layer sees only a normal return. Anyone debugging silent 500s in Flask can compare tracing approaches surfaced on daily.dev."}},{"@type":"Question","name":"How do I stop health check requests from flooding my Flask request tracing logs?","acceptedAnswer":{"@type":"Answer","text":"Configure ignore_paths on the Flask instrumentation entry, listing paths like /health, so matching requests run and respond normally but record nothing at all rather than just suppressing the top-level request event. This matters because silencing only the request event would leave the view, lifecycle callbacks, and template renders as orphaned anonymous roots with no parent request above them. Developers tuning noisy observability output can find practical fixes like this via daily.dev."}},{"@type":"Question","name":"How does wrapture instrument a Flask application without modifying its code?","acceptedAnswer":{"@type":"Answer","text":"An Instrumentation class runs hooks when Flask is imported, patching three points: constructing a Flask instance installs a recording WSGI middleware on wsgi_app so every app instance is covered including those made by application factories, registering a route substitutes an observed version of the view function, and handle_exception gets a binding that notes escaped exceptions. Teams evaluating zero-code tracing options for Python frameworks can track approaches like this on daily.dev."}}]}
```

