base / base/account-sdk

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

Open Beginner friendly
#361 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
172
Forks
207
Avg merge
49m
Merged PRs (30d)
1

Description

### Summary
`withTelemetry` (the HOF wrapping the spend-permission utilities) is a synchronous function
that does not `await` the wrapped call. Since all wrapped utilities are `async`, this causes
two telemetry defects for every wrapped utility:

1. The **completed** event (`logSpendPermissionUtilCompleted`) fires the moment the promise is
created, not when it resolves. Completion timing/duration is therefore wrong.
2. An **async rejection bypasses** the synchronous `try/catch`, so `logSpendPermissionUtilError`
is never called and error telemetry is silently lost.

Public behavior is unaffected (the returned promise resolves/rejects identically) — only the
internal telemetry timing and error capture are wrong.

### Affected
All 8 wrapped utilities: `requestSpendPermission`, `fetchPermission`, `fetchPermissions`,
`prepareRevokeCallData`, `getPermissionStatus`, `requestRevoke`, `getHash`, `prepareSpendCallData`.

### Evidence
The repo's two sibling telemetry HOFs, `withMeasurement` and `withSignerMeasurement`, already
handle this correctly: they are `async` and `await` the handler inside the `try/catch`.
`withTelemetry` is the lone outlier.

### Proposed fix
Make the returned wrapper `async` and `await` the call inside the existing `try/catch`,
mirroring the two sibling HOFs, while preserving the `telemetry === false` passthrough.

### Location
`packages/account-sdk/src/interface/public-utilities/spend-permission/withTelemetry.ts`

Contributor guide

Open the contributing guide

Research direction

Start in packages/account-sdk/src/interface/public-utilities/spend-permission/withTelemetry.ts and compare its wrapper with the sibling withMeasurement and withSignerMeasurement HOFs. Preserve the telemetry === false passthrough, then verify that completion telemetry waits for async utilities and that rejected calls produce error telemetry for the affected utilities.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.