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
9 changes: 9 additions & 0 deletions packages/react-native-vega/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,31 @@ else()
)
endif()
FetchContent_MakeAvailable(Datadog)
include(cmake/DatadogLoggingCompatibility.cmake)
datadog_vega_patch_logging_registration("${datadog_SOURCE_DIR}")

set(HEADERS
kepler/turbo-modules/generated/DdRumSpec.h
kepler/turbo-modules/DdRum.h
kepler/turbo-modules/RumBridge.h
kepler/turbo-modules/generated/DdLogsSpec.h
kepler/turbo-modules/DdLogs.h
kepler/turbo-modules/LoggingConfiguration.h
kepler/turbo-modules/generated/DdSdkSpec.h
kepler/turbo-modules/DdSdk.h
kepler/turbo-modules/EnumParsers.h
kepler/turbo-modules/AttributeConverter.h
kepler/turbo-modules/DatadogGlobalState.h
kepler/turbo-modules/FeatureAttributes.h
kepler/turbo-modules/HttpJsProxy.h
)

set(SOURCES
kepler/turbo-modules/generated/DdRumSpec.cpp
kepler/turbo-modules/DdRum.cpp
kepler/turbo-modules/generated/DdLogsSpec.cpp
kepler/turbo-modules/DdLogs.cpp
kepler/turbo-modules/LoggingConfiguration.cpp
kepler/turbo-modules/generated/DdSdkSpec.cpp
kepler/turbo-modules/DdSdk.cpp
kepler/turbo-modules/EnumParsers.cpp
Expand Down
36 changes: 35 additions & 1 deletion packages/react-native-vega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,

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.

Just flagging that these new paragraphs are added at the end of the ### C++ SDK 0.7.0 limitations section. Could you confirm if that's the expected location? If not, suggesting to add an H2 heading such as ## Logs and user and account context before the DdLogs paragraph, matching the existing ## Manual RUM and global attributes heading, so the logging content and its compatibility subsection get their own section.

message, stack and attributes. `DdSdkReactNative` supports setting, updating and
clearing user/account information. Native failures leave JavaScript context
Comment on lines +79 to +81

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
`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
`DdLogs` forwards debug, info, warn, and error logs, with optional error kind,
message, stack, and attributes. `DdSdkReactNative` supports setting, updating,
and clearing user and account information. Native failures leave JavaScript context

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

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
`bundleLogsWithRum` to control RUM correlation (defaults to `true`). Initialization
is added separately; importing these APIs does not initialize the SDK. Logs are
`bundleLogsWithRum` to control RUM correlation (defaults to `true`). This package
does not initialize the SDK, and importing these APIs does not initialize it. Logs are

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

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
logging-only attributes. This uses the same compatibility source as Vega builds
and requires the SDK and include paths described above.
logging-only attributes. The test uses the same compatibility source as Vega builds
and requires `DATADOG_CPP_SOURCE_DIR`, `KEPLER_INCLUDE_DIR`, and `NODE_API_INCLUDE_DIR`.

119 changes: 119 additions & 0 deletions packages/react-native-vega/__tests__/DdLogsVega.test.ts
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();
});
});
Loading