Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/react-native-vega/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ endif()
FetchContent_MakeAvailable(Datadog)

set(HEADERS
kepler/turbo-modules/generated/DdRumSpec.h
kepler/turbo-modules/DdRum.h
kepler/turbo-modules/RumBridge.h
kepler/turbo-modules/generated/DdSdkSpec.h
kepler/turbo-modules/DdSdk.h
kepler/turbo-modules/EnumParsers.h
Expand All @@ -59,6 +62,8 @@ set(HEADERS
)

set(SOURCES
kepler/turbo-modules/generated/DdRumSpec.cpp
kepler/turbo-modules/DdRum.cpp
kepler/turbo-modules/generated/DdSdkSpec.cpp
kepler/turbo-modules/DdSdk.cpp
kepler/turbo-modules/EnumParsers.cpp
Expand Down
40 changes: 38 additions & 2 deletions packages/react-native-vega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This private package provides the native bridge and HTTP transport for Vega OS.
The bridge uses the Datadog C++ SDK and Kepler TurboModules. Native upload
requests are forwarded through JavaScript `fetch`; responses are returned to the
native upload thread. SDK initialization and feature APIs will be added
separately.
native upload thread. Manual RUM and global attribute APIs are available; SDK
initialization and automatic instrumentation are added separately.
Comment on lines +6 to +7

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.

Suggesting a minor clarification

Suggested change
native upload thread. Manual RUM and global attribute APIs are available; SDK
initialization and automatic instrumentation are added separately.
native upload thread. This package provides manual RUM and global attribute APIs.
It does not include SDK initialization or automatic instrumentation.


`startHttpProxy()` resolves to a cleanup function. Await it before starting the
native SDK so the JavaScript listener and native emitter are ready for uploads.
Expand Down Expand Up @@ -38,3 +38,39 @@ Build the native module with the Vega SDK installed:
cd packages/react-native-vega
vega build -b Release
```

## Manual RUM and global attributes

Import `DdRum` and `DdSdkReactNative` from `@datadog/mobile-react-native-vega`.
After RUM is initialized, use `DdRum` to start and stop views, record discrete or
continuous actions, start and stop resources, report errors, update view
attributes, stop a session, report full app display, and track feature operations.

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.

Suggested change
attributes, stop a session, report full app display, and track feature operations.
attributes, stop a session, report when the app is fully displayed, and track feature operations.


`DdSdkReactNative.addAttribute`, `addAttributes`, `removeAttribute`, and
`removeAttributes` update global RUM attributes and the shared JavaScript context.
View attributes take precedence over global attributes until removed or the view

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.

Suggested change
View attributes take precedence over global attributes until removed or the view
View attributes take precedence over global attributes until they are removed or the view

ends. JSON-compatible values retain their types, including nested objects,
arrays, numbers, booleans, and null. Singular attribute calls wrap the value for
the bridge; that wrapper is removed before passing it to the C++ SDK.

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.

Suggested change
the bridge; that wrapper is removed before passing it to the C++ SDK.
the bridge, and the bridge removes that wrapper before passing the value to the C++ SDK.


Calls resolve safely when the native module or RUM feature is unavailable. They

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.

Suggesting a minor clarification, but please confirm this is accurate

Suggested change
Calls resolve safely when the native module or RUM feature is unavailable. They
`DdRum` and `DdSdkReactNative` calls resolve without error when the native module or RUM feature is unavailable. They

are not buffered for later initialization. Native calls keep bridge order and use
the C++ SDK's existing event queue.

### C++ SDK 0.7.0 limitations

- `addTiming`, `addViewLoadingTime`, and `addFeatureFlagEvaluation` are safe no-ops.
- `getCurrentSessionId` resolves to `undefined`; the SDK does not expose a getter.
- Event timestamps come from the native SDK. Optional `timestampMs` arguments are
accepted for compatibility but do not override that clock.
- Custom error fingerprints are accepted but are not supported by the native SDK.

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.

Suggested change
- Custom error fingerprints are accepted but are not supported by the native SDK.
- Custom error fingerprints are accepted but ignored, because the native SDK does not support them.

- `BACK` actions map to the C++ SDK's `Custom` action type.
- Event mappers, JavaScript error enrichment, and tracing helpers are not provided
by this manual wrapper.

Attribute conversion tests can run on the host with dd-sdk-cpp 0.7.0 and the Vega

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.

Suggesting to use code font to mark dd-sdk-cpp

Suggested change
Attribute conversion tests can run on the host with dd-sdk-cpp 0.7.0 and the Vega
Attribute conversion tests can run on the host with `dd-sdk-cpp` 0.7.0 and the Vega

SDK headers installed. Pass `DATADOG_CPP_SOURCE_DIR`, `KEPLER_INCLUDE_DIR` (a root
containing `Kepler/` and `JsonContainer/`), and `NODE_API_INCLUDE_DIR` to the test
CMake configuration. Keep platform system headers separate from those roots when
building on macOS. The default host test command still runs the transport tests
without these SDK dependencies.
204 changes: 204 additions & 0 deletions packages/react-native-vega/__tests__/DdRumVega.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

import { AttributesSingleton } from '@datadog/mobile-react-native/internal';

import { DdRum, DdSdkReactNative } from '../src';

const mockRum = Object.fromEntries(
[
'startView',
'stopView',
'startAction',
'stopAction',
'addAction',
'startResource',
'stopResource',
'addError',
'addViewAttribute',
'removeViewAttribute',
'addViewAttributes',
'removeViewAttributes',
'reportAppFullyDisplayed',
'stopSession',
'startFeatureOperation',
'succeedFeatureOperation',
'failFeatureOperation'
].map(name => [name, jest.fn()])
);
const mockSdk = Object.fromEntries(
[
'addAttribute',
'removeAttribute',
'addAttributes',
'removeAttributes'
].map(name => [name, jest.fn()])
);
const mockGet = jest.fn();
jest.mock('@amazon-devices/keplerscript-turbomodule-api', () => ({
TurboModuleRegistry: { get: (...args: unknown[]) => mockGet(...args) }
}));

const context = {
number: 42.5,
bool: false,
nil: null,
list: [1, 'two'],
object: { value: 3 }
};

describe('Vega manual RUM APIs', () => {
beforeEach(() => {
jest.resetAllMocks();
AttributesSingleton.reset();
jest.spyOn(Date, 'now').mockReturnValue(1234);
mockGet.mockImplementation(name =>
name === 'DdRum' ? mockRum : mockSdk
);
});
afterEach(() => jest.restoreAllMocks());

it.each([
['startView', ['key', 'name'], ['key', 'name', {}, 1234]],
['stopView', ['key'], ['key', {}, 1234]],
['startAction', ['TAP', 'name'], ['TAP', 'name', {}, 1234]],
['stopAction', ['CUSTOM', 'name'], ['CUSTOM', 'name', {}, 1234]],
['addAction', ['SCROLL', 'name'], ['SCROLL', 'name', {}, 1234]],
[
'startResource',
['key', 'POST', 'https://example.com'],
['key', 'POST', 'https://example.com', {}, 1234]
],
[
'stopResource',
['key', 201, 'xhr'],
['key', 201, 'xhr', -1, {}, 1234]
],
[
'addError',
['message', 'SOURCE', 'stack'],
['message', 'SOURCE', 'stack', {}, 1234, '']
],
[
'startView',
['key', 'name', context, 99],
['key', 'name', context, 99]
],
[
'stopResource',
['key', 202, 'fetch', 128, context, 99],
['key', 202, 'fetch', 128, context, 99]
],
[
'addError',
['message', 'NETWORK', 'stack', context, 99, 'group'],
['message', 'NETWORK', 'stack', context, 99, 'group']
],
['addViewAttributes', [context], [context]],
['removeViewAttribute', ['key'], ['key']],
['removeViewAttributes', [['key', 'other']], [['key', 'other']]],
['reportAppFullyDisplayed', [], []],
['stopSession', [], []],
['startFeatureOperation', ['login', null], ['login', '', {}]],
[
'succeedFeatureOperation',
['login', 'key', context],
['login', 'key', context]
],
[
'failFeatureOperation',
['login', null, 'ABANDONED', context],
['login', '', 'ABANDONED', context]
]
])('forwards %s arguments', async (method, args, expected) => {
await (DdRum[method as keyof typeof DdRum] as (
...values: unknown[]
) => Promise<void>)(...args);
expect(mockGet).toHaveBeenCalledWith('DdRum');
expect(mockRum[method]).toHaveBeenCalledWith(...expected);
});

it.each([null, false, 0, 'text', [1, null], { value: { nested: true } }])(
'wraps a singular view attribute without changing its value: %p',
async value => {
await DdRum.addViewAttribute('key', value);
expect(mockRum.addViewAttribute).toHaveBeenCalledWith('key', {
value
});
}
);

it('handles unavailable, throwing, and rejecting bridges without failing the app', async () => {
mockGet.mockReturnValueOnce(null).mockImplementationOnce(() => {
throw new Error('lookup');
});
await expect(DdRum.startView('key', 'name')).resolves.toBeUndefined();
await expect(DdRum.stopSession()).resolves.toBeUndefined();
mockRum.addAction.mockImplementationOnce(() => {
throw new Error('bridge');
});
await expect(
DdRum.addAction('CUSTOM', 'action')
).resolves.toBeUndefined();
mockRum.stopSession.mockRejectedValueOnce(new Error('native'));
await expect(DdRum.stopSession()).resolves.toBeUndefined();
await DdRum.startView('retry', 'retry');
expect(mockRum.startView).toHaveBeenCalledWith(
'retry',
'retry',
{},
1234
);
});

it('keeps unsupported APIs safe and does not resolve a native module for them', async () => {
await DdRum.addTiming('ready');
await DdRum.addViewLoadingTime(true);
await DdRum.addFeatureFlagEvaluation('flag', true);
await expect(DdRum.getCurrentSessionId()).resolves.toBeUndefined();
expect(mockGet).not.toHaveBeenCalled();
});

it('adds, replaces, and removes global attributes in native and shared JS context', async () => {
await DdSdkReactNative.addAttributes(context);
expect(mockSdk.addAttributes).toHaveBeenCalledWith(context);
await DdSdkReactNative.addAttribute('number', { value: false });
expect(mockSdk.addAttribute).toHaveBeenCalledWith('number', {
value: { value: false }
});
expect(AttributesSingleton.getInstance().getAttributes()).toEqual({
...context,
number: { value: false }
});
await DdSdkReactNative.removeAttribute('number');
await DdSdkReactNative.removeAttributes(['list', 'object']);
expect(mockSdk.removeAttribute).toHaveBeenCalledWith('number');
expect(mockSdk.removeAttributes).toHaveBeenCalledWith([
'list',
'object'
]);
expect(AttributesSingleton.getInstance().getAttributes()).toEqual({
bool: false,
nil: null
});
});

it('does not change shared attributes when native cannot accept the update', async () => {
mockGet.mockReturnValueOnce(null);
await DdSdkReactNative.addAttribute('missing', true);
mockSdk.addAttributes.mockResolvedValueOnce(false);
await DdSdkReactNative.addAttributes(context);
mockSdk.addAttribute.mockRejectedValueOnce(new Error('native'));
await DdSdkReactNative.addAttribute('failed', true);
expect(AttributesSingleton.getInstance().getAttributes()).toEqual({});
await DdSdkReactNative.addAttribute('keep', true);
mockSdk.removeAttributes.mockResolvedValueOnce(false);
await DdSdkReactNative.removeAttributes(['keep']);
expect(AttributesSingleton.getInstance().getAttributes()).toEqual({
keep: true
});
});
});
2 changes: 2 additions & 0 deletions packages/react-native-vega/kepler/AutoLinkInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#include <Kepler/turbomodule/KeplerTurboModuleRegistration.h>
#include "turbo-modules/DdSdk.h"
#include "turbo-modules/DdRum.h"

extern "C" {
__attribute__((visibility("default"))) void
autoLinkKeplerTurboModulesV1() noexcept {
KEPLER_REGISTER_TURBO_MODULE(DdSdkTurboModule, DdSdk);
KEPLER_REGISTER_TURBO_MODULE(DdRumTurboModule, DdRum);
}
}
Loading