Skip to content

Commit 86fc7aa

Browse files
authored
fix: correctly forward error payload to launchdarkly (#285)
## Summary Ensure that the SDK correctly reports the error payload to LaunchDarkly. ## How did you test this change? <img width="2209" height="1922" alt="image" src="https://github.com/user-attachments/assets/cb6977b3-b891-4f9a-a505-ed865d0338ec" /> ## Are there any deployment considerations? no <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Parses/merges error payload into span attributes and forwards it to LaunchDarkly error events; sets default error source to "frontend". > > - **Observe SDK (`sdk/observe.ts`)**: > - Merge JSON from `errorMsg.payload` into error span attributes and forward integrations a stringified `payload`. > - Set default error `source` to `"frontend"` in `recordError`. > - **LaunchDarkly Integration (`integrations/launchdarkly/index.ts`)**: > - Parse `error.payload` and include its fields in `LD_ERROR_EVENT` tracking payload. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit e33ef4f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent afcc5c5 commit 86fc7aa

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

sdk/highlight-run/src/integrations/launchdarkly/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,17 @@ export class LaunchDarklyIntegrationSDK implements IntegrationClient {
246246
}
247247

248248
error(sessionSecureID: string, error: ErrorMessage) {
249+
let payload: { [key: string]: string } = {}
250+
try {
251+
if (error.payload) {
252+
payload = JSON.parse(error.payload)
253+
}
254+
} catch (e) {}
255+
const { payload: _, ...errorWithoutPayload } = error
249256
this.client.track(LD_ERROR_EVENT, {
250-
...error,
257+
...errorWithoutPayload,
251258
sessionID: sessionSecureID,
259+
...payload,
252260
})
253261
}
254262

sdk/highlight-run/src/sdk/observe.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ export class ObserveSDK implements Observe {
221221
errorMsg: ErrorMessage,
222222
payload?: { [key: string]: string },
223223
) {
224+
try {
225+
if (errorMsg.payload) {
226+
payload = {
227+
...JSON.parse(errorMsg.payload),
228+
...(payload ? payload : {}),
229+
}
230+
}
231+
} catch (e) {}
224232
this.startSpan('highlight.exception', (span) => {
225233
// This is handled in the callsites, but this redundancy handles it from a pure
226234
// type safety perspective.
@@ -237,8 +245,12 @@ export class ObserveSDK implements Observe {
237245
...payload,
238246
})
239247
})
248+
const { payload: _, ...errorWithoutPayload } = errorMsg
240249
for (const integration of this._integrations) {
241-
integration.error(getPersistentSessionSecureID(), errorMsg)
250+
integration.error(getPersistentSessionSecureID(), {
251+
...errorWithoutPayload,
252+
payload: JSON.stringify(payload),
253+
})
242254
}
243255
}
244256

@@ -266,7 +278,7 @@ export class ObserveSDK implements Observe {
266278
event,
267279
type: type ?? 'custom',
268280
url: window.location.href,
269-
source: source ?? '',
281+
source: source ?? 'frontend',
270282
lineNumber: res[0]?.lineNumber ? res[0]?.lineNumber : 0,
271283
columnNumber: res[0]?.columnNumber ? res[0]?.columnNumber : 0,
272284
stackTrace: res,

0 commit comments

Comments
 (0)