Skip to content

feat(mail): SMTP code + retryable attrs on gomailer.send spans - #796

Draft
shyim wants to merge 1 commit into
mainfrom
cursor/mail-smtp-span-attrs-e6b9
Draft

feat(mail): SMTP code + retryable attrs on gomailer.send spans#796
shyim wants to merge 1 commit into
mainfrom
cursor/mail-smtp-span-attrs-e6b9

Conversation

@shyim

@shyim shyim commented Aug 12, 2026

Copy link
Copy Markdown
Member

Why

Production SES failures show up as generic gomailer.send error spans (451 4.4.2 Timeout waiting for data from client) with no structured way to filter soft vs hard SMTP failures in Datadog (see #790). Outcome counters from #793 help at the metric layer; this PR adds span attributes so APM queries can alert on SES 451 specifically without high-cardinality recipient data.

What

On each instrumented send attempt, when the error wraps *gomailer.TransportError with an SMTP code:

Attribute Type Meaning
messaging.gomailer.smtp_code int SMTP reply code (e.g. 451) — extends existing otelmw messaging.gomailer.* attrs
mail.retryable bool true for 4xx soft failures; false for 5xx permanent

Wiring: AfterSend middleware sits inside otelmw so attributes attach to the still-open gomailer.send span (otelmw already sets messaging.gomailer.outcome).

Not attached: recipient email, subject, or body.

Classification: IsRetryableSMTPCode treats 400–499 as retryable and 5xx as not (RFC 5321 transient vs permanent). Span status remains Error for now; this stands alone from any future error-taxonomy work.

Sample Datadog queries

SES 451 rate (APM spans):

service:shopmon-worker resource_name:gomailer.send @messaging.gomailer.smtp_code:451

Retryable soft failures only:

service:shopmon-worker resource_name:gomailer.send @mail.retryable:true

Monitor idea: alert when count of @messaging.gomailer.smtp_code:451 over a 15m window exceeds a threshold relative to successful messaging.gomailer.outcome:success (or use shopmon.mail.send{outcome} from #793 for cheaper volume, and this attr for code breakdown).

Test plan

  • Unit tests for SMTP code → retryable classification
  • Span wiring test (451 attrs on gomailer.send via otelmw + AfterSend)
  • mise run lint (local + CI)
  • mise run test (CI Lint and Test green)
Open in Web Open in Cursor 

Enrich gomailer.send OpenTelemetry spans with low-cardinality
messaging.gomailer.smtp_code and mail.retryable so Datadog can alert
on SES soft failures (e.g. 451) without recipient/subject cardinality.

Co-authored-by: Soner <github@shyim.de>
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