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

✨[RUMF-1188] add telemetry event types #1353

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
120 changes: 120 additions & 0 deletions packages/core/src/domain/internalMonitoring/telemetryEvent.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* eslint-disable */
/**
* DO NOT MODIFY IT BY HAND. Run `yarn rum-events-format:sync` instead.
*/

/**
* Schema of all properties of a telemetry event
*/
export type TelemetryEvent = TelemetryErrorEvent | TelemetryDebugEvent
/**
* Schema of all properties of a telemetry error event
*/
export type TelemetryErrorEvent = CommonTelemetryProperties & {
/**
* Level/severity of the log
*/
status: 'error'
/**
* Body of the log
*/
message: string
/**
* Error properties
*/
error?: {
/**
* The stack trace or the complementary information about the error
*/
stack?: string
/**
* The error type or kind (or code in some cases)
*/
kind?: string
[k: string]: unknown
}
[k: string]: unknown
}
/**
* Schema of all properties of a telemetry debug event
*/
export type TelemetryDebugEvent = CommonTelemetryProperties & {
/**
* Level/severity of the log
*/
status: 'debug'
/**
* Body of the log
*/
message: string
[k: string]: unknown
}

/**
* Schema of common properties of Telemetry events
*/
export interface CommonTelemetryProperties {
/**
* Internal properties
*/
_dd: {
/**
* Event type
*/
event_type: 'internal_telemetry'
[k: string]: unknown
}
/**
* Start of the event in ms from epoch
*/
date: number
/**
* The SDK generating the telemetry event
*/
service: string
/**
* The version of the SDK generating the telemetry event
*/
version: string
/**
* Application properties
*/
readonly application?: {
/**
* UUID of the application
*/
id: string
[k: string]: unknown
}
/**
* Session properties
*/
session?: {
/**
* UUID of the session
*/
id: string
[k: string]: unknown
}
/**
* View properties
*/
view?: {
/**
* UUID of the view
*/
id: string
[k: string]: unknown
}
/**
* Action properties
*/
action?: {
/**
* UUID of the action
*/
id: string
[k: string]: unknown
}
[k: string]: unknown
}
32 changes: 16 additions & 16 deletions packages/rum-core/test/formatValidation.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import type { Context } from '@datadog/browser-core'
import ajv from 'ajv'
import rumEventsFormatJson from '../../../rum-events-format/rum-events-format.json'
import _commonSchemaJson from '../../../rum-events-format/schemas/_common-schema.json'
import actionSchemaJson from '../../../rum-events-format/schemas/action-schema.json'
import errorSchemaJson from '../../../rum-events-format/schemas/error-schema.json'
import longTaskSchemaJson from '../../../rum-events-format/schemas/long_task-schema.json'
import resourceSchemaJson from '../../../rum-events-format/schemas/resource-schema.json'
import viewSchemaJson from '../../../rum-events-format/schemas/view-schema.json'
import rumEventsSchemaJson from '../../../rum-events-format/schemas/rum-events-schema.json'
import _commonSchemaJson from '../../../rum-events-format/schemas/rum/_common-schema.json'
import actionSchemaJson from '../../../rum-events-format/schemas/rum/action-schema.json'
import errorSchemaJson from '../../../rum-events-format/schemas/rum/error-schema.json'
import longTaskSchemaJson from '../../../rum-events-format/schemas/rum/long_task-schema.json'
import resourceSchemaJson from '../../../rum-events-format/schemas/rum/resource-schema.json'
import viewSchemaJson from '../../../rum-events-format/schemas/rum/view-schema.json'

