Skip to content

Publish autogravity preview failures to Sentry with span context - #13681

Open
TorstenDittmann wants to merge 1 commit into
mainfrom
torsten/autogravity-sentry-spans-d666
Open

TorstenDittmann wants to merge 1 commit into
mainfrom
torsten/autogravity-sentry-spans-d666

Conversation

@TorstenDittmann

Copy link
Copy Markdown
Contributor

What does this PR do?

When gravity=auto failed — including oversized images that came back as 4xx from Autogravity and were remapped to a user-facing 500 — Sentry never received a usable event.

Two things were going wrong:

  1. The failure was filtered out. Autogravity HTTP errors keep the service status as the exception code (413, 400, …). Sentry only exports Appwrite exceptions that are publishable, or other errors with code 0 or >= 500. A 413 from a too-large payload was rewritten to 500 Server Error for the client, then dropped by the sampler.
  2. Span attributes were added too late. File id, bucket, size, crop gravity, and timing were recorded only after a successful transform, so even a published event had no image context.

This change:

  • Records file, dimension, crop, and download timing attributes before detection.
  • Stamps autogravity.cache, autogravity.bytes, autogravity.status, and autogravity.error on the current span when detection runs or fails.
  • Wraps Autogravity/Imagick detector failures as a publishable GENERAL_SERVER_ERROR (keeping the original exception as previous).
  • Promotes storage.bucket.id, storage.file.id, and autogravity.status to Sentry tags so oversized-image 500s can be filtered.

Test Plan

  • Unit: tests/unit/Autogravity/DetectorTest.php (cache hit/miss and 413 failure attributes on the current span)
  • Unit: tests/unit/Autogravity/ClientTest.php (testAnalyzePayloadTooLarge)
  • composer lint on the touched PHP files (environment here has no PHP/Composer; CI should run these)

Related PRs and Issues

  • Follow-up to automatic gravity (gravity=auto) preview work

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
Open in Web Open in Cursor 

Autogravity 4xx responses (for example 413 on oversized payloads) were
attached to the request span with that HTTP status. Sentry only exports
Appwrite exceptions that are publishable, or other errors with code 0 or
5xx, so those failures never arrived. File, crop, and timing attributes
were also added only after a successful transform.

Record identifying preview attributes before detection, stamp autogravity
cache/bytes/status on the span, and wrap detector failures as a
publishable 500 so oversized-image 500s can be debugged in Sentry.

Co-authored-by: Torsten Dittmann <TorstenDittmann@users.noreply.github.com>
@TorstenDittmann
TorstenDittmann marked this pull request as ready for review September 14, 2026 19:01
@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → torsten/autogravity-sentry-spans-d666 (after).

Metric Before After Change
🚀 Requests/sec 238.86 229.57 -3.9%
⏱️ Latency P50 74.1 ms 75.11 ms +1.4%
⏱️ Latency P95 166.97 ms 178.52 ms 🔴 +6.9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 75.11 178.52 14,535 229.57 +11.56
Account 149.35 271.49 765 12.67 +20.2
TablesDB 71.89 133.81 7,905 128.31 +5.63
Storage 70.03 153.54 3,825 63.52 +7.73
Functions 112.31 222.75 2,040 34.6 +18.65

Top API waits (after)

API request Max wait (ms)
account.name.update 486.34
functions.create 472.39
storage.files.create 411.12
storage.files.preview 392.43
functions.delete 377.96

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The runtime change appears sound, but the repository’s explicit testing requirement must be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 Tests Mirror Internal Telemetry
Fix with agent prompt
### Issue 1
tests/unit/Autogravity/DetectorTest.php:82-83
These tests assert private telemetry details, including exact span keys, byte-counting values, and internal span error state. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Replace these assertions with coverage at the exported Sentry-event boundary; this repository requirement must be satisfied before merging. The same pattern also appears in the failure assertions on lines 108–113.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • Moves file, dimensions, timing, and crop attributes ahead of automatic-gravity detection.
  • Records Autogravity cache, payload, status, error, and focal-point details.
  • Wraps detector failures as publishable general server errors while preserving the original throwable.
  • Promotes storage identifiers and Autogravity status to Sentry tags.
  • Adds client and detector coverage, although the detector tests violate the repository’s testing rule by mirroring internal telemetry implementation.

Reviews (1) · Last reviewed commit: "fix: publish autogravity preview failure..."

Comment on lines +82 to +83
$this->assertSame(\strlen('source-image'), $span->get('autogravity.bytes'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests Mirror Internal Telemetry

These tests assert private telemetry details, including exact span keys, byte-counting values, and internal span error state. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Replace these assertions with coverage at the exported Sentry-event boundary; this repository requirement must be satisfied before merging. The same pattern also appears in the failure assertions on lines 108–113.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Autogravity/DetectorTest.php
Line: 82-83

Comment:
**Tests Mirror Internal Telemetry**

These tests assert private telemetry details, including exact span keys, byte-counting values, and internal span error state. This violates the repository directive to test observable behavior rather than mirror source code or configuration. Replace these assertions with coverage at the exported Sentry-event boundary; this repository requirement must be satisfied before merging. The same pattern also appears in the failure assertions on lines 108–113.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

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