Skip to content

Commit 541c5b4

Browse files
committed
wip
1 parent 5a12bfc commit 541c5b4

File tree

14 files changed

+234
-116
lines changed

14 files changed

+234
-116
lines changed

packages/core/src/domain/telemetry/telemetryEvent.types.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,6 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
209209
* Whether the allowed tracing urls list is used
210210
*/
211211
use_allowed_tracing_urls?: boolean
212-
/**
213-
* Whether the allowed GraphQL urls list is used
214-
*/
215-
use_allowed_graph_ql_urls?: boolean
216-
/**
217-
* Whether GraphQL payload tracking is used for at least one GraphQL endpoint
218-
*/
219-
use_track_graph_ql_payload?: boolean
220212
/**
221213
* A list of selected tracing propagators
222214
*/
@@ -451,22 +443,6 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
451443
* The variant of the SDK build (e.g., standard, lite, etc.).
452444
*/
453445
variant?: string
454-
/**
455-
* The id of the remote configuration
456-
*/
457-
remote_configuration_id?: string
458-
/**
459-
* Whether a proxy is used for remote configuration
460-
*/
461-
use_remote_configuration_proxy?: boolean
462-
/**
463-
* The percentage of sessions with Profiling enabled
464-
*/
465-
profiling_sample_rate?: number
466-
/**
467-
* Whether trace baggage is propagated to child spans
468-
*/
469-
propagate_trace_baggage?: boolean
470446
[k: string]: unknown
471447
}
472448
[k: string]: unknown

packages/rum-core/src/domain/assembly.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export function startRumAssembly(
8686
...VIEW_MODIFIABLE_FIELD_PATHS,
8787
...ROOT_MODIFIABLE_FIELD_PATHS,
8888
},
89+
[RumEventType.STREAM]: {
90+
...USER_CUSTOMIZABLE_FIELD_PATHS,
91+
...VIEW_MODIFIABLE_FIELD_PATHS,
92+
...ROOT_MODIFIABLE_FIELD_PATHS,
93+
},
8994
}
9095
const eventRateLimiters = {
9196
[RumEventType.ERROR]: createEventRateLimiter(
@@ -109,7 +114,7 @@ export function startRumAssembly(
109114
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
110115
({ startTime, duration, rawRumEvent, domainContext }) => {
111116
const defaultRumEventAttributes = hooks.triggerHook(HookNames.Assemble, {
112-
eventType: rawRumEvent.type,
117+
eventType: rawRumEvent.type === 'stream' ? 'view' : rawRumEvent.type,
113118
startTime,
114119
duration,
115120
})!
@@ -126,6 +131,11 @@ export function startRumAssembly(
126131
if (isEmptyObject(serverRumEvent.context!)) {
127132
delete serverRumEvent.context
128133
}
134+
135+
if (rawRumEvent.type === 'stream') {
136+
serverRumEvent.type = 'view'
137+
}
138+
129139
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent)
130140
}
131141
}

packages/rum-core/src/domain/event/eventCollection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
RawRumLongTaskEvent,
1111
RawRumResourceEvent,
1212
RawRumVitalEvent,
13+
RawRumStreamEvent,
1314
} from '../../rawRumEvent.types'
1415
import { RumEventType } from '../../rawRumEvent.types'
1516

@@ -18,6 +19,7 @@ const allowedEventTypes = [
1819
RumEventType.ERROR,
1920
RumEventType.LONG_TASK,
2021
RumEventType.RESOURCE,
22+
RumEventType.STREAM,
2123
RumEventType.VITAL,
2224
] as const
2325

@@ -28,6 +30,7 @@ export type AllowedRawRumEvent = (
2830
| RawRumLongAnimationFrameEvent
2931
| RawRumActionEvent
3032
| RawRumVitalEvent
33+
| RawRumStreamEvent
3134
) & { context?: Context }
3235

3336
export function startEventCollection(lifeCycle: LifeCycle) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { RumPlugin, OnRumStartOptions } from '../..'
2+
import type { AddEvent, API } from './stream'
3+
import { createStream } from './stream'
4+
5+
export function createStreamPlugin(): { plugin: RumPlugin; createStream: () => ReturnType<typeof createStream> } {
6+
let addEvent: OnRumStartOptions['addEvent']
7+
const callbacks = new Set<(addEvent: OnRumStartOptions['addEvent']) => void>()
8+
const store: AddEvent = (...args) => {
9+
callbacks.add(() => {
10+
addEvent!(...args)
11+
})
12+
}
13+
14+
const api: API = {
15+
get addEvent() {
16+
return addEvent ?? store
17+
},
18+
}
19+
20+
return {
21+
plugin: {
22+
name: 'stream',
23+
onRumStart: (options) => {
24+
addEvent = options.addEvent
25+
26+
callbacks.forEach((callback) => callback(addEvent))
27+
callbacks.clear()
28+
},
29+
},
30+
createStream: () => createStream(api),
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// eslint-disable-next-line no-restricted-syntax
2+
abstract class Metric {
3+
constructor(private name: string) {}
4+
5+
update(value: number, weight?: number): void {
6+
// This method is a placeholder for metric updates.
7+
}
8+
}
9+
10+
// eslint-disable-next-line no-restricted-syntax
11+
export class WeightAverageMetric extends Metric {
12+
private average: number = 0
13+
private weight: number = 0
14+
15+
update(value: number, weight: number): void {
16+
this.average = (this.average * this.weight + value * weight) / (this.weight + weight)
17+
this.weight += weight
18+
}
19+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { clocksNow, generateUUID } from '@datadog/browser-core'
2+
import type { StartRumResult } from '../..'
3+
import type { WeightAverageMetric } from './metric'
4+
import { createTimer } from './timer'
5+
6+
export interface API {
7+
addEvent: AddEvent
8+
}
9+
10+
export type AddEvent = StartRumResult['addEvent']
11+
12+
interface Meta {
13+
duration?: number
14+
format?: string
15+
resolution?: string
16+
}
17+
18+
interface Metrics {
19+
bitrate: WeightAverageMetric
20+
fps: WeightAverageMetric
21+
timestamp: number
22+
watchTime: number
23+
}
24+
25+
type Transition = 'end' | 'error' | 'pause' | 'play' | 'preload' | 'quit' | 'rebuff' | 'seek' | 'start'
26+
27+
export function createStream(api: API) {
28+
const id = generateUUID()
29+
const origin = clocksNow()
30+
const timer = createTimer()
31+
32+
return {
33+
interaction(id: string): void {},
34+
transition(state: Transition, context: any): void {
35+
if (state === 'play') {
36+
timer.start()
37+
}
38+
39+
if (state === 'pause' || state === 'end') {
40+
timer.stop()
41+
}
42+
43+
const now = clocksNow()
44+
45+
api.addEvent(
46+
now.relative,
47+
{
48+
date: now.timeStamp,
49+
type: 'action',
50+
action: { id: generateUUID(), type: 'custom', target: { name: state } },
51+
stream: { id },
52+
},
53+
context
54+
)
55+
},
56+
update(key: string, value: any): void {
57+
const now = clocksNow()
58+
59+
api.addEvent(
60+
now.relative,
61+
{
62+
date: now.timeStamp,
63+
type: 'stream',
64+
stream: {
65+
id: generateUUID(),
66+
},
67+
},
68+
{}
69+
)
70+
},
71+
}
72+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { RelativeTime } from '@datadog/browser-core'
2+
import { relativeNow } from '@datadog/browser-core'
3+
4+
export function createTimer() {
5+
let start: RelativeTime
6+
let count = 0
7+
8+
return {
9+
start(): number {
10+
start = relativeNow()
11+
12+
return count
13+
},
14+
stop(): number {
15+
const duration = relativeNow() - start
16+
17+
count += duration
18+
19+
return count
20+
},
21+
}
22+
}

packages/rum-core/src/domain/trackEventCounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function trackEventCounts({
3030
}
3131

3232
const subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (event): void => {
33-
if (event.type === 'view' || event.type === 'vital' || !isChildEvent(event)) {
33+
if (event.type === 'view' || event.type === 'vital' || !isChildEvent(event) || ['stream'].includes(event.type)) {
3434
return
3535
}
3636
switch (event.type) {

packages/rum-core/src/domainContext.types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export type RumEventDomainContext<T extends RumEventType = any> = T extends type
1616
? RumLongTaskEventDomainContext
1717
: T extends typeof RumEventType.VITAL
1818
? RumVitalEventDomainContext
19-
: never
19+
: T extends typeof RumEventType.STREAM
20+
? { streamId: string }
21+
: never
2022

2123
export interface RumViewEventDomainContext {
2224
location: Readonly<Location>
@@ -59,3 +61,5 @@ export interface RumLongTaskEventDomainContext {
5961

6062
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
6163
export interface RumVitalEventDomainContext {}
64+
65+
export interface RumStreamEventDomainContext {}

packages/rum-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ export type { Hooks, DefaultRumEventAttributes, DefaultTelemetryEventAttributes
7171
export { createHooks } from './domain/hooks'
7272
export { isSampled } from './domain/sampler/sampler'
7373
export type { TracingOption, PropagatorType } from './domain/tracing/tracer.types'
74+
export { createStreamPlugin } from './domain/stream'

0 commit comments

Comments
 (0)