Skip to content

Commit

Permalink
Update error observable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Feb 9, 2022
1 parent 4b8ea23 commit 197dadc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/logs/src/boot/startLogs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const DEFAULT_MESSAGE = { status: StatusType.info, message: 'message' }
describe('logs', () => {
let sessionIsTracked: boolean
let server: sinon.SinonFakeServer
let errorObservable: Observable<RawError>
let rawErrorObservable: Observable<RawError>
let consoleObservable: Observable<ConsoleLog>
const sessionManager: LogsSessionManager = {
findTrackedSession: () => (sessionIsTracked ? { id: SESSION_ID } : undefined),
Expand All @@ -72,7 +72,7 @@ describe('logs', () => {
const configuration = { ...baseConfiguration, ...configurationOverrides }
return doStartLogs(
configuration,
errorObservable,
rawErrorObservable,
consoleObservable,
internalMonitoring,
sessionManager,
Expand All @@ -82,7 +82,7 @@ describe('logs', () => {

beforeEach(() => {
sessionIsTracked = true
errorObservable = new Observable<RawError>()
rawErrorObservable = new Observable<RawError>()
consoleObservable = new Observable<ConsoleLog>()
server = sinon.fakeServer.create()
})
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('logs', () => {
}
sendLogStrategy = startLogs({ errorLogger: new Logger(sendLog) })

errorObservable.notify({
rawErrorObservable.notify({
message: 'error!',
source: ErrorSource.SOURCE,
startClocks: { relative: 1234 as RelativeTime, timeStamp: getTimeStamp(1234 as RelativeTime) },
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('logs', () => {
const sendLogSpy = jasmine.createSpy()
startLogs({ errorLogger: new Logger(sendLogSpy) })

errorObservable.notify({
rawErrorObservable.notify({
message: 'error!',
source: ErrorSource.SOURCE,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
Expand Down
36 changes: 22 additions & 14 deletions packages/logs/src/boot/startLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import type { LogsEvent } from '../logsEvent.types'
export function startLogs(configuration: LogsConfiguration, logger: Logger) {
const internalMonitoring = startInternalMonitoring(configuration)

const errorObservable = new Observable<RawError>()
const rawErrorObservable = new Observable<RawError>()

if (configuration.forwardErrorsToLogs) {
trackRuntimeError(errorObservable)
trackNetworkError(configuration, errorObservable)
trackRuntimeError(rawErrorObservable)
trackNetworkError(configuration, rawErrorObservable)
}
const consoleObservable = initConsoleObservable(configuration.forwardConsoleLogs)

Expand All @@ -38,12 +38,12 @@ export function startLogs(configuration: LogsConfiguration, logger: Logger) {
? startLogsSessionManager(configuration)
: startLogsSessionManagerStub(configuration)

return doStartLogs(configuration, errorObservable, consoleObservable, internalMonitoring, session, logger)
return doStartLogs(configuration, rawErrorObservable, consoleObservable, internalMonitoring, session, logger)
}

export function doStartLogs(
configuration: LogsConfiguration,
errorObservable: Observable<RawError>,
rawErrorObservable: Observable<RawError>,
consoleObservable: Observable<ConsoleLog>,
internalMonitoring: InternalMonitoring,
sessionManager: LogsSessionManager,
Expand All @@ -55,7 +55,7 @@ export function doStartLogs(
})
)

const assemble = buildAssemble(sessionManager, configuration, reportError)
const assemble = buildAssemble(sessionManager, configuration, reportRawError)

let onLogEventCollected: (message: Context) => void
if (canUseEventBridge()) {
Expand All @@ -66,7 +66,7 @@ export function doStartLogs(
onLogEventCollected = (message) => batch.add(message)
}

function reportError(error: RawError) {
function reportRawError(error: RawError) {
const messageContext: Partial<LogsEvent> = {
date: error.startClocks.timeStamp,
error: {
Expand Down Expand Up @@ -106,7 +106,7 @@ export function doStartLogs(
logger.log(log.message, messageContext, LogStatusForApi[log.api])
}

errorObservable.subscribe(reportError)
rawErrorObservable.subscribe(reportRawError)
consoleObservable.subscribe(reportConsoleLog)

return (message: LogsMessage, currentContext: Context) => {
Expand All @@ -120,14 +120,22 @@ export function doStartLogs(
export function buildAssemble(
sessionManager: LogsSessionManager,
configuration: LogsConfiguration,
reportError: (error: RawError) => void
reportRawError: (error: RawError) => void
) {
const logRateLimiters = {
[StatusType.error]: createEventRateLimiter(StatusType.error, configuration.eventRateLimiterThreshold, reportError),
[StatusType.warn]: createEventRateLimiter(StatusType.warn, configuration.eventRateLimiterThreshold, reportError),
[StatusType.info]: createEventRateLimiter(StatusType.info, configuration.eventRateLimiterThreshold, reportError),
[StatusType.debug]: createEventRateLimiter(StatusType.debug, configuration.eventRateLimiterThreshold, reportError),
['custom']: createEventRateLimiter('custom', configuration.eventRateLimiterThreshold, reportError),
[StatusType.error]: createEventRateLimiter(
StatusType.error,
configuration.eventRateLimiterThreshold,
reportRawError
),
[StatusType.warn]: createEventRateLimiter(StatusType.warn, configuration.eventRateLimiterThreshold, reportRawError),
[StatusType.info]: createEventRateLimiter(StatusType.info, configuration.eventRateLimiterThreshold, reportRawError),
[StatusType.debug]: createEventRateLimiter(
StatusType.debug,
configuration.eventRateLimiterThreshold,
reportRawError
),
['custom']: createEventRateLimiter('custom', configuration.eventRateLimiterThreshold, reportRawError),
}

return (message: LogsMessage, currentContext: Context) => {
Expand Down

0 comments on commit 197dadc

Please sign in to comment.