Skip to content

[Fix] attributeEncoders are not registered nor called - #1441

Merged
sbarrio merged 1 commit into
developfrom
sbarrio/fix/attribute-encoders-not-working
Sep 29, 2026
Merged

sbarrio merged 1 commit into
developfrom
sbarrio/fix/attribute-encoders-not-working

Conversation

@sbarrio

@sbarrio sbarrio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes #1426

attributeEncoders were not being properly registered nor called, even when set on the SDK configuration.

The main culprit of this was DdSdkInternal, which imported the Native SDK Spec and named it NativeDdSdk, used it on its own methods to properly wire calls from JS to the native SDK, but then, instead of exporting the DdSdkWrapper re-exported it as is, so when DdSdk.ts wrapped this export and exposed it as DdSdk it made it so calls to functions in DdSdk were directly being routed to the Native Spec, skipping the methods on DdSdkInternal altogether, including the attributeEncoders setup.

The fix is to properly import the spec as NativeDdSdkSpec, use it as such and then have DdSdkInternal export DdSdkWrapper, which is then wrapped as a singleton on DdSdk.ts.

This PR updates calls to NativeDdSdk as DdSdk across the board, makes it explicit when the NativeSpec is being called (on tests, mainly), adds missing mocks for unit tests and also adds a set of guarding tests to make sure that calls to DdSdk actually call the DdSdkInternal interface and then the native spec.

Motivation

Raised on #1426

Additional Notes

Tested locally on the example apps by adding a custom set of attributeEncoders:

Screenshot 2026-09-22 at 14 18 38

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

clearAllData: jest.fn().mockImplementation(
() => new Promise<void>(resolve => resolve())
) as jest.MockedFunction<DdNativeSdkType['clearAllData']>,
setAccountInfo: jest.fn().mockImplementation(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These mocks were missing.

import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
import { BufferSingleton } from '../../../sdk/DatadogProvider/Buffer/BufferSingleton';
import { NativeDdSdk } from '../../../sdk/DdSdkInternal';
import NativeDdSdkSpec from '../../../specs/NativeDdSdk';

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix has been applied across all tests. We should have always imported the native Spec from specs/NativeDdSdk but since DdSdkInternal wrongly exported it (instead of its own DdSdkWrapper) this import was technically correct, although very misleading.

This change makes it clear across the codebase.

@sbarrio
sbarrio force-pushed the sbarrio/fix/attribute-encoders-not-working branch from a7dce45 to bbfbcd1 Compare September 22, 2026 12:22
});
}
);
describe('routing through DdSdkWrapper', () => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new set of tests make sure that the DdSdkWrapper exported from DdsdkInternal is actually being called and not skipped.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bbfbcd1 | Docs | View more details | Give us feedback!

@sbarrio
sbarrio marked this pull request as ready for review September 22, 2026 14:28
Copilot AI lite review requested due to automatic review settings September 22, 2026 14:28
@sbarrio
sbarrio requested a review from a team as a code owner September 22, 2026 14:28

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.

Copilot review overview

🟡 Changes recommended

Unresolved moderate issues remain around unsupported-value handling, native-module null safety, and custom encoder initialization coverage.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes SDK initialization so configured attributeEncoders are registered and used through DdSdkWrapper.

Changes:

  • Routes SDK, RUM, telemetry, and buffer operations through the wrapper.
  • Updates native spec references, tests, and React Native mocks.
  • Adds wrapper-routing test coverage.
File Summary
packages/​core/​src/​sdk/​EventMappers/​EventMapper.ts Routes mapper telemetry through the wrapper.
packages/​core/​src/​sdk/​EventMappers/​__tests__/​EventMapper.test.ts Updates mapper telemetry assertions.
packages/​core/​src/​sdk/​DdSdkInternal.ts Registers encoders and delegates native calls; initialization coverage for custom encoders remains missing.
packages/​core/​src/​sdk/​DatadogProvider/​Buffer/​BoundedBuffer.ts Routes buffered telemetry through the wrapper.
packages/​core/​src/​sdk/​DatadogProvider/​Buffer/​__tests__/​BoundedBuffer.test.ts Updates buffered telemetry assertions.
packages/​core/​src/​rum/​instrumentation/​interactionTracking/​DdRumUserInteractionTracking.tsx Routes interaction telemetry through the wrapper; native-module null safety needs preservation.
packages/​core/​src/​rum/​DdRum.ts Routes RUM telemetry through the wrapper.
packages/​core/​src/​rum/​__tests__/​DdRum.test.ts Updates RUM telemetry assertions.
packages/​core/​src/​DdSdkReactNative.tsx Routes initialization through the wrapper; unsupported values can still throw, and custom encoder initialization coverage is incomplete.
packages/​core/​src/​__tests__/​rum/​instrumentation/​DdRumUserInteractionTracking.test.tsx Updates interaction tracking assertions.
packages/​core/​src/​__tests__/​DdSdkReactNative.test.tsx Updates native assertions and adds wrapper-routing tests.
packages/​core/​__mocks__/​react-native.ts Adds required native SDK method mocks.

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

Comment on lines +100 to 102
await DdSdk.initialize(
DdSdkReactNative.buildConfiguration(configuration, params)
);
@sbarrio
sbarrio merged commit 5d28c8e into develop Sep 29, 2026
16 checks passed
@sbarrio
sbarrio deleted the sbarrio/fix/attribute-encoders-not-working branch September 29, 2026 07:31
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.

attributeEncoders have never been registered (all v3 releases), and the unsupported-value drop path throws on prototype-less objects

3 participants