Skip to content
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

📝 [RUM-1026] Update READMEs for v5 #2453

Merged
merged 54 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
356499a
💥 Promote track frustration as default action behaviour (#2232)
bcaudan May 12, 2023
503751f
💥[RUMF-1554] Drop some deprecated config parameters (#2238)
bcaudan May 12, 2023
fe261e6
💥 [RUMF-1554] Drop some deprecated public APIs (#2241)
bcaudan May 15, 2023
3877dea
Merge branch 'main' into prerelease-v5
bcaudan May 17, 2023
aad4d97
💥 [RUMF-1587] Remove `premiumSampleRate` and `replaySampleRate` (#2256)
bcaudan May 26, 2023
ebeeef3
Merge branch 'main' into prerelease-v5
bcaudan May 26, 2023
808d652
💥 [RUMF-1588] Update default session replay behaviour (#2257)
bcaudan May 30, 2023
9a053b7
Merge branch 'main' into prerelease-v5
bcaudan May 30, 2023
638b655
🐛 [RUMF-1499] Don't send duration for resources crossing a page froze…
amortemousque May 30, 2023
cf5f10e
Merge branch 'main' into prerelease-v5
bcaudan Jun 5, 2023
de514ba
Merge branch 'main' into prerelease-v5
bcaudan Jun 5, 2023
f875c2b
💥 [RUMF-1589] automatically start recording (#2275)
bcaudan Jun 5, 2023
892bc23
♻️ Remove deprecated context manager APIs (#2284)
bcaudan Jun 6, 2023
982e7db
💥 [RUMF-1555] Remove `event` in action domain context (#2286)
bcaudan Jun 6, 2023
c928b60
🔥 [RUMF-1555] Remove `startTime` in xhr start context (#2287)
bcaudan Jun 6, 2023
fad84dd
💥[RUMF-1152] sanitize resource method names (#2288)
bcaudan Jun 7, 2023
512137b
💥 [RUMF-1555] Rework logger context APIs (#2285)
bcaudan Jun 7, 2023
e2fb6c1
💥[RUMF-1228] Remove console error message prefix (#2289)
amortemousque Jun 9, 2023
bc13cd0
Merge branch 'main' into prerelease-v5
bcaudan Jun 12, 2023
76872fb
💥[RUMF-1229] Logs: remove `error.origin` attribute (#2294)
bcaudan Jun 15, 2023
1c9f153
Merge branch 'main' into prerelease-v5
bcaudan Jun 15, 2023
3fdf329
Merge branch 'main' into prerelease-v5
bcaudan Jun 20, 2023
02f6a03
💥[RUMF-1230] Only apply main logger configuration to its own logs (#2…
bcaudan Jun 23, 2023
fe1d663
💥 Typings: consistent beforeSend return type (#2303)
bcaudan Jun 26, 2023
1cc6086
Merge branch 'main' into prerelease-v5
bcaudan Jun 26, 2023
d1882c7
💥 beforeSend domain context: use PerformanceEntry (#2300)
bcaudan Jun 26, 2023
f62b245
Merge branch 'main' into prerelease-v5
amortemousque Jun 28, 2023
ec62075
💥[RUMF-1564] remove intake subdomains (#2309)
bcaudan Jun 28, 2023
682d40b
💥 [RUMF-1473] Ignore untrusted event (#2308)
amortemousque Jul 3, 2023
ae5aac6
💥 [RUMF-1577] Stop collecting foreground periods (#2311)
amortemousque Jul 4, 2023
62ebc12
Merge branch 'main' into prerelease-v5
bcaudan Jul 6, 2023
251a484
v5.0.0-alpha.0 (#2321)
bcaudan Jul 7, 2023
206edb6
Merge branch 'main' into prerelease-v5
bcaudan Jul 10, 2023
5bc9940
Merge branch 'main' into prerelease-v5
bcaudan Jul 20, 2023
b1b88e8
Merge branch 'main' into prerelease-v5
bcaudan Jul 24, 2023
cd60262
💥 [RUMF-1597] Drop `plan` and send `sampled_for_replay` (#2293)
bcaudan Jul 25, 2023
ca21e65
Merge branch 'main' into prerelease-v5
bcaudan Jul 25, 2023
be9d18f
✨ [RUM-255] add allowUntrustedEvents config parameter (#2347)
bcaudan Jul 25, 2023
dbad5b6
Merge branch 'main' into prerelease-v5
bcaudan Jul 25, 2023
475592e
Merge branch 'main' into prerelease-v5
bcaudan Aug 10, 2023
23bbc71
👷 fix merge
bcaudan Aug 10, 2023
1fbf140
Merge branch 'main' into prerelease-v5
bcaudan Aug 24, 2023
3d6b2b5
Merge branch 'main' into prerelease-v5
bcaudan Aug 29, 2023
1672f53
Merge branch 'main' into prerelease-v5
bcaudan Sep 14, 2023
2838a3f
Merge branch 'main' into prerelease-v5
bcaudan Sep 14, 2023
eddca77
Merge branch 'main' into prerelease-v5
bcaudan Sep 15, 2023
f69f12e
Merge branch 'main' into prerelease-v5
amortemousque Sep 19, 2023
13852dc
Merge branch 'main' into prerelease-v5
amortemousque Sep 20, 2023
6203004
Merge branch 'main' into prerelease-v5
yannickadam Oct 3, 2023
4196b47
Update lock file
yannickadam Oct 3, 2023
4c7860f
✨ [RUM-1210] Add W3C tracecontext to default propagator types (#2443)
yannickadam Oct 4, 2023
1f9e7d9
Merge branch 'main' into prerelease-v5
bcaudan Oct 5, 2023
2ae80ed
Update READMEs for v5
bcaudan Oct 5, 2023
1b8ec1d
Merge branch 'main' into bcaudan/v5-readme-updates
bcaudan Oct 9, 2023
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
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.50.0

- ✨ [RUM-1062] add a prefix to all console message displayed by the SDK ([#2432](https://github.com/DataDog/browser-sdk/pull/2432))
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Datadog provides one CDN bundle per [site][60]:

| Site | logs | rum | rum-slim |
| ------- | -------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------ |
| US1 | https://www.datadoghq-browser-agent.com/us1/v4/datadog-logs.js | https://www.datadoghq-browser-agent.com/us1/v4/datadog-rum.js | https://www.datadoghq-browser-agent.com/us1/v4/datadog-rum-slim.js |
| US3 | https://www.datadoghq-browser-agent.com/us3/v4/datadog-logs.js | https://www.datadoghq-browser-agent.com/us3/v4/datadog-rum.js | https://www.datadoghq-browser-agent.com/us3/v4/datadog-rum-slim.js |
| US5 | https://www.datadoghq-browser-agent.com/us5/v4/datadog-logs.js | https://www.datadoghq-browser-agent.com/us5/v4/datadog-rum.js | https://www.datadoghq-browser-agent.com/us5/v4/datadog-rum-slim.js |
| EU1 | https://www.datadoghq-browser-agent.com/eu1/v4/datadog-logs.js | https://www.datadoghq-browser-agent.com/eu1/v4/datadog-rum.js | https://www.datadoghq-browser-agent.com/eu1/v4/datadog-rum-slim.js |
| US1-FED | https://www.datadoghq-browser-agent.com/datadog-logs-v4.js | https://www.datadoghq-browser-agent.com/datadog-rum-v4.js | https://www.datadoghq-browser-agent.com/datadog-rum-slim-v4.js |
| US1 | https://www.datadoghq-browser-agent.com/us1/v5/datadog-logs.js | https://www.datadoghq-browser-agent.com/us1/v5/datadog-rum.js | https://www.datadoghq-browser-agent.com/us1/v5/datadog-rum-slim.js |
| US3 | https://www.datadoghq-browser-agent.com/us3/v5/datadog-logs.js | https://www.datadoghq-browser-agent.com/us3/v5/datadog-rum.js | https://www.datadoghq-browser-agent.com/us3/v5/datadog-rum-slim.js |
| US5 | https://www.datadoghq-browser-agent.com/us5/v5/datadog-logs.js | https://www.datadoghq-browser-agent.com/us5/v5/datadog-rum.js | https://www.datadoghq-browser-agent.com/us5/v5/datadog-rum-slim.js |
| EU1 | https://www.datadoghq-browser-agent.com/eu1/v5/datadog-logs.js | https://www.datadoghq-browser-agent.com/eu1/v5/datadog-rum.js | https://www.datadoghq-browser-agent.com/eu1/v5/datadog-rum-slim.js |
| US1-FED | https://www.datadoghq-browser-agent.com/datadog-logs-v5.js | https://www.datadoghq-browser-agent.com/datadog-rum-v5.js | https://www.datadoghq-browser-agent.com/datadog-rum-slim-v5.js |

[1]: https://github.githubassets.com/favicons/favicon.png
[2]: https://imgix.datadoghq.com/img/favicons/favicon-32x32.png
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.50.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.50.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.50.0",
"version": "5.0.0-alpha.0",
"license": "Apache-2.0",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
54 changes: 52 additions & 2 deletions packages/core/src/browser/addEventListener.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Configuration } from '@datadog/browser-core'
import { stubZoneJs } from '../../test'
import { createNewEvent, stubZoneJs } from '../../test'
import { noop } from '../tools/utils/functionUtils'
import { addEventListener, DOM_EVENT } from './addEventListener'

Expand All @@ -10,7 +10,7 @@ describe('addEventListener', () => {
let zoneJsStub: ReturnType<typeof stubZoneJs>

beforeEach(() => {
configuration = {} as Configuration
configuration = { allowUntrustedEvents: false } as Configuration
zoneJsStub = stubZoneJs()
})

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

describe('Untrusted event', () => {
beforeEach(() => {
configuration = { allowUntrustedEvents: false } as Configuration
})

it('should be ignored if __ddIsTrusted is absent', () => {
const listener = jasmine.createSpy()
const eventTarget = document.createElement('div')
addEventListener(configuration, 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(configuration, 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(configuration, eventTarget, DOM_EVENT.CLICK, listener)

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

expect(listener).toHaveBeenCalled()
})

it('should not be ignored if allowUntrustedEvents is true', () => {
const listener = jasmine.createSpy()
const eventTarget = document.createElement('div')
configuration = { allowUntrustedEvents: true } as Configuration

addEventListener(configuration, eventTarget, DOM_EVENT.CLICK, listener)

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

expect(listener).toHaveBeenCalled()
})
})
})
25 changes: 15 additions & 10 deletions packages/core/src/browser/addEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getZoneJsOriginalValue } from '../tools/getZoneJsOriginalValue'
import type { Configuration } from '../domain/configuration'
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 @@ -106,20 +110,21 @@ export function addEventListener<Target extends EventTarget, EventName extends k
* * with `once: true`, the listener will be called at most once, even if different events are listened
*/
export function addEventListeners<Target extends EventTarget, EventName extends keyof EventMapFor<Target> & string>(
_: Configuration,
configuration: Configuration,
eventTarget: Target,
eventNames: EventName[],
listener: (event: EventMapFor<Target>[EventName] & { type: EventName }) => void,
{ once, capture, passive }: AddEventListenerOptions = {}
) {
const listenerWithMonitor = monitor(
once
? (event: Event) => {
stop()
listener(event as unknown as EventMapFor<Target>[EventName] & { type: EventName })
}
: (listener as unknown as (event: Event) => void)
)
const listenerWithMonitor = monitor((event: TrustableEvent) => {
if (!event.isTrusted && !event.__ddIsTrusted && !configuration.allowUntrustedEvents) {
return
}
if (once) {
stop()
}
listener(event as unknown as EventMapFor<Target>[EventName] & { type: 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
25 changes: 15 additions & 10 deletions packages/core/src/browser/xhrObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,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 @@ -70,7 +84,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 @@ -90,7 +103,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 @@ -110,7 +122,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 @@ -136,7 +147,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 @@ -158,7 +168,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 @@ -181,7 +190,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 @@ -203,7 +211,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 @@ -276,15 +283,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 type { Configuration } from '../domain/configuration'
Expand All @@ -15,7 +15,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 @@ -67,7 +66,7 @@ function createXhrObservable(configuration: Configuration) {
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 @@ -80,7 +79,6 @@ function sendXhr(this: XMLHttpRequest, configuration: Configuration, observable:

const startContext = context as XhrStartContext
startContext.state = 'start'
startContext.startTime = relativeNow()
startContext.startClocks = clocksNow()
startContext.isAborted = false
startContext.xhr = this
Expand All @@ -92,7 +90,7 @@ function sendXhr(this: XMLHttpRequest, configuration: Configuration, observable:
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
Loading