Skip to content

Commit

Permalink
Merge branch 'prerelease-v5' (5bc9940) into staging-29
Browse files Browse the repository at this point in the history
 pm_trace_id: 18017467
 feature_branch_pipeline_id: 18017467
 source: to-staging

* commit '5bc99408ea1dffffedaf9e13facb23f14c1f0c0f':
  v5.0.0-alpha.0 (#2321)
  💥 [RUMF-1577] Stop collecting foreground periods (#2311)
  💥 [RUMF-1473] Ignore untrusted event (#2308)
  💥[RUMF-1564] remove intake subdomains (#2309)
  💥 beforeSend domain context: use PerformanceEntry (#2300)
  💥 Typings: consistent beforeSend return type (#2303)
  💥[RUMF-1230] Only apply main logger configuration to its own logs (#2298)
  💥[RUMF-1229] Logs: remove `error.origin` attribute (#2294)
  💥[RUMF-1228] Remove console error message prefix (#2289)
  💥 [RUMF-1555] Rework logger context APIs (#2285)
  💥[RUMF-1152] sanitize resource method names (#2288)
  🔥 [RUMF-1555] Remove `startTime` in xhr start context (#2287)
  💥 [RUMF-1555] Remove `event` in action domain context (#2286)
  ♻️ Remove deprecated context manager APIs (#2284)
  💥 [RUMF-1589] automatically start recording (#2275)
  🐛 [RUMF-1499] Don't send duration for resources crossing a page frozen state (#2271)
  💥 [RUMF-1588] Update default session replay behaviour (#2257)
  💥 [RUMF-1587] Remove `premiumSampleRate` and `replaySampleRate` (#2256)
  💥 [RUMF-1554] Drop some deprecated public APIs (#2241)
  💥[RUMF-1554] Drop some deprecated config parameters (#2238)
  💥 Promote track frustration as default action behaviour (#2232)
  • Loading branch information
bcaudan committed Jul 20, 2023
2 parents 4592763 + 5bc9940 commit 3ed30fc
Show file tree
Hide file tree
Showing 114 changed files with 1,008 additions and 1,850 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@
---

## v5.0.0-alpha.0

- 💥 [RUMF-1577] Stop collecting foreground periods ([#2311](https://github.com/DataDog/browser-sdk/pull/2311))
- 💥 [RUMF-1473] Ignore untrusted event ([#2308](https://github.com/DataDog/browser-sdk/pull/2308))
- 💥 [RUMF-1564] remove intake subdomains ([#2309](https://github.com/DataDog/browser-sdk/pull/2309))
- 💥 [RUMF-1557] beforeSend domain context: use PerformanceEntry ([#2300](https://github.com/DataDog/browser-sdk/pull/2300))
- 💥 [RUMF-1556] Typings: consistent beforeSend return type ([#2303](https://github.com/DataDog/browser-sdk/pull/2303))
- 💥 [RUMF-1230] Only apply main logger configuration to its own logs ([#2298](https://github.com/DataDog/browser-sdk/pull/2298))
- 💥 [RUMF-1229] Logs: remove `error.origin` attribute ([#2294](https://github.com/DataDog/browser-sdk/pull/2294))
- 💥 [RUMF-1228] Remove console error message prefix ([#2289](https://github.com/DataDog/browser-sdk/pull/2289))
- 💥 [RUMF-1555] Rework logger context APIs ([#2285](https://github.com/DataDog/browser-sdk/pull/2285))
- 💥 [RUMF-1152] sanitize resource method names ([#2288](https://github.com/DataDog/browser-sdk/pull/2288))
- 💥 [RUMF-1555] Remove `event` in action domain context ([#2286](https://github.com/DataDog/browser-sdk/pull/2286))
- 💥 [RUMF-1589] automatically start recording ([#2275](https://github.com/DataDog/browser-sdk/pull/2275))
- 💥 [RUMF-1588] Update default session replay behaviour ([#2257](https://github.com/DataDog/browser-sdk/pull/2257))
- 💥 [RUMF-1587] Remove `premiumSampleRate` and `replaySampleRate` ([#2256](https://github.com/DataDog/browser-sdk/pull/2256))
- 💥 [RUMF-1554] Drop some deprecated public APIs ([#2241](https://github.com/DataDog/browser-sdk/pull/2241))
- 💥 [RUMF-1554] Drop some deprecated config parameters ([#2238](https://github.com/DataDog/browser-sdk/pull/2238))
- 💥 [RUMF-1578] Promote track frustration as default action behaviour ([#2232](https://github.com/DataDog/browser-sdk/pull/2232))
- 🐛 [RUMF-1499] Don't send duration for resources crossing a page frozen state ([#2271](https://github.com/DataDog/browser-sdk/pull/2271))
- 🔥 [RUMF-1555] Remove `startTime` in xhr start context ([#2287](https://github.com/DataDog/browser-sdk/pull/2287))
- ♻️ [RUMF-1555] Remove deprecated context manager APIs ([#2284](https://github.com/DataDog/browser-sdk/pull/2284))

## v4.45.0

-[RUM-235] add sample rates fields ([#2323](https://github.com/DataDog/browser-sdk/pull/2323))
Expand Down
2 changes: 1 addition & 1 deletion developer-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datadog/browser-sdk-developer-extension",
"version": "4.45.0",
"version": "5.0.0-alpha.0",
"private": true,
"scripts": {
"build": "rm -rf dist && webpack --mode production",
Expand Down
4 changes: 2 additions & 2 deletions developer-extension/src/panel/hooks/useSdkInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ async function getInfos(): Promise<SdkInfos> {
version: window.DD_RUM?.version,
config: window.DD_RUM?.getInitConfiguration?.(),
internalContext: window.DD_RUM?.getInternalContext?.(),
globalContext: window.DD_RUM?.getRumGlobalContext?.(),
globalContext: window.DD_RUM?.getGlobalContext?.(),
user: window.DD_RUM?.getUser?.(),
}
const logs = window.DD_LOGS && {
version: window.DD_LOGS?.version,
config: window.DD_LOGS?.getInitConfiguration?.(),
globalContext: window.DD_LOGS?.getLoggerGlobalContext?.(),
globalContext: window.DD_LOGS?.getGlobalContext?.(),
user: window.DD_LOGS?.getUser?.(),
}
return { rum, logs, cookie }
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"npmClient": "yarn",
"version": "4.45.0"
"version": "5.0.0-alpha.0"
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datadog/browser-core",
"version": "4.45.0",
"version": "5.0.0-alpha.0",
"license": "Apache-2.0",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
35 changes: 34 additions & 1 deletion packages/core/src/browser/addEventListener.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stubZoneJs } from '../../test'
import { createNewEvent, stubZoneJs } from '../../test'
import { noop } from '../tools/utils/functionUtils'
import { addEventListener, DOM_EVENT } from './addEventListener'

Expand Down Expand Up @@ -33,4 +33,37 @@ describe('addEventListener', () => {
expect(zoneJsPatchedRemoveEventListener).not.toHaveBeenCalled()
})
})

describe('Untrusted event', () => {
it('should be ignored if __ddIsTrusted is absent', () => {
const listener = jasmine.createSpy()
const eventTarget = document.createElement('div')
addEventListener(eventTarget, DOM_EVENT.CLICK, listener)

const event = createNewEvent(DOM_EVENT.CLICK, { __ddIsTrusted: undefined })
eventTarget.dispatchEvent(event)
expect(listener).not.toHaveBeenCalled()
})

it('should be ignored if __ddIsTrusted is false', () => {
const listener = jasmine.createSpy()
const eventTarget = document.createElement('div')
addEventListener(eventTarget, DOM_EVENT.CLICK, listener)

const event = createNewEvent(DOM_EVENT.CLICK, { __ddIsTrusted: false })
eventTarget.dispatchEvent(event)
expect(listener).not.toHaveBeenCalled()
})

it('should not be ignored if __ddIsTrusted is true', () => {
const listener = jasmine.createSpy()
const eventTarget = document.createElement('div')
addEventListener(eventTarget, DOM_EVENT.CLICK, listener)

const event = createNewEvent(DOM_EVENT.CLICK, { __ddIsTrusted: true })
eventTarget.dispatchEvent(event)

expect(listener).toHaveBeenCalled()
})
})
})
23 changes: 14 additions & 9 deletions packages/core/src/browser/addEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { monitor } from '../tools/monitor'
import { getZoneJsOriginalValue } from '../tools/getZoneJsOriginalValue'
import type { VisualViewport, VisualViewportEventMap } from './types'

export const enum DOM_EVENT {
export type TrustableEvent<E extends Event = Event> = E & { __ddIsTrusted?: boolean }

// We want to use a real enum (i.e. not a const enum) here, to be able to iterate over it to automatically add _ddIsTrusted in e2e tests
// eslint-disable-next-line no-restricted-syntax
export enum DOM_EVENT {
BEFORE_UNLOAD = 'beforeunload',
CLICK = 'click',
DBL_CLICK = 'dblclick',
Expand Down Expand Up @@ -108,14 +112,15 @@ export function addEventListeners<Target extends EventTarget, EventName extends
listener: (event: EventMapFor<Target>[EventName]) => void,
{ once, capture, passive }: AddEventListenerOptions = {}
) {
const wrappedListener = monitor(
once
? (event: Event) => {
stop()
listener(event as EventMapFor<Target>[EventName])
}
: (listener as (event: Event) => void)
)
const wrappedListener = monitor((event: TrustableEvent) => {
if (!event.isTrusted && !event.__ddIsTrusted) {
return
}
if (once) {
stop()
}
listener(event as EventMapFor<Target>[EventName])
})

const options = passive ? { capture, passive } : capture

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/browser/fetchObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('fetch proxy', () => {
fetchStub(new Request(FAKE_URL, { method: 'PUT' }), { method: 'POST' }).resolveWith({ status: 500 })
fetchStub(new Request(FAKE_URL), { method: 'POST' }).resolveWith({ status: 500 })
fetchStub(FAKE_URL, { method: 'POST' }).resolveWith({ status: 500 })
fetchStub(FAKE_URL, { method: 'post' }).resolveWith({ status: 500 })
fetchStub(null as any).resolveWith({ status: 500 })
fetchStub({ method: 'POST' } as any).resolveWith({ status: 500 })

Expand All @@ -123,8 +124,9 @@ describe('fetch proxy', () => {
expect(requests[3].method).toEqual('POST')
expect(requests[4].method).toEqual('POST')
expect(requests[5].method).toEqual('POST')
expect(requests[6].method).toEqual('GET')
expect(requests[6].method).toEqual('POST')
expect(requests[7].method).toEqual('GET')
expect(requests[8].method).toEqual('GET')
done()
})
})
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/browser/fetchObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function createFetchObservable() {
}

function beforeSend(observable: Observable<FetchContext>, input: unknown, init?: RequestInit) {
const method = (init && init.method) || (input instanceof Request && input.method) || 'GET'
const methodFromParams = (init && init.method) || (input instanceof Request && input.method)
const method = methodFromParams ? methodFromParams.toUpperCase() : 'GET'
const url = input instanceof Request ? input.url : normalizeUrl(String(input))
const startClocks = clocksNow()

Expand Down
27 changes: 16 additions & 11 deletions packages/core/src/browser/xhrObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@ describe('xhr observable', () => {
expect(request.url).toContain('/ok')
expect(request.status).toBe(200)
expect(request.isAborted).toBe(false)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
done()
},
})
})

it('should sanitize request method', (done) => {
withXhr({
setup(xhr) {
xhr.open('get', '/ok')
xhr.send()
xhr.complete(200, 'ok')
},
onComplete() {
const request = requests[0]
expect(request.method).toBe('GET')
done()
},
})
})

it('should track client error', (done) => {
withXhr({
setup(xhr) {
Expand All @@ -67,7 +81,6 @@ describe('xhr observable', () => {
expect(request.url).toContain('/expected-404')
expect(request.status).toBe(404)
expect(request.isAborted).toBe(false)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
done()
},
Expand All @@ -87,7 +100,6 @@ describe('xhr observable', () => {
expect(request.url).toContain('/throw')
expect(request.status).toBe(500)
expect(request.isAborted).toBe(false)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
done()
},
Expand All @@ -107,7 +119,6 @@ describe('xhr observable', () => {
expect(request.url).toBe('http://foo.bar/qux')
expect(request.status).toBe(0)
expect(request.isAborted).toBe(false)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
done()
},
Expand All @@ -133,7 +144,6 @@ describe('xhr observable', () => {
expect(request.method).toBe('GET')
expect(request.url).toContain('/ok')
expect(request.status).toBe(200)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
expect(request.isAborted).toBe(false)
expect(xhr.status).toBe(0)
Expand All @@ -155,7 +165,6 @@ describe('xhr observable', () => {
expect(request.method).toBe('GET')
expect(request.url).toContain('/ok')
expect(request.status).toBe(0)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
expect(request.isAborted).toBe(true)
expect(xhr.status).toBe(0)
Expand All @@ -178,7 +187,6 @@ describe('xhr observable', () => {
expect(request.url).toContain('/ok')
expect(request.status).toBe(200)
expect(request.isAborted).toBe(false)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
expect(xhr.onreadystatechange).toHaveBeenCalled()
done()
Expand All @@ -200,7 +208,6 @@ describe('xhr observable', () => {
expect(request.url).toContain('/ok')
expect(request.status).toBe(200)
expect(request.isAborted).toBe(false)
expect(request.startTime).toEqual(jasmine.any(Number))
expect(request.duration).toEqual(jasmine.any(Number))
expect(xhr.onreadystatechange).toHaveBeenCalled()
done()
Expand Down Expand Up @@ -247,7 +254,7 @@ describe('xhr observable', () => {
})

it('should track multiple requests with the same xhr instance', (done) => {
let listeners: { [k: string]: Array<() => void> }
let listeners: { [k: string]: Array<(event: Event) => void> }
withXhr({
setup(xhr) {
const secondOnload = () => {
Expand All @@ -273,15 +280,13 @@ describe('xhr observable', () => {
expect(firstRequest.url).toContain('/ok?request=1')
expect(firstRequest.status).toBe(200)
expect(firstRequest.isAborted).toBe(false)
expect(firstRequest.startTime).toEqual(jasmine.any(Number))
expect(firstRequest.duration).toEqual(jasmine.any(Number))

const secondRequest = requests[1]
expect(secondRequest.method).toBe('GET')
expect(secondRequest.url).toContain('/ok?request=2')
expect(secondRequest.status).toBe(400)
expect(secondRequest.isAborted).toBe(false)
expect(secondRequest.startTime).toEqual(jasmine.any(Number))
expect(secondRequest.duration).toEqual(jasmine.any(Number))

expect(xhr.onreadystatechange).toHaveBeenCalledTimes(2)
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/browser/xhrObservable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { instrumentMethodAndCallOriginal } from '../tools/instrumentMethod'
import { Observable } from '../tools/observable'
import type { Duration, RelativeTime, ClocksState } from '../tools/utils/timeUtils'
import { elapsed, relativeNow, clocksNow, timeStampNow } from '../tools/utils/timeUtils'
import type { Duration, ClocksState } from '../tools/utils/timeUtils'
import { elapsed, clocksNow, timeStampNow } from '../tools/utils/timeUtils'
import { normalizeUrl } from '../tools/utils/urlPolyfill'
import { shallowClone } from '../tools/utils/objectUtils'
import { addEventListener } from './addEventListener'
Expand All @@ -14,7 +14,6 @@ export interface XhrOpenContext {

export interface XhrStartContext extends Omit<XhrOpenContext, 'state'> {
state: 'start'
startTime: RelativeTime // deprecated
startClocks: ClocksState
isAborted: boolean
xhr: XMLHttpRequest
Expand Down Expand Up @@ -66,7 +65,7 @@ function createXhrObservable() {
function openXhr(this: XMLHttpRequest, method: string, url: string | URL | undefined | null) {
xhrContexts.set(this, {
state: 'open',
method,
method: method.toUpperCase(),
url: normalizeUrl(String(url)),
})
}
Expand All @@ -79,7 +78,6 @@ function sendXhr(this: XMLHttpRequest, observable: Observable<XhrContext>) {

const startContext = context as XhrStartContext
startContext.state = 'start'
startContext.startTime = relativeNow()
startContext.startClocks = clocksNow()
startContext.isAborted = false
startContext.xhr = this
Expand All @@ -91,7 +89,7 @@ function sendXhr(this: XMLHttpRequest, observable: Observable<XhrContext>) {
if (this.readyState === XMLHttpRequest.DONE) {
// Try to report the XHR as soon as possible, because the XHR may be mutated by the
// application during a future event. For example, Angular is calling .abort() on
// completed requests during a onreadystatechange event, so the status becomes '0'
// completed requests during an onreadystatechange event, so the status becomes '0'
// before the request is collected.
onEnd()
}
Expand Down
17 changes: 0 additions & 17 deletions packages/core/src/domain/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ describe('validateAndBuildConfiguration', () => {
expect(displaySpy).not.toHaveBeenCalled()
})

it('requires deprecated sampleRate to be a percentage', () => {
expect(
validateAndBuildConfiguration({ clientToken, sampleRate: 'foo' } as unknown as InitConfiguration)
).toBeUndefined()
expect(displaySpy).toHaveBeenCalledOnceWith('Session Sample Rate should be a number between 0 and 100')

displaySpy.calls.reset()
expect(
validateAndBuildConfiguration({ clientToken, sampleRate: 200 } as unknown as InitConfiguration)
).toBeUndefined()
expect(displaySpy).toHaveBeenCalledOnceWith('Session Sample Rate should be a number between 0 and 100')

displaySpy.calls.reset()
validateAndBuildConfiguration({ clientToken: 'yes', sampleRate: 1 })
expect(displaySpy).not.toHaveBeenCalled()
})

it('requires sessionSampleRate to be a percentage', () => {
expect(
validateAndBuildConfiguration({ clientToken, sessionSampleRate: 'foo' } as unknown as InitConfiguration)
Expand Down
Loading

0 comments on commit 3ed30fc

Please sign in to comment.