Skip to content

feat: timing spans - #276

Open
noahpodgurski wants to merge 2 commits into
traffic-contractsfrom
timing-spans
Open

noahpodgurski wants to merge 2 commits into
traffic-contractsfrom
timing-spans

Conversation

@noahpodgurski

Copy link
Copy Markdown
Collaborator

What's new

  • Add support for returning span timing data in any MLPA response. Simply add header debug-timing-key: <env.MLPA_DEBUG_TIMING_KEY> to the request.
  • RequestTimingsMiddleware is a new middleware which adds request profiling. It wraps the ASGI send callable and inspects http.response.start for response headers, then handles http.response.body messages: JSON bodies are collected, spans are added, and sent with an updated Content-Length. Streaming SSE chunks pass through immediately, with spans appended when the final DONE body message arrives.
  • Timing format returns at the top level of the response (for non streaming) and for successful streams, after data: [DONE], receive one additional data: {"spans": [...]} event.

Examples:

Non streaming

"spans": [
    {
      "name": "total",
      "start_ms": 0.0,
      "duration_ms": 717.08
    },
    {
      "name": "auth",
      "start_ms": 0.84,
      "duration_ms": 0.52
    },
    {
      "name": "traffic_contract",
      "start_ms": 1.38,
      "duration_ms": 0.0
    },
    {
      "name": "db",
      "start_ms": 1.38,
      "duration_ms": 3.06
    },
    {
      "name": "upstream",
      "start_ms": 4.5,
      "duration_ms": 711.26
    }
]

Streaming

data: {"spans": [{"name": "total", "start_ms": 0.0, "duration_ms": 1311.5}, {"name": "auth", "start_ms": 1.06, "duration_ms": 238.21}, {"name": "traffic_contract", "start_ms": 239.65, "duration_ms": 0.01}, {"name": "db", "start_ms": 239.79, "duration_ms": 19.7}, {"name": "upstream", "start_ms": 259.87, "duration_ms": 1051.05}]}

https://mozilla-hub.atlassian.net/browse/AIPLAT-1287

@noahpodgurski
noahpodgurski requested a review from a team as a code owner September 17, 2026 14:40
Comment thread src/mlpa/core/request_timings.py Outdated
@noahpodgurski

Copy link
Copy Markdown
Collaborator Author

/build-pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants