Skip to content

Commit

Permalink
🐛 [RUM-4629] accept null as env/version/service (#2781)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer authored May 24, 2024
1 parent 1bc3671 commit e6db01b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/domain/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,27 @@ describe('validateAndBuildConfiguration', () => {
})

describe('env parameter validation', () => {
it('should not validate the env parameter', () => {
it('should validate the env parameter', () => {
validateAndBuildConfiguration({ clientToken, env: false as any })
expect(displaySpy).toHaveBeenCalledOnceWith('Env must be defined as a string')
})
})

describe('service parameter validation', () => {
it('should not validate the service parameter', () => {
it('should validate the service parameter', () => {
validateAndBuildConfiguration({ clientToken, service: 1 as any })
expect(displaySpy).toHaveBeenCalledOnceWith('Service must be defined as a string')
})

it('should not reject null', () => {
const configuration = validateAndBuildConfiguration({ clientToken, service: null })
expect(displaySpy).not.toHaveBeenCalled()
expect(configuration!.service).toBeUndefined()
})
})

describe('version parameter validation', () => {
it('should not validate the version parameter', () => {
it('should validate the version parameter', () => {
validateAndBuildConfiguration({ clientToken, version: 0 as any })
expect(displaySpy).toHaveBeenCalledOnceWith('Version must be defined as a string')
})
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export interface InitConfiguration {
site?: string | undefined

// tag and context options
service?: string | undefined
env?: string | undefined
version?: string | undefined
service?: string | undefined | null
env?: string | undefined | null
version?: string | undefined | null

// cookie options
/**
Expand Down Expand Up @@ -109,8 +109,8 @@ export interface Configuration extends TransportConfiguration {
messageBytesLimit: number
}

function checkIfString(tag: unknown, tagName: string) {
if (tag !== undefined && typeof tag !== 'string') {
function checkIfString(tag: unknown, tagName: string): tag is string | undefined | null {
if (tag !== undefined && tag !== null && typeof tag !== 'string') {
display.error(`${tagName} must be defined as a string`)
return false
}
Expand Down Expand Up @@ -196,7 +196,7 @@ export function validateAndBuildConfiguration(initConfiguration: InitConfigurati
telemetrySampleRate: initConfiguration.telemetrySampleRate ?? 20,
telemetryConfigurationSampleRate: initConfiguration.telemetryConfigurationSampleRate ?? 5,
telemetryUsageSampleRate: initConfiguration.telemetryUsageSampleRate ?? 5,
service: initConfiguration.service,
service: initConfiguration.service || undefined,
silentMultipleInit: !!initConfiguration.silentMultipleInit,
allowUntrustedEvents: !!initConfiguration.allowUntrustedEvents,
trackingConsent: initConfiguration.trackingConsent ?? TrackingConsent.GRANTED,
Expand Down
8 changes: 8 additions & 0 deletions packages/rum-core/src/domain/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ describe('validateAndBuildRumConfiguration', () => {
).toBe('https://example.org/worker.js')
})
})

describe('version parameter validation', () => {
it('should not reject null', () => {
const configuration = validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, version: null })
expect(displayErrorSpy).not.toHaveBeenCalled()
expect(configuration!.version).toBeUndefined()
})
})
})

describe('serializeRumConfiguration', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function validateAndBuildRumConfiguration(
return assign(
{
applicationId: initConfiguration.applicationId,
version: initConfiguration.version,
version: initConfiguration.version || undefined,
actionNameAttribute: initConfiguration.actionNameAttribute,
sessionReplaySampleRate: initConfiguration.sessionReplaySampleRate ?? 0,
startSessionReplayRecordingManually: !!initConfiguration.startSessionReplayRecordingManually,
Expand Down

0 comments on commit e6db01b

Please sign in to comment.