Repository navigation
[RUM-20337] feat: Add Vega logging and user/account context #1579
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
Open
cdn34dd
wants to merge
4
commits into
carlosnogueira/RUM-20336/add-vega-rum-and-global-attributes
from
carlosnogueira/RUM-20337/add-vega-logging-and-user-account-context
+1,091
−13
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,7 +47,8 @@ continuous actions, start and stop resources, report errors, update view | |||||||||||||
| attributes, stop a session, report full app display, and track feature operations. | ||||||||||||||
|
|
||||||||||||||
| `DdSdkReactNative.addAttribute`, `addAttributes`, `removeAttribute`, and | ||||||||||||||
| `removeAttributes` update global RUM attributes and the shared JavaScript context. | ||||||||||||||
| `removeAttributes` update global RUM and logging attributes and the shared | ||||||||||||||
| JavaScript context. They also work when only logging is enabled. | ||||||||||||||
| View attributes take precedence over global attributes until 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 | ||||||||||||||
|
|
@@ -74,3 +75,36 @@ containing `Kepler/` and `JsonContainer/`), and `NODE_API_INCLUDE_DIR` to the te | |||||||||||||
| 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. | ||||||||||||||
|
|
||||||||||||||
| `DdLogs` forwards debug, info, warn and error logs, with optional error kind, | ||||||||||||||
| message, stack and attributes. `DdSdkReactNative` supports setting, updating and | ||||||||||||||
| clearing user/account information. Native failures leave JavaScript context | ||||||||||||||
|
Comment on lines
+79
to
+81
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
|
||||||||||||||
| unchanged and do not reject into application code. | ||||||||||||||
|
|
||||||||||||||
| The native initializer must call `configureLogging(core, logsConfiguration)` | ||||||||||||||
| when a logs configuration is present, before starting the core. The logger uses | ||||||||||||||
| `bundleLogsWithRum` to control RUM correlation (defaults to `true`). Initialization | ||||||||||||||
| is added separately; importing these APIs does not initialize the SDK. Logs are | ||||||||||||||
|
Comment on lines
+86
to
+87
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
|
||||||||||||||
| ignored until the native logger has been configured. | ||||||||||||||
|
|
||||||||||||||
| The optional log `source` argument does not change the C++ logger's source. | ||||||||||||||
| Custom fingerprints are kept in attributes but do not control native error | ||||||||||||||
| grouping in C++ SDK 0.7.0. Error symbolication and JavaScript error enrichment | ||||||||||||||
| are added separately. | ||||||||||||||
|
|
||||||||||||||
| Anonymous user attributes are supported through `addUserExtraInfo`, matching | ||||||||||||||
| core. Account attributes require an account ID to be set first. | ||||||||||||||
|
|
||||||||||||||
| ### Logging registration compatibility | ||||||||||||||
|
|
||||||||||||||
| C++ SDK 0.7.0 returns non-null no-op objects when logging registration fails. | ||||||||||||||
| Vega builds compile a private copy of that source with nullable failure returns, | ||||||||||||||
| so failed registrations leave logging disabled. Repeated configuration keeps the | ||||||||||||||
| working logger. The dependency checkout is never edited, including when using | ||||||||||||||
| `Datadog_SOURCE_DIR`. The build rejects unexpected SDK versions or source changes | ||||||||||||||
| so this adjustment is reviewed when the C++ SDK is upgraded. | ||||||||||||||
|
|
||||||||||||||
| Set `VEGA_TEST_LOGGING_CONFIGURATION=ON` in the host test CMake configuration to | ||||||||||||||
| build the actual SDK and test failed registration, repeated configuration, and | ||||||||||||||
| logging-only attributes. This uses the same compatibility source as Vega builds | ||||||||||||||
| and requires the SDK and include paths described above. | ||||||||||||||
|
Comment on lines
+109
to
+110
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
|
||||||||||||||
119 changes: 119 additions & 0 deletions
119
packages/react-native-vega/__tests__/DdLogsVega.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * 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 type { ErrorSource } from '@datadog/mobile-react-native'; | ||
|
|
||
| import { DdLogs } from '../src/DdLogsVega'; | ||
|
|
||
| const mockNative = { log: jest.fn() }; | ||
| const mockGet = jest.fn(); | ||
| jest.mock('@amazon-devices/keplerscript-turbomodule-api', () => ({ | ||
| TurboModuleRegistry: { get: (...args: unknown[]) => mockGet(...args) } | ||
| })); | ||
|
|
||
| describe('Vega logs', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockGet.mockReturnValue(mockNative); | ||
| }); | ||
| it.each(['debug', 'info', 'warn', 'error'] as const)( | ||
| 'forwards %s logs and attributes', | ||
| async level => { | ||
| const context = { | ||
| count: 3, | ||
| enabled: false, | ||
| nested: { value: null } | ||
| }; | ||
| await DdLogs[level]('message', context); | ||
| expect(mockNative.log).toHaveBeenCalledWith( | ||
| level, | ||
| 'message', | ||
| '', | ||
| '', | ||
| '', | ||
| context | ||
| ); | ||
| await DdLogs[level]('default context'); | ||
| expect(mockNative.log).toHaveBeenLastCalledWith( | ||
| level, | ||
| 'default context', | ||
| '', | ||
| '', | ||
| '', | ||
| {} | ||
| ); | ||
| } | ||
| ); | ||
| it.each(['debug', 'info', 'warn', 'error'] as const)( | ||
| 'forwards %s error details without changing caller attributes', | ||
| async level => { | ||
| const context = Object.freeze({ custom: true }); | ||
| await DdLogs[level]( | ||
| 'message', | ||
| 'TypeError', | ||
| 'failure', | ||
| 'stack', | ||
| context, | ||
| 'group' | ||
| ); | ||
| expect(mockNative.log).toHaveBeenCalledWith( | ||
| level, | ||
| 'message', | ||
| 'TypeError', | ||
| 'failure', | ||
| 'stack', | ||
| { | ||
| custom: true, | ||
| '_dd.error.fingerprint': 'group' | ||
| } | ||
| ); | ||
| expect(context).toEqual({ custom: true }); | ||
| } | ||
| ); | ||
| it('handles error overloads with missing optional fields', async () => { | ||
| await DdLogs.error('message', undefined, undefined, 'stack'); | ||
| expect(mockNative.log).toHaveBeenCalledWith( | ||
| 'error', | ||
| 'message', | ||
| '', | ||
| '', | ||
| 'stack', | ||
| {} | ||
| ); | ||
| }); | ||
| it('accepts a source-only error overload without shifting attributes', async () => { | ||
| await DdLogs.error( | ||
| 'message', | ||
| undefined, | ||
| undefined, | ||
| undefined, | ||
| undefined, | ||
| undefined, | ||
| 'SOURCE' as ErrorSource | ||
| ); | ||
| expect(mockNative.log).toHaveBeenCalledWith( | ||
| 'error', | ||
| 'message', | ||
| '', | ||
| '', | ||
| '', | ||
| {} | ||
| ); | ||
| }); | ||
| it('ignores missing, throwing, and rejecting native modules', async () => { | ||
| mockGet.mockReturnValueOnce(null).mockImplementationOnce(() => { | ||
| throw Error('lookup'); | ||
| }); | ||
| await expect(DdLogs.info('message')).resolves.toBeUndefined(); | ||
| await expect(DdLogs.info('message')).resolves.toBeUndefined(); | ||
| mockNative.log.mockImplementationOnce(() => { | ||
| throw Error('call'); | ||
| }); | ||
| await expect(DdLogs.info('message')).resolves.toBeUndefined(); | ||
| mockNative.log.mockRejectedValueOnce(Error('rejected')); | ||
| await expect(DdLogs.info('message')).resolves.toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just flagging that these new paragraphs are added at the end of the
### C++ SDK 0.7.0 limitationssection. Could you confirm if that's the expected location? If not, suggesting to add an H2 heading such as## Logs and user and account contextbefore theDdLogsparagraph, matching the existing## Manual RUM and global attributesheading, so the logging content and its compatibility subsection get their own section.