Skip to content

Commit b4e0c67

Browse files
Integrate adlrb/logs-node (#3914) into staging-43
Integrated commit sha: 2da32f9 Co-authored-by: dd-devflow[bot] <129370481+dd-devflow[bot]@users.noreply.github.com>
2 parents ec3c412 + 2da32f9 commit b4e0c67

File tree

6 files changed

+6
-35
lines changed

6 files changed

+6
-35
lines changed

packages/core/src/tools/globalObject.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,4 @@ export function getGlobalObject<T = typeof globalThis>(): T {
4848
// eslint-disable-next-line local-rules/disallow-side-effects
4949
export const globalObject = getGlobalObject<GlobalObject>()
5050

51-
export const isBrowserEnvironment = 'document' in globalObject
5251
export const isWorkerEnvironment = 'WorkerGlobalScope' in globalObject
53-
export const isNodeEnvironment =
54-
// @ts-expect-error for Node.js-specific globals that are not present in browser environments
55-
typeof process !== 'undefined' && process.versions !== null && process.versions.node !== null

packages/logs/src/boot/preStartLogs.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { TrackingConsentState } from '@datadog/browser-core'
22
import {
3-
isNodeEnvironment,
43
createBoundedBuffer,
54
canUseEventBridge,
65
display,
@@ -56,10 +55,6 @@ export function createPreStartStrategy(
5655

5756
return {
5857
init(initConfiguration, errorStack) {
59-
if (isNodeEnvironment) {
60-
return
61-
}
62-
6358
if (!initConfiguration) {
6459
display.error('Missing configuration')
6560
return

packages/logs/src/boot/startLogs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { TrackingConsentState, BufferedObservable, BufferedData, PageMayExitEvent } from '@datadog/browser-core'
22
import {
3-
isBrowserEnvironment,
43
Observable,
54
sendToExtension,
65
createPageMayExitObservable,
@@ -12,6 +11,7 @@ import {
1211
TelemetryService,
1312
createIdentityEncoder,
1413
startUserContext,
14+
isWorkerEnvironment,
1515
} from '@datadog/browser-core'
1616
import { startLogsSessionManager, startLogsSessionManagerStub } from '../domain/logsSessionManager'
1717
import type { LogsConfiguration } from '../domain/configuration'
@@ -55,7 +55,7 @@ export function startLogs(
5555

5656
const reportError = startReportError(lifeCycle)
5757
// Page exit is not observable in worker environments (no window/document events)
58-
const pageMayExitObservable = !isBrowserEnvironment
58+
const pageMayExitObservable = isWorkerEnvironment
5959
? new Observable<PageMayExitEvent>()
6060
: createPageMayExitObservable(configuration)
6161

packages/logs/src/domain/networkError/networkErrorCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { FetchResolveContext, XhrCompleteContext } from '@datadog/browser-core'
22
import {
3-
isBrowserEnvironment,
3+
isWorkerEnvironment,
44
Observable,
55
ErrorSource,
66
initXhrObservable,
@@ -28,7 +28,7 @@ export function startNetworkErrorCollection(configuration: LogsConfiguration, li
2828

2929
// XHR is not available in web workers, so we use an empty observable that never emits
3030
const xhrSubscription = (
31-
!isBrowserEnvironment ? new Observable<XhrCompleteContext>() : initXhrObservable(configuration)
31+
isWorkerEnvironment ? new Observable<XhrCompleteContext>() : initXhrObservable(configuration)
3232
).subscribe((context) => {
3333
if (context.state === 'complete') {
3434
handleResponse(RequestType.XHR, context)

packages/rum-core/src/boot/preStartRum.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { TrackingConsentState, DeflateWorker, Context, ContextManager, BoundedBuffer } from '@datadog/browser-core'
22
import {
3-
isNodeEnvironment,
43
createBoundedBuffer,
54
display,
65
canUseEventBridge,
@@ -101,10 +100,6 @@ export function createPreStartStrategy(
101100
}
102101

103102
function doInit(initConfiguration: RumInitConfiguration, errorStack?: string) {
104-
if (isNodeEnvironment) {
105-
return
106-
}
107-
108103
const eventBridgeAvailable = canUseEventBridge()
109104
if (eventBridgeAvailable) {
110105
initConfiguration = overrideInitConfigurationForBridge(initConfiguration)

test/apps/vanilla/app.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,8 @@ if (typeof window !== 'undefined') {
1717
window.RUM_INIT()
1818
}
1919
} else {
20-
// Document is always generated by the SSR environment
21-
// @ts-ignore If document is mocked, the SDK executes further enough to throw an error
22-
globalThis.document = {}
23-
24-
// Check if the SDK sent any events
25-
;(globalThis as any).__ddBrowserSdkExtensionCallback = () => {
26-
throw new Error('the SDK should not send events')
27-
}
28-
2920
// compat test
30-
31-
datadogLogs.init({ clientToken: 'xxx', beforeSend: undefined, telemetrySampleRate: 100 })
32-
datadogRum.init({ clientToken: 'xxx', applicationId: 'xxx', beforeSend: undefined, telemetrySampleRate: 100 })
21+
datadogLogs.init({ clientToken: 'xxx', beforeSend: undefined })
22+
datadogRum.init({ clientToken: 'xxx', applicationId: 'xxx', beforeSend: undefined })
3323
datadogRum.setUser({ id: undefined })
34-
35-
// Check the SDK is not started
36-
if (datadogLogs.getInternalContext() || datadogRum.getInternalContext()) {
37-
throw new Error('SDK should not start on SSR environments')
38-
}
3924
}

0 commit comments

Comments
 (0)