Open History to see the last commit
1# Relay observability
2
3> For maintainers. Using T3 Code? See [docs/user](../user/).
4
5The relay Alchemy stack owns a shared Axiom trace setup:
6
7- `t3-code-relay-traces-prod`, the OpenTelemetry trace dataset shared by the Worker, mobile app, and
8 first-party relay clients
9- `t3-code-relay-otel-ingest-prod`, the dataset-scoped Worker ingest token
10- `t3-code-mobile-otel-ingest-prod`, the dataset-scoped mobile ingest token
11- `t3-code-relay-client-otel-ingest-prod`, the dataset-scoped first-party relay-client ingest token
12- `t3-code-relay-recent-spans-prod`, a view of recent request and endpoint spans
13
14Alchemy stages append their sanitized stage name to isolate resources, for example
15`t3-code-relay-traces-dev-julius` for a personal stage.
16
17Deploy from `infra/relay` with the normal Alchemy workflow:
18
19```sh
20vp run deploy
21```
22
23Alchemy resolves account-level Axiom deployment credentials through its provider. At runtime, the
24Worker receives only its scoped ingest token. Mobile and relay clients use their own separately
25provisioned scoped ingest tokens.
26
27The Worker emits Effect's built-in HTTP server spans plus endpoint and database child spans.
28Effect's OpenTelemetry exporter stores semantic HTTP attributes below the `attributes.` prefix.
29For example:
30
31```apl
32['t3-code-relay-traces-prod']
33| where kind == 'server'
34| extend endpoint = column_ifexists('attributes.http.route', ''),
35 customAttributes = column_ifexists('attributes.custom', dynamic({}))
36| project _time, name, trace_id, duration,
37 ['attributes.http.request.method'],
38 ['attributes.url.path'],
39 ['attributes.http.response.status_code'],
40 endpoint,
41 relayOperation = customAttributes['relay']['operation']
42| order by _time desc
43| limit 200
44```
45
46The provisioned view also reads the endpoint from `attributes.http.route`. Relay-specific span
47annotations are stored under `attributes.custom`; `relay.operation` is one of the emitted custom
48attributes.
49
50Agents should prefer the provisioned view or APL queries for completed incidents instead of
51tailing the Cloudflare Worker. The stack does not provision a separate query token. Responders who
52need scripted query access use the authorized account-level `AXIOM_TOKEN` together with
53`AXIOM_ORG_ID`; scoped ingest tokens remain write-only credentials for their producers.
54
55DPoP proof failures include the stable `relay.dpop.failure_code` span attribute. A `time_window`
56failure means that a signed proof was too old or too far in the future for the relay's allowed
57window. It can point to a date or time problem on either device, but it can also result from a
58delayed request. The client uses this category, and the absence of a category from an older relay,
59to decide whether clock skew is confirmed or only one possible cause.
60
61## Webhooks
62
63A public webhook request is one `relay.hooks.forward` span. Its `relay.hook.outcome` says what
64happened: `forwarded`, `held`, `rate_limited`, `inbox_full`, `not_found`, `payload_too_large`,
65`environment_unavailable`, or `environment_timeout`. `relay.hook.endpoint_key` identifies the
66managed endpoint, and with it the environment. On a forward, `relay.hook.upstream_status` or
67`relay.hook.upstream_error` records the environment's answer, and
68`relay.hook.upstream_outcome` what it did with the request (`accepted`, `duplicate`,
69`prompt_too_long`, `queue_full`, `rejected_signature`, `expired`, `disabled`, ...), from its
70`x-t3-hook-outcome` response header. A held request's delivery records the same on its
71`relay.inbox.deliver` span. The relay sends its own `traceparent` with each forward and drops any a
72sender supplied, and signs each forward (`x-t3-relay-delivery`) so the environment trusts the
73relay's delivery id, receive time and trace context only from the relay, so on environments that export to T3 Connect, the environment's
74`ScheduledTaskService.triggerWebhook` span lands in the same trace. `relay.hook.rate_limit` says which
75budget ran out: `endpoint` or `hook`. `relay.hook.rate_limiter_failed_open` is set when the
76Cloudflare rate limiter was unavailable and the request went through unlimited.
77
78Held requests are handled in the endpoint's `HookInboxObject`, and each call into it is its own
79trace, not a child of the forward span: `relay.inbox.hold`, `relay.inbox.wake`, and
80`relay.inbox.deliver` for each alarm run. Each carries `relay.hook.endpoint_key`, so they join to
81forwards. The details are on the child spans: `HookInboxStore.hold` carries
82`relay.inbox.refused` when the inbox refused a request (`max_per_hook`, `max_requests`,
83`max_bytes`, or `already_held`). `HookInboxStore.deliverDue` carries `relay.inbox.run_result`
84(`drained`, `more_pending`, `busy`, or `unreachable`), how many requests it sent and delivered,
85the consecutive failures behind the retry delay, the longest time a delivered request waited, and
86the backlog left. A run that errored outright has `relay.inbox.run_result = failed` on the root
87`relay.inbox.deliver` span instead.
88
89Questions these answer:
90
91```apl
92// Webhook outcomes per hour
93['t3-code-relay-traces-prod']
94| where name == 'relay.hooks.forward'
95| summarize count() by bin(_time, 1h), outcome = tostring(['attributes.custom']['relay.hook.outcome'])
96
97// Inboxes stuck behind an unreachable environment, by endpoint
98['t3-code-relay-traces-prod']
99| where name == 'HookInboxStore.deliverDue'
100| extend c = ['attributes.custom']
101| where tostring(c['relay.inbox.run_result']) == 'unreachable'
102| project trace_id, failures = toint(c['relay.inbox.consecutive_failures']),
103 backlog = toint(c['relay.inbox.held_count'])
104| join kind=inner (
105 ['t3-code-relay-traces-prod']
106 | where name == 'relay.inbox.deliver'
107 | project trace_id, endpoint = tostring(['attributes.custom']['relay.hook.endpoint_key'])
108 ) on trace_id
109| summarize runs = count(), failures = max(failures), backlog = max(backlog) by endpoint
110```