Skip to content

fix(spend-permission): await wrapped async util in withTelemetry#362

Open
anilkaracay wants to merge 1 commit into
base:masterfrom
anilkaracay:fix/with-telemetry-async-handling
Open

fix(spend-permission): await wrapped async util in withTelemetry#362
anilkaracay wants to merge 1 commit into
base:masterfrom
anilkaracay:fix/with-telemetry-async-handling

Conversation

@anilkaracay

Copy link
Copy Markdown

Problem

withTelemetry (the HOF wrapping the spend-permission utilities) is synchronous and does not
await the wrapped call. Because all 8 wrapped utilities are async, the completed telemetry
event fires on promise creation (wrong timing) and async rejections bypass the sync try/catch,
so error telemetry is never logged.

Change

Make the returned wrapper async and await the call inside the existing try/catch, mirroring
the repo's correct sibling HOFs (withMeasurement, withSignerMeasurement). The
telemetry === false passthrough is preserved. Public behavior is unchanged (the returned
promise resolves/rejects identically); only internal telemetry timing and error capture are fixed.

Testing

Added first-ever coverage in withTelemetry.test.ts (6 tests), written test-first:

  • completed event fires only AFTER the wrapped async fn resolves (failed before the fix)

  • error event is logged on async rejection (failed before the fix)

  • started fires before completion (regression guard)

  • telemetry === false passthrough returns the raw fn and logs nothing

  • resolved value propagates unchanged

  • function name derivation

  • yarn test --run: full suite green (account package 74 files / 1006 tests; the 8 wrapped
    utilities' existing tests still pass)

  • yarn format: clean (Biome)

  • yarn build:packages: type-checks

Closes #361

@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@anilkaracay anilkaracay marked this pull request as ready for review July 10, 2026 05:25
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.

withTelemetry does not await wrapped async utilities (wrong completion timing, dropped error telemetry)

2 participants