Skip to content

[Innovation week] ✨ add extra slim package #3476

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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
830c8f0
✨ add extra slim package with navigation tracking and session management
thomas-lebeau Apr 8, 2025
9839843
✨ add 'rum-extra-slim' package to deployment utilities
thomas-lebeau Apr 8, 2025
c19089b
✨ add support for 'rum-extra-slim' in rule building
thomas-lebeau Apr 8, 2025
f57216e
✨ refactor: consolidate navigation and resource timing tracking in ru…
thomas-lebeau Apr 9, 2025
aff98e0
✨ refactor: rename trackUrlChange to trackUrls and add performance ev…
thomas-lebeau Apr 9, 2025
864b40d
✨ refactor: improve transportManager by consolidating batch sending l…
thomas-lebeau Apr 9, 2025
ff1e088
✨ refactor: simplify build script in rum-extra-slim package
thomas-lebeau Apr 9, 2025
ae06fbd
✨ refactor: update performance event types to use 'entry' property an…
thomas-lebeau Apr 9, 2025
9c81da4
✨ refactor: enhance error tracking by adding uncaught error handling …
thomas-lebeau Apr 9, 2025
9306a61
✨ refactor: remove unused import of createHandlingStack from browser-…
thomas-lebeau Apr 9, 2025
52a5bc6
✨ refactor: unify error event types by replacing UncaughtErrorEvent w…
thomas-lebeau Apr 9, 2025
3259bb9
✨ refactor: improve condition check for DD_RUM existence
thomas-lebeau Apr 9, 2025
9f910d7
✨ refactor: enhance error and console tracking by adding trackConsole…
thomas-lebeau Apr 10, 2025
f7deffb
✨ refactor: remove unused import of ContextArray from browser-core
thomas-lebeau Apr 10, 2025
60df374
✨ refactor: implement context management by adding setContext and tra…
thomas-lebeau Apr 10, 2025
4b8ab1d
✨ refactor: fix optional chaining for error context assignment and re…
thomas-lebeau Apr 10, 2025
6d0ea25
✨ feat: add tracking for long tasks
rgaignault Apr 10, 2025
0387f63
✨ refactor: update long task tracking to use long animation frame and…
rgaignault Apr 10, 2025
2dddc8f
✨ refactor: update context type names and adjust event handling for c…
thomas-lebeau Apr 11, 2025
bdcb96e
rename LT to LoAF
thomas-lebeau Apr 11, 2025
78b1fad
✨ feat: add action and feature flag evaluation tracking methods
thomas-lebeau Apr 11, 2025
ef81c87
use onReady to instrument DD_RUM APIs
BenoitZugmeyer Apr 14, 2025
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
92 changes: 46 additions & 46 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,52 +257,52 @@ check-schemas:
- yarn
- node scripts/check-schemas.js

unit-bs:
stage: browserstack
needs: ['unit']
extends:
- .base-configuration
- .bs-allowed-branches
interruptible: true
resource_group: browserstack
artifacts:
reports:
junit: test-report/unit-bs/*.xml
script:
- yarn
- ./scripts/test/ci-bs.sh test:unit
after_script:
- node ./scripts/test/export-test-result.js unit-bs

e2e-bs:
stage: browserstack
needs: ['e2e']
extends:
- .base-configuration
- .bs-allowed-branches
- .resource-allocation-4-cpus
interruptible: true
resource_group: browserstack
timeout: 35 minutes
artifacts:
when: always
reports:
junit: test-report/e2e-bs/*.xml
script:
- yarn
- FORCE_COLOR=1 ./scripts/test/ci-bs.sh test:e2e:ci
after_script:
- node ./scripts/test/export-test-result.js e2e-bs

script-tests:
extends:
- .base-configuration
- .test-allowed-branches
interruptible: true
script:
- yarn
- yarn build:bundle
- yarn test:script
# unit-bs:
# stage: browserstack
# needs: ['unit']
# extends:
# - .base-configuration
# - .bs-allowed-branches
# interruptible: true
# resource_group: browserstack
# artifacts:
# reports:
# junit: test-report/unit-bs/*.xml
# script:
# - yarn
# - ./scripts/test/ci-bs.sh test:unit
# after_script:
# - node ./scripts/test/export-test-result.js unit-bs

# e2e-bs:
# stage: browserstack
# needs: ['e2e']
# extends:
# - .base-configuration
# - .bs-allowed-branches
# - .resource-allocation-4-cpus
# interruptible: true
# resource_group: browserstack
# timeout: 35 minutes
# artifacts:
# when: always
# reports:
# junit: test-report/e2e-bs/*.xml
# script:
# - yarn
# - FORCE_COLOR=1 ./scripts/test/ci-bs.sh test:e2e:ci
# after_script:
# - node ./scripts/test/export-test-result.js e2e-bs

# script-tests:
# extends:
# - .base-configuration
# - .test-allowed-branches
# interruptible: true
# script:
# - yarn
# - yarn build:bundle
# - yarn test:script
########################################################################################################################
# Deploy
########################################################################################################################
Expand Down
6 changes: 5 additions & 1 deletion developer-extension/src/background/domain/syncRules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NetRequestRulesOptions } from '../../common/extension.types'
import {
DEV_LOGS_URL,
DEV_RUM_EXTRA_SLIM_URL,
DEV_RUM_RECORDER_CHUNK_URL,
DEV_RUM_SLIM_URL,
DEV_RUM_URL,
Expand Down Expand Up @@ -67,10 +68,13 @@ function buildRules(
const devRumUrl = useRumSlim ? DEV_RUM_SLIM_URL : DEV_RUM_URL
logger.log('add redirect to dev bundles rules')
rules.push(
createRedirectRule(/^https:\/\/.*\/datadog-rum(-[\w-]+)?\.js$/, { url: devRumUrl }),
createRedirectRule(/^https:\/\/.*\/datadog-rum-extra-slim(-[\w-]+)?\.js$/, {
url: DEV_RUM_EXTRA_SLIM_URL,
}),
createRedirectRule(/^https:\/\/.*\/datadog-rum-slim(-[\w-]+)?\.js$/, {
url: DEV_RUM_SLIM_URL,
}),
createRedirectRule(/^https:\/\/.*\/datadog-rum(-[\w-]+)?\.js$/, { url: devRumUrl }),
createRedirectRule(/^https:\/\/.*\/datadog-logs(-[\w-]+)?\.js$/, { url: DEV_LOGS_URL }),
createRedirectRule(/^https:\/\/.*\/chunks\/recorder(-[\w-]+)?-datadog-rum.js$/, {
url: DEV_RUM_RECORDER_CHUNK_URL,
Expand Down
1 change: 1 addition & 0 deletions developer-extension/src/common/packagesUrlConstants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const DEV_LOGS_URL = 'http://localhost:8080/datadog-logs.js'
export const DEV_RUM_RECORDER_CHUNK_URL = 'http://localhost:8080/chunks/recorder-datadog-rum.js'
export const DEV_RUM_SLIM_URL = 'http://localhost:8080/datadog-rum-slim.js'
export const DEV_RUM_EXTRA_SLIM_URL = 'http://localhost:8080/datadog-rum-extra-slim.js'
export const DEV_RUM_URL = 'http://localhost:8080/datadog-rum.js'
9 changes: 8 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,19 @@ export default tseslint.config(
},

{
files: ['packages/{rum,logs,rum-slim}/src/entries/*.ts'],
files: ['packages/{rum,logs,rum-slim,rum-extra-slim}/src/entries/*.ts'],
rules: {
'local-rules/disallow-enum-exports': 'error',
},
},

{
files: ['packages/rum-extra-slim/**/*.ts'],
rules: {
'local-rules/disallow-side-effects': 'off',
},
},

{
// Files executed by nodejs
files: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"postinstall": "scripts/cli init_submodule",
"build": "lerna run build --stream",
"build:bundle": "lerna run build:bundle --stream",
"build:xs": "lerna run build --scope @datadog/browser-rum-extra-slim",
"build:app": "lerna run pack --stream && cd test/apps/vanilla && rm -rf node_modules && yarn install --no-immutable && yarn build",
"build:react-app": "lerna run pack --stream && cd test/apps/react && rm -rf node_modules && yarn install --no-immutable && yarn build",
"build:apps": "yarn build:app && yarn build:react-app",
Expand Down
4 changes: 2 additions & 2 deletions packages/rum-core/src/browser/performanceObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface RumPerformanceResourceTiming {
renderBlockingStatus?: string
traceId?: string
deliveryType?: 'cache' | 'navigational-prefetch' | ''
toJSON(): Omit<PerformanceEntry, 'toJSON'>
toJSON(): Omit<RumPerformanceResourceTiming, 'toJSON'>
}

export interface RumPerformancePaintTiming {
Expand All @@ -75,7 +75,7 @@ export interface RumPerformancePaintTiming {
toJSON(): Omit<RumPerformancePaintTiming, 'toJSON'>
}

export interface RumPerformanceNavigationTiming extends Omit<RumPerformanceResourceTiming, 'entryType'> {
export interface RumPerformanceNavigationTiming extends Omit<RumPerformanceResourceTiming, 'entryType' | 'toJSON'> {
entryType: RumPerformanceEntryType.NAVIGATION
initiatorType: 'navigation'
name: string
Expand Down
7 changes: 7 additions & 0 deletions packages/rum-extra-slim/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!/bundle/datadog-rum-extra-slim.js
!/cjs/**/*
!/esm/**/*
!/src/**/*
/src/**/*.spec.ts
/src/**/*.specHelper.ts
2 changes: 2 additions & 0 deletions packages/rum-extra-slim/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
save-exact true

10 changes: 10 additions & 0 deletions packages/rum-extra-slim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# RUM Browser Monitoring - extra slim package

## Overview

> [!CAUTION]
> Experimental package. Not recommended for production use.

## Setup

See the [RUM package](../rum/README.md) documentation.
39 changes: 39 additions & 0 deletions packages/rum-extra-slim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@datadog/browser-rum-extra-slim",
"version": "6.6.3",
"license": "Apache-2.0",
"main": "cjs/entries/main.js",
"module": "esm/entries/main.js",
"types": "cjs/entries/main.d.ts",
"private": true,
"scripts": {
"pack": "yarn pack",
"build": "yarn build:bundle",
"build:bundle": "rm -rf bundle && SDK_SETUP=cdn webpack --mode=production",
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json"
},
"dependencies": {
"@datadog/browser-core": "6.6.3",
"@datadog/browser-rum-core": "6.6.3"
},
"peerDependencies": {
"@datadog/browser-logs": "6.6.3"
},
"peerDependenciesMeta": {
"@datadog/browser-logs": {
"optional": true
}
},
"repository": {
"type": "git",
"url": "https://github.com/DataDog/browser-sdk.git",
"directory": "packages/rum-extra-slim"
},
"volta": {
"extends": "../../package.json"
},
"publishConfig": {
"access": "public"
}
}
52 changes: 52 additions & 0 deletions packages/rum-extra-slim/src/boot/start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { setDebugMode } from '@datadog/browser-core'
import { startSessionManager } from '../domain/sessionManager'
import { trackPerformanceNavigationTimings } from '../domain/collection/trackPerformanceNavigationTimings'
import { startTransportManager } from '../domain/transportManager'
import { trackUrls } from '../domain/collection/trackUrls'
import { trackPerformanceResourceTimings } from '../domain/collection/trackPerformanceResourceTimings'
import { trackPerformanceEventTimings } from '../domain/collection/trackPerformanceEventTimings'
import { trackUncaughtErrors } from '../domain/collection/trackUncaughtErrors'
import { addError } from '../domain/collection/addError'
import { trackConsoleMethods } from '../domain/collection/trackConsoleMethods'
import { trackDDRumMethods } from '../domain/collection/trackDdRumMethods'
import { setContext } from '../domain/collection/setContext'
import { trackPerformanceLongAnimationFrameTimings } from '../domain/collection/trackPerformanceLongAnimationFrameTimings'
import { addAction } from '../domain/collection/addAction'
import { addFeatureFlagEvaluation } from '../domain/collection/addFeatureFlagEvaluation'

export function start() {
const sessionManager = startSessionManager()
const transportManager = startTransportManager(sessionManager)

const trackers: Array<() => void> = []

function init() {
trackers.push(
trackUrls(transportManager),
trackUncaughtErrors(transportManager),
trackPerformanceResourceTimings(transportManager),
trackPerformanceNavigationTimings(transportManager),
trackPerformanceEventTimings(transportManager),
trackConsoleMethods(transportManager),
trackDDRumMethods(transportManager),
trackPerformanceLongAnimationFrameTimings(transportManager)
)
}

return {
init,

addError: addError.bind(null, transportManager),
addAction: addAction.bind(null, transportManager),
addFeatureFlagEvaluation: addFeatureFlagEvaluation.bind(null, transportManager),

setGlobalContext: setContext.bind(null, transportManager, 'globalContext'),
setViewContext: setContext.bind(null, transportManager, 'viewContext'),
setUser: setContext.bind(null, transportManager, 'user'),
setAccount: setContext.bind(null, transportManager, 'account'),

stop: () => trackers.forEach((tracker) => tracker()),

_setDebug: setDebugMode,
}
}
14 changes: 14 additions & 0 deletions packages/rum-extra-slim/src/domain/collection/addAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { sanitize } from '@datadog/browser-core'
import type { TransportManager } from '../transportManager'
import type { ActionEvent } from '../event'
import { EVENT } from '../event'

export function addAction(transportManager: TransportManager, key: unknown, value: unknown) {
const data: ActionEvent = {
type: EVENT.ACTION,
key: sanitize(key) as string,
value: sanitize(value),
}

transportManager.send(data)
}
24 changes: 24 additions & 0 deletions packages/rum-extra-slim/src/domain/collection/addError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { combine, isError, sanitize } from '@datadog/browser-core'
import type { ErrorEvent } from '../event'
import { EVENT } from '../event'
import type { TransportManager } from '../transportManager'
import { createHandlingStack, serializeError } from '../../tools/errors'

export function addError(transportManager: TransportManager, error: unknown, context?: unknown) {
if (!isError(error)) {
return
}

const data: ErrorEvent = {
type: EVENT.ERROR,
error: serializeError(error),
}

if (context) {
data.error.context = combine(data.error?.context, sanitize(context))
}

data.error.handlingStack = createHandlingStack()

transportManager.send(data)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { clearTimeout, sanitize, setTimeout } from '@datadog/browser-core'
import type { TransportManager } from '../transportManager'
import type { FeatureFlagEvent } from '../event'
import { EVENT } from '../event'

const cache = new Map<unknown, unknown>()
const debounceFns = new Map<unknown, (callback: () => void) => void>()

function createDebounceFn() {
let timeout: number | undefined

return (callback: () => void) => {
if (timeout) {
clearTimeout(timeout)
}
timeout = setTimeout(() => {
callback()
timeout = undefined
}, 100)
}
}

export function addFeatureFlagEvaluation(transportManager: TransportManager, key: unknown, value: unknown) {
// avoid sending the same value multiple times
if (cache.get(key) === value) {
return
}

cache.set(key, value)

// debounce the sending of the event
if (!debounceFns.has(key)) {
debounceFns.set(key, createDebounceFn())
}
const debounce = debounceFns.get(key)!

const data: FeatureFlagEvent = {
type: EVENT.FEATURE_FLAG,
key: sanitize(key) as string,
value: sanitize(value),
}

debounce(() => transportManager.send(data))
}
Loading