Skip to content

Commit 24ad4e1

Browse files
cursoragentclaude
andcommitted
fix(node-native): Strip non-serializable fields from ScopeData before passing to native module
The native module requires serializable data for cross-thread communication. ScopeData contains non-serializable fields (eventProcessors, span, attachments) that could cause serialization failures. This fix extracts only the serializable fields that are actually used by the watchdog thread. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0742247 commit 24ad4e1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/node-native/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ export interface WorkerStartData extends ThreadBlockedIntegrationOptions {
4040

4141
export interface ThreadState {
4242
session: Session | undefined;
43-
scope: ScopeData;
43+
scope: Partial<ScopeData>;
4444
debugImages: Record<string, string>;
4545
}

packages/node-native/src/event-loop-block-integration.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ function getLocalScopeData(): ScopeData {
5454
return globalScope;
5555
}
5656

57+
/**
58+
* Extracts only the serializable fields from ScopeData that can be passed to the native module.
59+
* Removes non-serializable fields like eventProcessors (functions), span (complex object), and attachments.
60+
*/
61+
function getSerializableScopeData(scopeData: ScopeData): Partial<ScopeData> {
62+
return {
63+
tags: scopeData.tags,
64+
attributes: scopeData.attributes,
65+
extra: scopeData.extra,
66+
user: scopeData.user,
67+
contexts: scopeData.contexts,
68+
level: scopeData.level,
69+
fingerprint: scopeData.fingerprint,
70+
propagationContext: scopeData.propagationContext,
71+
conversationId: scopeData.conversationId,
72+
};
73+
}
74+
5775
type IntegrationInternal = { start: () => void; stop: () => void };
5876

5977
function poll(enabled: boolean, clientOptions: ClientOptions): void {
@@ -62,7 +80,9 @@ function poll(enabled: boolean, clientOptions: ClientOptions): void {
6280
// We need to copy the session object and remove the toJSON method so it can be sent to the worker
6381
// serialized without making it a SerializedSession
6482
const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;
65-
const scope = getLocalScopeData();
83+
const scopeData = getLocalScopeData();
84+
// Strip non-serializable fields from scope data before passing to native module
85+
const scope = getSerializableScopeData(scopeData);
6686
// message the worker to tell it the main event loop is still running
6787
threadPoll(enabled, { session, scope, debugImages: getFilenameToDebugIdMap(clientOptions.stackParser) });
6888
} catch {

0 commit comments

Comments
 (0)