export function validateFormat(rumEvent: Context) {
export function validateRumFormat(rumEvent: Context) {
const instance = new ajv({
allErrors: true,
})
void instance
.addSchema(_commonSchemaJson, 'schemas/_common-schema.json')
.addSchema(viewSchemaJson, 'schemas/view-schema.json')
.addSchema(actionSchemaJson, 'schemas/action-schema.json')
.addSchema(resourceSchemaJson, 'schemas/resource-schema.json')
.addSchema(longTaskSchemaJson, 'schemas/long_task-schema.json')
.addSchema(errorSchemaJson, 'schemas/error-schema.json')
.addSchema(rumEventsFormatJson, 'rum-events-format.json')
.validate('rum-events-format.json', rumEvent)
.addSchema(_commonSchemaJson, 'rum/_common-schema.json')
.addSchema(viewSchemaJson, 'rum/view-schema.json')
.addSchema(actionSchemaJson, 'rum/action-schema.json')
.addSchema(resourceSchemaJson, 'rum/resource-schema.json')
.addSchema(longTaskSchemaJson, 'rum/long_task-schema.json')
.addSchema(errorSchemaJson, 'rum/error-schema.json')
.addSchema(rumEventsSchemaJson, 'rum-events-schema.json')
.validate('rum-events-schema.json', rumEvent)

if (instance.errors) {
instance.errors.map((error) => fail(`${error.dataPath || 'event'} ${error.message!}`))
Expand Down
4 changes: 2 additions & 2 deletions packages/rum-core/test/specHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import type { CiTestWindow } from '../src/domain/ciTestContext'
import type { RumConfiguration } from '../src/domain/configuration'
import { validateAndBuildRumConfiguration } from '../src/domain/configuration'
import { validateFormat } from './formatValidation'
import { validateRumFormat } from './formatValidation'
import { createRumSessionManagerMock } from './mockRumSessionManager'

export interface TestSetupBuilder {
Expand Down Expand Up @@ -205,7 +205,7 @@ function validateRumEventFormat(rawRumEvent: RawRumEvent) {
url: 'fake url',
},
}
validateFormat(combine(fakeContext, rawRumEvent))
validateRumFormat(combine(fakeContext, rawRumEvent))
}

export type ViewTest = ReturnType<typeof setupViewTest>
Expand Down
22 changes: 16 additions & 6 deletions scripts/generate-schema-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ const { compileFromFile } = require('json-schema-to-typescript')
const prettier = require('prettier')
const { printLog, logAndExit } = require('./utils')

const workingDirectory = path.join(__dirname, '../rum-events-format')
const schemaPath = path.join(workingDirectory, 'rum-events-format.json')
const compiledTypesPath = path.join(__dirname, '../packages/rum-core/src/rumEvent.types.ts')
const schemasDirectoryPath = path.join(__dirname, '../rum-events-format/schemas')
const prettierConfigPath = path.join(__dirname, '../.prettierrc.yml')

async function main() {
await generateTypesFromSchema(
path.join(__dirname, '../packages/rum-core/src/rumEvent.types.ts'),
'rum-events-schema.json'
)
await generateTypesFromSchema(
path.join(__dirname, '../packages/core/src/domain/internalMonitoring/telemetryEvent.types.ts'),
'telemetry-events-schema.json'
)
}

async function generateTypesFromSchema(typesPath, schema) {
const schemaPath = path.join(schemasDirectoryPath, schema)
const prettierConfig = await prettier.resolveConfig(prettierConfigPath)
printLog(`Compiling ${schemaPath}...`)
const compiledTypes = await compileFromFile(schemaPath, {
cwd: workingDirectory,
cwd: schemasDirectoryPath,
bannerComment:
'/* eslint-disable */\n/**\n * DO NOT MODIFY IT BY HAND. Run `yarn rum-events-format:sync` instead.\n*/',
style: prettierConfig,
})
printLog(`Writing ${compiledTypesPath}...`)
fs.writeFileSync(compiledTypesPath, compiledTypes)
printLog(`Writing ${typesPath}...`)
fs.writeFileSync(typesPath, compiledTypes)
printLog('Generation done.')
}

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/lib/framework/createTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { LogsInitConfiguration } from '@datadog/browser-logs'
import type { RumInitConfiguration } from '@datadog/browser-rum-core'
import { deleteAllCookies, withBrowserLogs } from '../helpers/browser'
import { flushEvents } from '../helpers/flushEvents'
import { validateFormat } from '../helpers/validation'
import { validateRumFormat } from '../helpers/validation'
import { EventRegistry } from './eventsRegistry'
import type { Servers } from './httpServers'
import { getTestServers, waitForServersIdle } from './httpServers'
Expand Down Expand Up @@ -191,8 +191,8 @@ async function setUpTest({ baseUrl }: TestContext) {
async function tearDownTest({ serverEvents, bridgeEvents }: TestContext) {
await flushEvents()
expect(serverEvents.internalMonitoring).toEqual([])
validateFormat(serverEvents.rum)
validateFormat(bridgeEvents.rum)
validateRumFormat(serverEvents.rum)
validateRumFormat(bridgeEvents.rum)
await withBrowserLogs((logs) => {
logs.forEach((browserLog) => {
log(`Browser ${browserLog.source}: ${browserLog.level} ${browserLog.message}`)
Expand Down
35 changes: 17 additions & 18 deletions test/e2e/lib/helpers/validation.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import type { RumEvent } from '@datadog/browser-rum'
import ajv from 'ajv'
import rumEventsFormatJson from '../../../../rum-events-format/rum-events-format.json'
import _commonSchemaJson from '../../../../rum-events-format/schemas/_common-schema.json'
import actionSchemaJson from '../../../../rum-events-format/schemas/action-schema.json'
import errorSchemaJson from '../../../../rum-events-format/schemas/error-schema.json'
import longTaskSchemaJson from '../../../../rum-events-format/schemas/long_task-schema.json'
import resourceSchemaJson from '../../../../rum-events-format/schemas/resource-schema.json'
import viewSchemaJson from '../../../../rum-events-format/schemas/view-schema.json'
import rumEventsSchemaJson from '../../../../rum-events-format/schemas/rum-events-schema.json'
import _commonSchemaJson from '../../../../rum-events-format/schemas/rum/_common-schema.json'
import actionSchemaJson from '../../../../rum-events-format/schemas/rum/action-schema.json'
import errorSchemaJson from '../../../../rum-events-format/schemas/rum/error-schema.json'
import longTaskSchemaJson from '../../../../rum-events-format/schemas/rum/long_task-schema.json'
import resourceSchemaJson from '../../../../rum-events-format/schemas/rum/resource-schema.json'
import viewSchemaJson from '../../../../rum-events-format/schemas/rum/view-schema.json'

export function validateFormat(events: RumEvent[]) {
events.forEach((event) => {
export function validateRumFormat(events: RumEvent[]) {
events.forEach((rumEvent) => {
const instance = new ajv({
allErrors: true,
})
void instance
.addSchema(_commonSchemaJson, 'schemas/_common-schema.json')
.addSchema(viewSchemaJson, 'schemas/view-schema.json')
.addSchema(actionSchemaJson, 'schemas/action-schema.json')
.addSchema(resourceSchemaJson, 'schemas/resource-schema.json')
.addSchema(longTaskSchemaJson, 'schemas/long_task-schema.json')
.addSchema(errorSchemaJson, 'schemas/error-schema.json')
.addSchema(rumEventsFormatJson, 'rum-events-format.json')
.validate('rum-events-format.json', event)

.addSchema(_commonSchemaJson, 'rum/_common-schema.json')
.addSchema(viewSchemaJson, 'rum/view-schema.json')
.addSchema(actionSchemaJson, 'rum/action-schema.json')
.addSchema(resourceSchemaJson, 'rum/resource-schema.json')
.addSchema(longTaskSchemaJson, 'rum/long_task-schema.json')
.addSchema(errorSchemaJson, 'rum/error-schema.json')
.addSchema(rumEventsSchemaJson, 'rum-events-schema.json')
.validate('rum-events-schema.json', rumEvent)
if (instance.errors) {
instance.errors.map((error) => fail(`${error.dataPath || 'event'} ${error.message!}`))
}
Expand Down