Skip to content

feat(aws-kinesis): flag-gated diagnostic latency logging (STRATCONN-6690) - #3946

Draft
harsh-joshi99 wants to merge 1 commit into
mainfrom
hjoshi/stratconn-6690-kinesis-diagnostic-logging
Draft

feat(aws-kinesis): flag-gated diagnostic latency logging (STRATCONN-6690)#3946
harsh-joshi99 wants to merge 1 commit into
mainfrom
hjoshi/stratconn-6690-kinesis-diagnostic-logging

Conversation

@harsh-joshi99

@harsh-joshi99 harsh-joshi99 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Customer Whatnot (STRATCONN-6690) sees intermittent 504 Gateway Timeout on the Amazon Kinesis destination. The 504 is not the AWS API Gateway 29s integration timeout — it's Segment's internal execution deadline aborting the request. Two things made this un-diagnosable:

  1. The delivery path makes 3 sequential calls per batch with no credential caching — 2× STS AssumeRole (intermediary role, then customer role) + 1 Kinesis PutRecords. Their cumulative tail latency breaches the deadline.
  2. The abort branch threw RequestTimeoutError before any log or metric, so the failure was completely invisible in Grafana/Loki — which is why the investigation stalled.

This PR adds diagnostic instrumentation to attribute the timeout to a specific phase (STS#1 / STS#2 / PutRecords), gated behind a Flagon flag so there's zero footprint until enabled.

Changes

All emits are gated on features['actions-aws-kinesis-advanced-logging'] (nothing logs/emits when the flag is off — no behavior change). Follows the existing salesforce-advanced-logging precedent.

Flagon gate: https://flagon.segment.com/families/centrifuge-destinations/gates/actions-aws-kinesis-advanced-logging

  • aws-kinesis/send/index.ts — read the flag off features, pass a boolean into send.
  • aws-kinesis/utils.ts — time the STS-total and PutRecords phases; track the in-flight phase; on AbortError emit actions_kinesis.request_timeout + an error log with the phase/elapsed before throwing (closes the silent-failure gap).
  • lib/AWS/sts.ts — split the two assume-role calls into sts_intermediary_ms vs sts_customer_ms (optional StsLogging arg; assumeRole is Kinesis-only, testAuthentication unaffected).

New metrics

actions_kinesis.sts_intermediary_ms, sts_customer_ms, sts_assume_role_ms, kinesis_put_records_ms (histograms), and actions_kinesis.request_timeout (counter).

Sample log lines

[aws-kinesis] assume_role phase=sts_intermediary_ms durationMs=142 region=us-east-1
[aws-kinesis] assume_role phase=sts_customer_ms durationMs=118 region=us-east-1
[aws-kinesis] put_records ok durationMs=87 totalMs=352 stream=<streamName> region=us-east-1 batch=340
[aws-kinesis] aborted (execution deadline exceeded) phase=kinesis elapsedMs=9800 stream=<streamName> region=us-east-1 batch=340

PII

None. Logs contain only durations, stream name, AWS region, batch size (a count), and phase label — no payload, partition keys, or credentials.

Testing

  • 5 new cases in aws-kinesis/__tests__/utils.test.ts (flag off = silent; flag on success = metrics + log; logging context forwarded; abort-with-flag = timeout metric + error log + still throws; abort-without-flag = silent + still throws).
  • 2 new cases in lib/AWS/__test__/index.test.ts (per-call latency metrics on/off).
  • Typecheck clean; lint 0 errors.

Rollout

  1. Gate already exists in Flagon (default off): actions-aws-kinesis-advanced-logging.
  2. Enable scoped to Whatnot's source 6421c0a60cc41c0c431f13d9.
  3. Read the per-phase metrics to identify which call breaches the deadline. Expected follow-up (separate PR): cache assumed credentials on the Kinesis path so 2 of the 3 calls disappear in steady state.

🤖 Generated with Claude Code

…NN-6690)

Kinesis deliveries intermittently fail with a 504 that is not the AWS API
Gateway 29s timeout but Segment's internal execution deadline aborting the
request. The delivery path makes 3 sequential calls per batch with no
credential caching (2x STS AssumeRole + 1 Kinesis PutRecords), and the abort
branch previously threw RequestTimeoutError before any log/metric, so the
failure was invisible in Grafana.

Adds instrumentation behind the `actions-aws-kinesis-advanced-logging` Flagon
gate (all emits gated; no behavior change when off):
- Per-phase latency: sts_intermediary_ms, sts_customer_ms, sts_assume_role_ms,
  kinesis_put_records_ms (histograms + info logs).
- Abort branch now emits actions_kinesis.request_timeout + an error log with
  the in-flight phase before throwing, closing the silent-failure gap.

Logs contain only durations, stream name, AWS region, batch size, and phase
label — no PII. Follows the salesforce-advanced-logging precedent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 17, 2026 05:20

Copilot AI left a comment

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.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds flag-gated diagnostic instrumentation to the AWS Kinesis destination to make “execution deadline exceeded” (internal 504) timeouts observable and attributable to STS vs. PutRecords phases.

Changes:

  • Plumbs a Flagon feature gate into the Kinesis send path to enable/disable advanced logging.
  • Adds per-phase latency histograms and timeout/error logging (AbortError) to pinpoint where deadlines are breached.
  • Splits STS assume-role latency into intermediary vs. customer role metrics.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/destination-actions/src/lib/AWS/sts.ts Adds optional StsLogging and emits per-assume-role latency metrics/logs.
packages/destination-actions/src/lib/AWS/test/index.test.ts Adds tests verifying STS per-call metrics/logging are gated by advancedLogging.
packages/destination-actions/src/destinations/aws-kinesis/utils.ts Adds phase tracking, abort diagnostics, and latency metrics for STS-total + PutRecords.
packages/destination-actions/src/destinations/aws-kinesis/send/index.ts Reads Flagon feature and passes advancedLogging into send/sendBatch.
packages/destination-actions/src/destinations/aws-kinesis/tests/utils.test.ts Adds tests for silent/verbose behavior and AbortError diagnostics under the gate.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +179 to +185
const start = Date.now()
const result = await stsClient.send(command)
if (logging?.advancedLogging && metric) {
const durationMs = Date.now() - start
logging.statsContext?.statsClient?.histogram(`actions_kinesis.${metric}`, durationMs, logging.statsContext?.tags)
logging.logger?.info(`[aws-kinesis] assume_role phase=${metric} durationMs=${durationMs} region=${region}`)
}
Comment on lines +57 to +58
const start = Date.now()
let phase: 'sts' | 'kinesis' = 'sts'
Comment on lines +65 to +67
if (advancedLogging) {
statsContext?.statsClient?.histogram('actions_kinesis.sts_assume_role_ms', Date.now() - start, tags)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants