Skip to content
Closed
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
d32f6ea
Add initial Salesforce support.
BeltranBulbarellaDD May 26, 2026
c02e9bf
Guard session
BeltranBulbarellaDD May 26, 2026
2fcb2ee
Linting
BeltranBulbarellaDD May 26, 2026
0d952b5
Add Resources and APM support
BeltranBulbarellaDD May 27, 2026
d6d525e
Make getGlobalLocationHref mockable, patch plain usage of location
BeltranBulbarellaDD May 27, 2026
363201b
use wire
BeltranBulbarellaDD May 29, 2026
2655dc5
Merge branch 'main' into beltran.bulbarella/salesforce_0
BeltranBulbarellaDD May 29, 2026
6a2eb32
Refactor for comments
BeltranBulbarellaDD May 29, 2026
059c321
Merge branch 'main' into beltran.bulbarella/salesforce_0
BeltranBulbarellaDD May 29, 2026
f7581c2
Fix bundle
BeltranBulbarellaDD May 29, 2026
783c96b
Use globalObject in turn of window
BeltranBulbarellaDD May 29, 2026
a8474b6
Add isCSPEventSupported function
BeltranBulbarellaDD May 29, 2026
59232c7
Create isEventSupported and reuse it
BeltranBulbarellaDD May 29, 2026
4f0711a
linter
BeltranBulbarellaDD May 29, 2026
721c1a2
Remove config parameter from isEventSupported
BeltranBulbarellaDD May 29, 2026
41a66d7
Remove views plugin and try catch debug
BeltranBulbarellaDD May 29, 2026
045bd3c
linter
BeltranBulbarellaDD May 29, 2026
3293b46
Fix compat
BeltranBulbarellaDD May 29, 2026
1f4c882
Revert changes to instrumentMethod.ts
BeltranBulbarellaDD Jun 3, 2026
a52f0d5
Move view tracking to bundle, rename bundle
BeltranBulbarellaDD Jun 3, 2026
a56d75f
Merge branch 'main' into beltran.bulbarella/salesforce_0
BeltranBulbarellaDD Jun 3, 2026
ff6a526
Move SF packages, add README
BeltranBulbarellaDD Jun 3, 2026
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
1 change: 1 addition & 0 deletions eslint-local-rules/disallowSideEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const pathsWithSideEffect = new Set([
`${packagesRoot}/browser-logs/src/entries/main.ts`,
`${packagesRoot}/browser-rum/src/entries/main.ts`,
`${packagesRoot}/browser-rum-slim/src/entries/main.ts`,
`${packagesRoot}/browser-rum-slim/src/entries/salesforce.ts`,
`${packagesRoot}/browser-debugger/src/entries/main.ts`,
])

Expand Down
14 changes: 14 additions & 0 deletions packages/browser-core/src/browser/addEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const enum DOM_EVENT {
SECURITY_POLICY_VIOLATION = 'securitypolicyviolation',
SELECTION_CHANGE = 'selectionchange',
STORAGE = 'storage',
UNHANDLED_REJECTION = 'unhandledrejection',
}

interface AddEventListenerOptions {
Expand Down Expand Up @@ -146,3 +147,16 @@ export function addEventListeners<Target extends EventTarget, EventName extends
stop,
}
}

export function isEventSupported<Target extends EventTarget, EventName extends keyof EventMapFor<Target> & string>(
eventTarget: Target,
eventName: EventName,
listener: (event: EventMapFor<Target>[EventName] & { type: EventName }) => void
) {
try {
addEventListener({}, eventTarget, eventName, listener).stop()
return true
} catch {
return false
}
}
8 changes: 7 additions & 1 deletion packages/browser-core/src/browser/cookieAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { Observable } from '../tools/observable'
import { mockable } from '../tools/mockable'
import { display } from '../tools/display'
import { generateUUID } from '../tools/utils/stringUtils'
import { noop } from '../tools/utils/functionUtils'
import type { Configuration } from '../domain/configuration'
import { addTelemetryDebug } from '../domain/telemetry'
import { globalObject } from '../tools/globalObject'
import { addEventListener, DOM_EVENT } from './addEventListener'
import { addEventListener, DOM_EVENT, isEventSupported } from './addEventListener'
import { getCookies, setCookie } from './cookie'
import type { CookieOptions } from './cookie'

Expand Down Expand Up @@ -162,3 +163,8 @@ export function createDocumentCookieAccess(
observable,
}
}

// Salesforce LWS does not support the change event of CookieStore objects. https://developer.salesforce.com/tools/lws-distortion-viewer
export function isCookieStoreSupported(): boolean {
return Boolean(globalObject.cookieStore && isEventSupported(globalObject.cookieStore, DOM_EVENT.CHANGE, noop))
}
7 changes: 7 additions & 0 deletions packages/browser-core/src/domain/error/trackRuntimeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { clocksNow } from '../../tools/utils/timeUtils'
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'
import { computeStackTraceFromOnErrorMessage } from '../../tools/stackTrace/computeStackTrace'
import { globalObject } from '../../tools/globalObject'
import { DOM_EVENT, isEventSupported } from '../../browser/addEventListener'
import { noop } from '../../tools/utils/functionUtils'
import { computeRawError, isError } from './error'
import type { RawError } from './error.types'
import { ErrorHandling, ErrorSource, NonErrorPrefix } from './error.types'
Expand Down Expand Up @@ -44,6 +46,11 @@ export function instrumentOnError(callback: UnhandledErrorCallback) {
}

export function instrumentUnhandledRejection(callback: UnhandledErrorCallback) {
// Salesforce LWS does not support the unhandledrejection event. https://developer.salesforce.com/tools/lws-distortion-viewer
if (!isEventSupported(globalObject.window, DOM_EVENT.UNHANDLED_REJECTION, noop)) {
return { stop: noop }
}

return instrumentMethod(globalObject, 'onunhandledrejection', ({ parameters: [e] }) => {
callback(e.reason || 'Empty reason')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { toStackTraceString } from '../../tools/stackTrace/handlingStack'
import { monitor } from '../../tools/monitor'
import { mergeObservables, Observable } from '../../tools/observable'
import { addEventListener, DOM_EVENT } from '../../browser/addEventListener'
import { addEventListener, DOM_EVENT, isEventSupported } from '../../browser/addEventListener'
import { safeTruncate } from '../../tools/utils/stringUtils'
import type { Configuration } from '../configuration'
import type { RawError } from '../error/error.types'
import { ErrorHandling, ErrorSource } from '../error/error.types'
import { clocksNow } from '../../tools/utils/timeUtils'
import { noop } from '../../tools/utils/functionUtils'
import type { ReportType, InterventionReport, DeprecationReport } from './browser.types'

export const RawReportType = {
Expand Down Expand Up @@ -60,6 +61,11 @@ function createReportObservable(reportTypes: ReportType[]) {

function createCspViolationReportObservable(configuration: Configuration) {
return new Observable<RawReportError>((observable) => {
// Salesforce does not allow to add a securitypolicyviolation event listener. https://developer.salesforce.com/tools/lws-distortion-viewer
if (!isEventSupported(document, DOM_EVENT.SECURITY_POLICY_VIOLATION, noop)) {
return
}

const { stop } = addEventListener(configuration, document, DOM_EVENT.SECURITY_POLICY_VIOLATION, (event) => {
observable.notify(buildRawReportErrorFromCspViolation(event))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
areCookiesAuthorized,
createCookieStoreAccess,
createDocumentCookieAccess,
isCookieStoreSupported,
} from '../../../browser/cookieAccess'
import { globalObject } from '../../../tools/globalObject'
import { CookieApi, LEGACY_SESSION_STORE_KEY, SESSION_STORE_KEY } from './sessionStoreStrategy'
import type {
SessionStoreStrategy,
Expand All @@ -33,10 +33,7 @@ export async function selectCookieStrategy(
return undefined
}

if (
mockable(globalObject.cookieStore) &&
(await areCookiesAuthorized(createCookieStoreAccess, cookieOptions, configuration))
) {
if (isCookieStoreSupported() && (await areCookiesAuthorized(createCookieStoreAccess, cookieOptions, configuration))) {
return { type: SessionPersistence.COOKIE, cookieOptions, cookieApi: CookieApi.COOKIE_STORE }
}

Expand Down
1 change: 1 addition & 0 deletions packages/browser-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export {
export { NonErrorPrefix } from './domain/error/error.types'
export type { Context, ContextArray, ContextValue } from './tools/serialisation/context'
export { getCookie, getInitCookie, setCookie, deleteCookie, resetInitCookies } from './browser/cookie'
export { isCookieStoreSupported } from './browser/cookieAccess'
export type {
CookieStore,
WeakRef,
Expand Down
3 changes: 2 additions & 1 deletion packages/browser-rum-core/src/browser/cookieObservable.ts
Comment thread
BeltranBulbarellaDD marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {
DOM_EVENT,
getCookie,
globalObject,
isCookieStoreSupported,
} from '@datadog/browser-core'

export type CookieObservable = ReturnType<typeof createCookieObservable>

export function createCookieObservable(configuration: Configuration, cookieName: string) {
const detectCookieChangeStrategy = globalObject.cookieStore
const detectCookieChangeStrategy = isCookieStoreSupported()
? listenToCookieStoreChange(configuration)
: watchCookieFallback

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { addEventListener, DOM_EVENT, instrumentMethod, Observable, shallowClone } from '@datadog/browser-core'
import {
addEventListener,
DOM_EVENT,
globalObject,
instrumentMethod,
Observable,
shallowClone,
} from '@datadog/browser-core'
import type { RumConfiguration } from '../domain/configuration'

export interface LocationChange {
Expand All @@ -7,7 +14,7 @@ export interface LocationChange {
}

export function createLocationChangeObservable(configuration: RumConfiguration) {
let currentLocation = shallowClone(location)
let currentLocation = shallowClone(globalObject.location)

return new Observable<LocationChange>((observable) => {
const { stop: stopHistoryTracking } = trackHistory(configuration, onLocationChange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
createValueHistory,
HookNames,
DISCARDED,
mockable,
buildUrl,
mockable,
globalObject,
} from '@datadog/browser-core'
import type { LocationChange } from '../../browser/locationChangeObservable'
import type { LifeCycle } from '../lifeCycle'
Expand Down Expand Up @@ -41,8 +42,9 @@ export function startUrlContexts(
let previousViewUrl: string | undefined

lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, ({ startClocks, url }) => {
const locationHref = mockable(location).href
const locationHref = mockable(globalObject.location).href
const viewUrl = url !== undefined ? buildUrl(url, locationHref).href : locationHref

urlContextHistory.add(
buildUrlContext({
url: viewUrl,
Expand Down
1 change: 1 addition & 0 deletions packages/browser-rum-slim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"build": "node ../../scripts/build/build-package.ts --modules --bundle datadog-rum-slim.js",
"build:bundle": "node ../../scripts/build/build-package.ts --bundle datadog-rum-slim.js",
"build:salesforce": "node ../../scripts/build/build-package.ts --bundle rum-salesforce-lightning.js --entry ./src/entries/salesforce.ts",
"prepack": "yarn build"
},
"dependencies": {
Expand Down
99 changes: 99 additions & 0 deletions packages/browser-rum-slim/src/domain/salesforce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Salesforce Lightning RUM

This entrypoint is intended for Salesforce Lightning and LWC applications using the `rum-salesforce-lightning.js`
bundle. The SDK forces the Salesforce-specific RUM settings required for this environment:

- `trackViewsManually: true`
- `profilingSampleRate: 0`
- `sessionReplaySampleRate: 0`

## Recommended LWC Setup

```js
import { LightningElement, api, wire } from 'lwc'
import { NavigationMixin, CurrentPageReference } from 'lightning/navigation'
import rumSalesforceLightning from '@salesforce/resourceUrl/rum_salesforce_lightning'
import { loadScript } from 'lightning/platformResourceLoader'

export default class DatadogInit extends NavigationMixin(LightningElement) {
@api applicationId
@api clientToken
@api site
@api service
@api env

connectedCallback() {
this.loadDatadogRum()
}

@wire(CurrentPageReference)
handleCurrentPageReference(pageReference) {
if (!pageReference) {
return
}

this.loadDatadogRum().then(() => {
this.startPageReference(pageReference)
})
}

startPageReference(pageReference) {
window.DD_RUM?.startSalesforceView?.({
pageReference,
baseUrl: window.location.origin || window.location.href,
generateUrl: (pageReferenceToGenerate) => this[NavigationMixin.GenerateUrl](pageReferenceToGenerate),
})
}

loadDatadogRum() {
return loadScript(this, rumSalesforceLightning).then(() => {
window.DD_RUM.initSalesforce({
applicationId: this.applicationId,
clientToken: this.clientToken,
site: this.site,
service: this.service,
env: this.env,
})
})
}
}
```

## Salesforce Feature Support

| Feature | Supported |
| ---------------------- | ------------------------------ |
| **View Events** | |
| Initial View | ✅ |
| Manual Tracking | ✅ |
| Navigation Timings | ✅ |
| Web Vitals | ✅ |
| Automatic Tracking | ✅⚠️ Supported with workaround |
| Loading Time | ✅⚠️(1) |
| **Resource Events** | |
| Fetch Resources | ✅⚠️(2) |
| XHR Resources | ✅⚠️(2) |
| Other Resources | ✅ |
| APM Correlation | ✅⚠️(2) |
| **Action Events** | |
| Custom Actions | ✅ |
| Click Actions | ✅ |
| Frustration Signals | ✅ |
| Selectors | ✅⚠️(3) |
| Action Name | ✅⚠️(2) |
| Loading Time | ✅⚠️(1) |
| **Error Events** | |
| Console Error | ✅ |
| Custom Errors | ✅ |
| Runtime Errors | ✅⚠️(4) |
| `onUnhandledRejection` | ❌ |
| CSP Violation | ❌ |
| **Other** | |
| Vital Events | ✅ |
| Long Task Events | ✅ |
| Session Replay | ❌ |

1. Loading time depends on page activity detection, which may not work fully in Salesforce Lightning due to shadow DOM restrictions on page lifecycle signals.
2. Cross-origin restrictions in the Lightning shell may hide full request URLs; APM correlation headers and action names derived from URLs may be incomplete.
3. Due to shadow boundaries, the SDK might receive the component host as `event.target` instead of the actual clicked element.
4. Direct synchronous errors can reach the SDK through `window.onerror`, but in the Lightning shell they may be redacted as "Script error." with no original error object, URL, line, or stack available to the SDK.
Loading
Loading