feat(webhook): add optional X-Ray instrumentation for GitHub event delivery latency - #5292
feat(webhook): add optional X-Ray instrumentation for GitHub event delivery latency#5292wadherv wants to merge 16 commits into
Conversation
…livery latency Add an opt-in `webhook_xray_github_latency_enabled` flag that adds an X-Ray annotation and a backdated synthetic "github" subsegment showing the delay between a GitHub workflow_job event's created_at and the webhook Lambda's invocation. Disabled by default since backdating trace timestamps is an unusual pattern; wired through the direct and eventbridge webhook submodules and the multi-runner module.
|
@wadherv your PR is removing some tf resource that are needed. Can you check please |
@edersonbrilhante issue is fixed, can you please review again |
|
I think this PR is addressing a broader observability problem with a feature-specific workaround.
Please rename this value to I also recommend removing The middleware should be composed at the Lambda handler boundary and exported with the wrapped handler, rather than being initialized as a side effect. This keeps the instrumentation separate from the webhook business logic and makes it reusable for other event types. X-Ray should represent the actual Lambda invocation and downstream SQS/EventBridge calls. The synthetic backdated GitHub subsegment may produce misleading trace semantics. |
implementing tracing via powertracer
|
@edersonbrilhante updated the code to use Middy middleware
|

Description
The
webhookLambda (lambdas/functions/webhook/src/webhook/index.ts) is the entry point for every GitHubworkflow_jobevent, but its X-Ray instrumentation only covers Lambda-internal and downstream-AWS-SDK timing. There is no visibility into the delivery/ingestion latency between when GitHub generated the event (workflow_job.created_at) and when the webhook Lambda actually began processing it — the gap could stem from GitHub's own delivery queue, network transit, API Gateway, or ingestion-side queuing/cold-start, and this instrumentation can't attribute it to either side by itself.We hit this directly: a workflow run was triggered by GitHub at
23:28:59but wasn't processed by our webhook Lambda until23:37:15— an ~8 minute gap — with no GitHub-side outage reported for that window. Diagnosing it required manually correlating the workflow run's GitHub timestamp against CloudWatch logs.This PR adds
instrumentGithubLatency(), called fromreadWorkflowJobEvent()(shared by bothpublishForRunnersandpublishOnEventBridge), which:workflow_job.created_atandDate.now().event_lag_ms) on the current segment via the sharedtracersingleton (@aws-github-runner/aws-powertools-util), so it's queryable/alertable directly.remote-namespace subsegment namedgithub, backdated to the event'screated_at, so the X-Ray service map shows a distinctgithubnode feeding into the webhook Lambda with a span representing the real end-to-end delay.The entire feature is disabled by default and gated behind a new boolean,
webhook_xray_github_latency_enabled(env varWEBHOOK_XRAY_GITHUB_LATENCY_ENABLED), since backdating a subsegment'sstart_timeis an unusual X-Ray pattern not every consumer of the module will want on by default. When the flag isfalse,instrumentGithubLatency()returns immediately — no annotation, no subsegment, zero behavior change for existing consumers.The new variable is threaded through the full config chain: root
variables.tf/main.tf→modules/webhook→ bothmodules/webhook/directandmodules/webhook/eventbridgesubmodules → the Lambda's environment block, and also throughmodules/multi-runnerfor consumers of that module.Test Plan
terraform fmt -check -recursiveclean.terraform validatepassing on the root module andmodules/multi-runner(pre-existing, unrelated deprecation warnings only).Durationcorrectly rolled up to the full backdated span,IsPartial: False, no fault/error flags, and the subsegment was promoted to a standalone linked segment in the trace (what renders as a distinct node in the Service Map).vitest/ESLint suite locally in this environment (nonode_modulesinstalled) — flagging for CI/reviewer to confirm.Related Issues
Addresses a gap identified in incident investigation; no visibility currently exists into GitHub-to-webhook delivery latency. (Link to feature-request issue to be added.)