Skip to content

Commit

Permalink
♻️ rename remaning references
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed May 23, 2022
1 parent c6363aa commit 444f782
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 163 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface Configuration extends TransportConfiguration {

// Event limits
eventRateLimiterThreshold: number // Limit the maximum number of actions, errors and logs per minutes
maxInternalMonitoringMessagesPerPage: number
maxTelemetryEventsPerPage: number

// Batch configuration
batchBytesLimit: number
Expand Down Expand Up @@ -107,7 +107,7 @@ export function validateAndBuildConfiguration(initConfiguration: InitConfigurati
batchBytesLimit: isExperimentalFeatureEnabled('lower-batch-size') ? 10 * ONE_KILO_BYTE : 16 * ONE_KILO_BYTE,

eventRateLimiterThreshold: 3000,
maxInternalMonitoringMessagesPerPage: 15,
maxTelemetryEventsPerPage: 15,

/**
* flush automatically, aim to be lower than ALB connection timeout
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/domain/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export {
Telemetry,
MonitoringMessage,
RawTelemetryEvent,
monitored,
monitor,
callMonitored,
addMonitoringMessage,
addMonitoringError,
startFakeInternalMonitoring,
resetInternalMonitoring,
addTelemetryDebug,
addTelemetryError,
startFakeTelemetry,
resetTelemetry,
setDebugMode,
startInternalMonitoring,
startTelemetry,
isTelemetryReplicationAllowed,
} from './telemetry'
export * from './telemetryEvent.types'
70 changes: 35 additions & 35 deletions packages/core/src/domain/telemetry/telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import type { Telemetry } from './telemetry'
import {
monitor,
monitored,
resetInternalMonitoring,
startInternalMonitoring,
resetTelemetry,
startTelemetry,
callMonitored,
setDebugMode,
scrubCustomerFrames,
} from './telemetry'
import type { TelemetryEvent, TelemetryErrorEvent } from './telemetryEvent.types'

const configuration: Partial<Configuration> = {
maxInternalMonitoringMessagesPerPage: 7,
maxTelemetryEventsPerPage: 7,
telemetrySampleRate: 100,
}

describe('internal monitoring', () => {
describe('telemetry', () => {
afterEach(() => {
resetInternalMonitoring()
resetTelemetry()
})

describe('decorator', () => {
Expand Down Expand Up @@ -71,9 +71,9 @@ describe('internal monitoring', () => {
let notifySpy: jasmine.Spy<(event: TelemetryEvent) => void>

beforeEach(() => {
const { telemetryEventObservable } = startInternalMonitoring(configuration as Configuration)
const { observable } = startTelemetry(configuration as Configuration)
notifySpy = jasmine.createSpy('notified')
telemetryEventObservable.subscribe(notifySpy)
observable.subscribe(notifySpy)
})

it('should preserve original behavior', () => {
Expand All @@ -88,25 +88,25 @@ describe('internal monitoring', () => {
it('should report error', () => {
candidate.monitoredThrowing()

const message = notifySpy.calls.mostRecent().args[0] as TelemetryErrorEvent
expect(message.telemetry.message).toEqual('monitored')
expect(message.telemetry.error!.stack).toMatch('monitored')
const event = notifySpy.calls.mostRecent().args[0] as TelemetryErrorEvent
expect(event.telemetry.message).toEqual('monitored')
expect(event.telemetry.error!.stack).toMatch('monitored')
})

it('should report string error', () => {
candidate.monitoredStringErrorThrowing()

const message = notifySpy.calls.mostRecent().args[0] as TelemetryErrorEvent
expect(message.telemetry.message).toEqual('Uncaught "string error"')
expect(message.telemetry.error!.stack).toMatch('Not an instance of error')
const event = notifySpy.calls.mostRecent().args[0] as TelemetryErrorEvent
expect(event.telemetry.message).toEqual('Uncaught "string error"')
expect(event.telemetry.error!.stack).toMatch('Not an instance of error')
})

it('should report object error', () => {
candidate.monitoredObjectErrorThrowing()

const message = notifySpy.calls.mostRecent().args[0] as TelemetryErrorEvent
expect(message.telemetry.message).toEqual('Uncaught {"foo":"bar"}')
expect(message.telemetry.error!.stack).toMatch('Not an instance of error')
const event = notifySpy.calls.mostRecent().args[0] as TelemetryErrorEvent
expect(event.telemetry.message).toEqual('Uncaught {"foo":"bar"}')
expect(event.telemetry.error!.stack).toMatch('Not an instance of error')
})
})
})
Expand All @@ -119,9 +119,9 @@ describe('internal monitoring', () => {
let notifySpy: jasmine.Spy<(event: TelemetryEvent) => void>

beforeEach(() => {
const { telemetryEventObservable } = startInternalMonitoring(configuration as Configuration)
const { observable } = startTelemetry(configuration as Configuration)
notifySpy = jasmine.createSpy('notified')
telemetryEventObservable.subscribe(notifySpy)
observable.subscribe(notifySpy)
})

describe('direct call', () => {
Expand Down Expand Up @@ -160,25 +160,25 @@ describe('internal monitoring', () => {
})

describe('telemetry context', () => {
let internalMonitoring: Telemetry
let telemetry: Telemetry
let notifySpy: jasmine.Spy<(event: TelemetryEvent) => void>

beforeEach(() => {
internalMonitoring = startInternalMonitoring(configuration as Configuration)
telemetry = startTelemetry(configuration as Configuration)
notifySpy = jasmine.createSpy('notified')
internalMonitoring.telemetryEventObservable.subscribe(notifySpy)
telemetry.observable.subscribe(notifySpy)
})

it('should be added to error messages', () => {
internalMonitoring.setTelemetryContextProvider(() => ({
it('should be added to telemetry events', () => {
telemetry.setContextProvider(() => ({
foo: 'bar',
}))
callMonitored(() => {
throw new Error('message')
})
expect(notifySpy.calls.mostRecent().args[0].foo).toEqual('bar')

internalMonitoring.setTelemetryContextProvider(() => ({}))
telemetry.setContextProvider(() => ({}))
callMonitored(() => {
throw new Error('message')
})
Expand All @@ -191,7 +191,7 @@ describe('internal monitoring', () => {

beforeEach(() => {
displaySpy = spyOn(display, 'error')
startInternalMonitoring(configuration as Configuration)
startTelemetry(configuration as Configuration)
})

it('when not called, should not display error', () => {
Expand All @@ -213,7 +213,7 @@ describe('internal monitoring', () => {
})

it('when called and telemetry not sampled, should display error', () => {
startInternalMonitoring({ ...configuration, telemetrySampleRate: 0 } as Configuration)
startTelemetry({ ...configuration, telemetrySampleRate: 0 } as Configuration)
setDebugMode(true)

callMonitored(() => {
Expand All @@ -225,19 +225,19 @@ describe('internal monitoring', () => {
})

describe('sampling', () => {
let internalMonitoring: Telemetry
let telemetry: Telemetry
let notifySpy: jasmine.Spy<(event: TelemetryEvent & Context) => void>

beforeEach(() => {
internalMonitoring = startInternalMonitoring(configuration as Configuration)
telemetry = startTelemetry(configuration as Configuration)
notifySpy = jasmine.createSpy('notified')
internalMonitoring.telemetryEventObservable.subscribe(notifySpy)
telemetry.observable.subscribe(notifySpy)
})

it('should notify when sampled', () => {
spyOn(Math, 'random').and.callFake(() => 0)
internalMonitoring = startInternalMonitoring({ ...configuration, telemetrySampleRate: 50 } as Configuration)
internalMonitoring.telemetryEventObservable.subscribe(notifySpy)
telemetry = startTelemetry({ ...configuration, telemetrySampleRate: 50 } as Configuration)
telemetry.observable.subscribe(notifySpy)

callMonitored(() => {
throw new Error('message')
Expand All @@ -248,8 +248,8 @@ describe('internal monitoring', () => {

it('should not notify when not sampled', () => {
spyOn(Math, 'random').and.callFake(() => 1)
internalMonitoring = startInternalMonitoring({ ...configuration, telemetrySampleRate: 50 } as Configuration)
internalMonitoring.telemetryEventObservable.subscribe(notifySpy)
telemetry = startTelemetry({ ...configuration, telemetrySampleRate: 50 } as Configuration)
telemetry.observable.subscribe(notifySpy)

callMonitored(() => {
throw new Error('message')
Expand All @@ -265,9 +265,9 @@ describe('internal monitoring', () => {
{ site: INTAKE_SITE_US1, enabled: true },
].forEach(({ site, enabled }) => {
it(`should be ${enabled ? 'enabled' : 'disabled'} on ${site}`, () => {
const internalMonitoring = startInternalMonitoring({ ...configuration, site } as Configuration)
const telemetry = startTelemetry({ ...configuration, site } as Configuration)
const notifySpy = jasmine.createSpy('notified')
internalMonitoring.telemetryEventObservable.subscribe(notifySpy)
telemetry.observable.subscribe(notifySpy)

callMonitored(() => {
throw new Error('message')
Expand Down
Loading

0 comments on commit 444f782

Please sign in to comment.