Repository navigation
feat(emails): add Headers and Tags to code sends - #415
Conversation
|
@PostHog review |
|
@mayteio PostHog Review is reviewing this pull request. |
posthog-dotnet Compliance ReportDate: 2026-12-02T14:38:36.567411+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
SDK performance: posthog-dotnetBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Compared 108 metric rows; 108 rows shown in all results. Omitted or shortened data remain in |
dustinbyrne
left a comment
There was a problem hiding this comment.
Looks good: additive, matches sdk-specs emails and the backend headers/tags serializer, and keys and values go out unchanged.
Follow-up: Once this ships, posthog.com needs a couple of updates:
contents/docs/libraries/dotnet/index.mdx(theSendCodeEmailOptionstable) needsHeadersandTagsrows.- The test-sender refusal lists in
workflows/email/test-sender.mdx:31,workflows/transactional/retries-and-errors.mdx:40andworkflows/reference/limits.mdx:116leave out headers and tags, although the backend refuses them withsandbox_fields_unsupported(transactional_email.pyL959–969) andsend-from-code.mdx:222lists them.
Not blocking for this PR.
AI-assisted review.
| /// <remarks> | ||
| /// At most 8 headers. PostHog takes <c>In-Reply-To</c>, <c>References</c>, <c>List-Unsubscribe</c>, | ||
| /// <c>List-Unsubscribe-Post</c>, <c>List-Id</c> and any <c>X-</c> header, except <c>X-PostHog-</c> and | ||
| /// <c>X-SES-</c> headers. A value is at most 870 ASCII characters without line breaks; only an <c>X-</c> header |
There was a problem hiding this comment.
Suggestion: These remarks read as PostHog's full rule list, but the backend refuses a few more cases with invalid_header:
- names that differ only by case (
code_send_fields.pyL287–291,names_ignore_case). A defaultDictionary<string, string>allows{ ["X-Ref"] = "a", ["x-ref"] = "b" }. - an empty value (L325,
0 < len(value)) - any control character, not only line breaks (L48/L331)
- an
X-name with characters other than letters, digits and hyphens, or longer than 77 characters (L58/L322)
The Tags remarks already say "1 to 256", so consider matching that here, for example:
"At most 8 headers, each named once, ignoring case. PostHog takes In-Reply-To, References, List-Unsubscribe, List-Unsubscribe-Post, List-Id and any X- header named with letters, digits and hyphens, except X-PostHog- and X-SES- headers. A value is 1 to 870 ASCII characters without line breaks or other control characters; only an X- header takes non-ASCII text, at most 200 UTF-8 bytes."
This is docs-only. The client should keep not checking these (sdk-specs emails L179). The published send-from-code page (L176) has the same gap.
💡 Motivation and Context
headersandtagson a code send (PostHog/posthog#144854, PostHog/posthog#144855). The .NET SDK can't set them yet.Changes
SendCodeEmailOptionstakesHeadersandTags, each anIReadOnlyDictionary<string, string>. The client sends each as given and leaves a null or empty dictionary out of the body. The server owns names, values and limits, and the XML docs list them with the refusal codes (invalid_header,invalid_tag,sandbox_fields_unsupported,field_not_accepted).Rejected: an SDK check of the template-send case, because
SendTemplateEmailOptionshas no such properties, so a template send can't carry them by construction. A test pins that. The spec's "not a mapping" check is also impossible with a typed dictionary.PublicAPI.Unshipped.txt.PostHogminor, so 2.32.0 if no other minor release lands first.Read yourself: the two body entries, L912-L920: is an empty dictionary left out?
Merge risk: low
Alignment: matches sdk-specs#191.
Impact: additive optional fields; unset sends are byte-for-byte unchanged.
Verification: unit tests cover the body, empty values and the template type.
Rollback cost: two-way door: revert before release, or deprecate.
Error detection: a server refusal throws
EmailExceptionwith its code.Tier: non-critical
💚 How did you test it?
What was proven, and what not
EmailSenderchange (1 of 4 red), and pass with it.dotnet restore --locked-mode,bin/fmt --check, Release build, and the fullUnitTestssuite on net10.0 and net8.0 pass locally.The tests check the exact JSON body, as the other code-send tests do.
Known issues
📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code wrote the change test-first from the sdk-specs contract at the assignee's request. The docs on posthog.com describe these fields from the XML docs here.