Repository navigation
[RUM-20336] feat: Add Vega RUM APIs and global attributes #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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. | ||||||
|
|
||||||
| `startHttpProxy()` resolves to a cleanup function. Await it before starting the | ||||||
| native SDK so the JavaScript listener and native emitter are ready for uploads. | ||||||
|
|
@@ -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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| `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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| Calls resolve safely when the native module or RUM feature is unavailable. They | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggesting a minor clarification, but please confirm this is accurate
Suggested change
|
||||||
| 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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| - `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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggesting to use code font to mark
Suggested change
|
||||||
| 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. | ||||||
| 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 | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting a minor clarification