diff --git a/common/api-review/crashlytics.api.md b/common/api-review/crashlytics.api.md index 0ad57a0505..83e80731e8 100644 --- a/common/api-review/crashlytics.api.md +++ b/common/api-review/crashlytics.api.md @@ -8,9 +8,6 @@ import { AnyValueMap } from '@opentelemetry/api-logs'; import { FirebaseApp } from '@firebase/app'; import { Instrumentation } from 'next'; -// @public -export function captureError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void; - // @public export interface Crashlytics { app: FirebaseApp; @@ -33,6 +30,9 @@ export { Instrumentation } // @public export function nextOnRequestError(crashlyticsOptions?: CrashlyticsOptions): Instrumentation.onRequestError; +// @public +export function recordError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void; + // (No @packageDocumentation comment for this package) diff --git a/docs-devsite/crashlytics_.md b/docs-devsite/crashlytics_.md index 04640934e4..747771690f 100644 --- a/docs-devsite/crashlytics_.md +++ b/docs-devsite/crashlytics_.md @@ -18,8 +18,8 @@ https://github.com/firebase/firebase-js-sdk | function(app, ...) | | [getCrashlytics(app, options)](./crashlytics_.md#getcrashlytics_a9d22a1) | Returns the default [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | | function(crashlytics, ...) | -| [captureError(crashlytics, error, attributes)](./crashlytics_.md#captureerror_6824e74) | Enqueues an error to be uploaded to the Firebase Crashlytics API. | | [flush(crashlytics)](./crashlytics_.md#flush_16fdf66) | Flushes all enqueued Crashlytics data immediately, instead of waiting for default batching. | +| [recordError(crashlytics, error, attributes)](./crashlytics_.md#recorderror_6824e74) | Enqueues an error to be uploaded to the Firebase Crashlytics API. | | function(crashlyticsOptions, ...) | | [nextOnRequestError(crashlyticsOptions)](./crashlytics_.md#nextonrequesterror_3caf5de) | Automatically report uncaught errors from server routes to Firebase Crashlytics. | @@ -71,14 +71,14 @@ const crashlytics = getCrashlytics(app); ## function(crashlytics, ...) -### captureError(crashlytics, error, attributes) {:#captureerror_6824e74} +### flush(crashlytics) {:#flush_16fdf66} -Enqueues an error to be uploaded to the Firebase Crashlytics API. +Flushes all enqueued Crashlytics data immediately, instead of waiting for default batching. Signature: ```typescript -export declare function captureError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void; +export declare function flush(crashlytics: Crashlytics): Promise; ``` #### Parameters @@ -86,21 +86,21 @@ export declare function captureError(crashlytics: Crashlytics, error: unknown, a | Parameter | Type | Description | | --- | --- | --- | | crashlytics | [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) | The [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) instance. | -| error | unknown | The caught exception, typically an | -| attributes | AnyValueMap | = Optional, arbitrary attributes to attach to the error log | Returns: -void +Promise<void> -### flush(crashlytics) {:#flush_16fdf66} +a promise which is resolved when all flushes are complete -Flushes all enqueued Crashlytics data immediately, instead of waiting for default batching. +### recordError(crashlytics, error, attributes) {:#recorderror_6824e74} + +Enqueues an error to be uploaded to the Firebase Crashlytics API. Signature: ```typescript -export declare function flush(crashlytics: Crashlytics): Promise; +export declare function recordError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void; ``` #### Parameters @@ -108,12 +108,12 @@ export declare function flush(crashlytics: Crashlytics): Promise; | Parameter | Type | Description | | --- | --- | --- | | crashlytics | [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) | The [Crashlytics](./crashlytics_.crashlytics.md#crashlytics_interface) instance. | +| error | unknown | The caught exception, typically an Error object | +| attributes | AnyValueMap | Optional, arbitrary attributes to attach to the error log | Returns: -Promise<void> - -a promise which is resolved when all flushes are complete +void ## function(crashlyticsOptions, ...) diff --git a/packages/crashlytics/src/angular/index.test.ts b/packages/crashlytics/src/angular/index.test.ts index 36fac9481f..1a86b25f0a 100644 --- a/packages/crashlytics/src/angular/index.test.ts +++ b/packages/crashlytics/src/angular/index.test.ts @@ -53,14 +53,14 @@ describe('FirebaseErrorHandler', () => { let fakeCrashlytics: Crashlytics; - let captureErrorStub: sinon.SinonStub; + let recordErrorStub: sinon.SinonStub; let getCrashlyticsStub: sinon.SinonStub; beforeEach(() => { app = initializeApp({ projectId: 'p', appId: 'fakeapp' }); fakeCrashlytics = {} as Crashlytics; - captureErrorStub = stub(crashlytics, 'captureError'); + recordErrorStub = stub(crashlytics, 'recordError'); getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns( fakeCrashlytics ); @@ -93,7 +93,7 @@ describe('FirebaseErrorHandler', () => { const testError = new Error('Test error message'); errorHandler.handleError(testError); expect(getCrashlyticsStub).to.have.been.called; - expect(captureErrorStub).to.have.been.calledWith( + expect(recordErrorStub).to.have.been.calledWith( fakeCrashlytics, testError, { @@ -107,8 +107,8 @@ describe('FirebaseErrorHandler', () => { const testError = new Error('Test error message'); errorHandler.handleError(testError); - expect(captureErrorStub).to.have.been.called; - expect(captureErrorStub).to.have.been.calledWith( + expect(recordErrorStub).to.have.been.called; + expect(recordErrorStub).to.have.been.calledWith( fakeCrashlytics, testError, { diff --git a/packages/crashlytics/src/angular/index.ts b/packages/crashlytics/src/angular/index.ts index 015c275cad..aaae4b5931 100644 --- a/packages/crashlytics/src/angular/index.ts +++ b/packages/crashlytics/src/angular/index.ts @@ -20,7 +20,7 @@ import { ErrorHandler, inject } from '@angular/core'; // eslint-disable-next-line import/no-extraneous-dependencies import { ActivatedRouteSnapshot, Router } from '@angular/router'; import { registerCrashlytics } from '../register'; -import { captureError, getCrashlytics } from '../api'; +import { recordError, getCrashlytics } from '../api'; import { Crashlytics, CrashlyticsOptions } from '../public-types'; import { FirebaseApp } from '@firebase/app'; @@ -90,7 +90,7 @@ export class FirebaseErrorHandler implements ErrorHandler { 'angular_route_path': this.getSafeRoutePath(this.router) }; - captureError(this.crashlytics, error, attributes); + recordError(this.crashlytics, error, attributes); } /** diff --git a/packages/crashlytics/src/api.test.ts b/packages/crashlytics/src/api.test.ts index b5da047abf..3db8cee705 100644 --- a/packages/crashlytics/src/api.test.ts +++ b/packages/crashlytics/src/api.test.ts @@ -33,7 +33,7 @@ import { } from '@firebase/app'; import { Component, ComponentType } from '@firebase/component'; import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types'; -import { captureError, flush, getCrashlytics } from './api'; +import { recordError, flush, getCrashlytics } from './api'; import { LOG_ENTRY_ATTRIBUTE_KEYS, CRASHLYTICS_SESSION_ID_KEY @@ -181,13 +181,13 @@ describe('Top level API', () => { }); }); - describe('captureError()', () => { + describe('recordError()', () => { it('should capture an Error object correctly', () => { const error = new Error('This is a test error'); error.stack = '...stack trace...'; error.name = 'TestError'; - captureError(fakeCrashlytics, error); + recordError(fakeCrashlytics, error); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -205,7 +205,7 @@ describe('Top level API', () => { const error = new Error('error with no stack'); error.stack = undefined; - captureError(fakeCrashlytics, error); + recordError(fakeCrashlytics, error); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -220,7 +220,7 @@ describe('Top level API', () => { }); it('should capture a string error correctly', () => { - captureError(fakeCrashlytics, 'a string error'); + recordError(fakeCrashlytics, 'a string error'); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -233,7 +233,7 @@ describe('Top level API', () => { }); it('should capture an unknown error type correctly', () => { - captureError(fakeCrashlytics, 12345); + recordError(fakeCrashlytics, 12345); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -259,7 +259,7 @@ describe('Top level API', () => { span.spanContext().traceId = 'my-trace'; span.spanContext().spanId = 'my-span'; - captureError(fakeCrashlytics, error); + recordError(fakeCrashlytics, error); span.end(); }); @@ -280,7 +280,7 @@ describe('Top level API', () => { error.stack = '...stack trace...'; error.name = 'TestError'; - captureError(fakeCrashlytics, error, { + recordError(fakeCrashlytics, error, { strAttr: 'string attribute', mapAttr: { boolAttr: true, @@ -315,7 +315,7 @@ describe('Top level API', () => { appVersion: '1.0.0' }; - captureError(crashlytics, 'a string error'); + recordError(crashlytics, 'a string error'); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -328,7 +328,7 @@ describe('Top level API', () => { it('should use auto constants if available', () => { AUTO_CONSTANTS.appVersion = '1.2.3'; - captureError(fakeCrashlytics, 'a string error'); + recordError(fakeCrashlytics, 'a string error'); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -342,7 +342,7 @@ describe('Top level API', () => { it('should retrieve existing session ID from sessionStorage', () => { storage[CRASHLYTICS_SESSION_ID_KEY] = 'existing-session-id'; - captureError(fakeCrashlytics, 'error'); + recordError(fakeCrashlytics, 'error'); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -364,7 +364,7 @@ describe('Top level API', () => { writable: true }); - captureError(fakeCrashlytics, 'error'); + recordError(fakeCrashlytics, 'error'); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -385,7 +385,7 @@ describe('Top level API', () => { writable: true }); - captureError(fakeCrashlytics, 'error'); + recordError(fakeCrashlytics, 'error'); expect(emittedLogs.length).to.equal(1); const log = emittedLogs[0]; @@ -397,8 +397,8 @@ describe('Top level API', () => { describe('flush()', () => { it('should flush logs correctly', async () => { - captureError(fakeCrashlytics, 'error1'); - captureError(fakeCrashlytics, 'error2'); + recordError(fakeCrashlytics, 'error1'); + recordError(fakeCrashlytics, 'error2'); expect(emittedLogs.length).to.equal(2); diff --git a/packages/crashlytics/src/api.ts b/packages/crashlytics/src/api.ts index c7acddc023..a55315a74f 100644 --- a/packages/crashlytics/src/api.ts +++ b/packages/crashlytics/src/api.ts @@ -71,10 +71,10 @@ export function getCrashlytics( * @public * * @param crashlytics - The {@link Crashlytics} instance. - * @param error - The caught exception, typically an {@link Error} - * @param attributes = Optional, arbitrary attributes to attach to the error log + * @param error - The caught exception, typically an Error object + * @param attributes - Optional, arbitrary attributes to attach to the error log */ -export function captureError( +export function recordError( crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap diff --git a/packages/crashlytics/src/next.test.ts b/packages/crashlytics/src/next.test.ts index 1fd78855f7..dc4476194d 100644 --- a/packages/crashlytics/src/next.test.ts +++ b/packages/crashlytics/src/next.test.ts @@ -30,7 +30,7 @@ use(chaiAsPromised); describe('nextOnRequestError', () => { let getCrashlyticsStub: sinon.SinonStub; - let captureErrorStub: sinon.SinonStub; + let recordErrorStub: sinon.SinonStub; let fakeApp: FirebaseApp; let fakeCrashlytics: Crashlytics; @@ -42,7 +42,7 @@ describe('nextOnRequestError', () => { getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns( fakeCrashlytics ); - captureErrorStub = stub(crashlytics, 'captureError'); + recordErrorStub = stub(crashlytics, 'recordError'); }); afterEach(() => { @@ -71,7 +71,7 @@ describe('nextOnRequestError', () => { await nextOnRequestError()(error, errorRequest, errorContext); expect(getCrashlyticsStub).to.have.been.calledOnceWith(fakeApp); - expect(captureErrorStub).to.have.been.calledOnceWith( + expect(recordErrorStub).to.have.been.calledOnceWith( fakeCrashlytics, error, { diff --git a/packages/crashlytics/src/next.ts b/packages/crashlytics/src/next.ts index bfce82c0d9..8577483c52 100644 --- a/packages/crashlytics/src/next.ts +++ b/packages/crashlytics/src/next.ts @@ -16,7 +16,7 @@ */ import { getApp } from '@firebase/app'; -import { captureError, getCrashlytics } from './api'; +import { recordError, getCrashlytics } from './api'; // eslint-disable-next-line import/no-extraneous-dependencies import { Instrumentation } from 'next'; import { CrashlyticsOptions } from './public-types'; @@ -52,6 +52,6 @@ export function nextOnRequestError( 'nextjs_route_type': errorContext.routeType }; - captureError(crashlytics, error, attributes); + recordError(crashlytics, error, attributes); }; } diff --git a/packages/crashlytics/src/react/index.test.tsx b/packages/crashlytics/src/react/index.test.tsx index 99d4deda57..7ea2bbac55 100644 --- a/packages/crashlytics/src/react/index.test.tsx +++ b/packages/crashlytics/src/react/index.test.tsx @@ -32,7 +32,7 @@ use(chaiAsPromised); describe('FirebaseCrashlytics', () => { let getCrashlyticsStub: sinon.SinonStub; - let captureErrorStub: sinon.SinonStub; + let recordErrorStub: sinon.SinonStub; let fakeApp: FirebaseApp; let fakeCrashlytics: Crashlytics; @@ -40,8 +40,10 @@ describe('FirebaseCrashlytics', () => { fakeApp = { name: 'fakeApp' } as FirebaseApp; fakeCrashlytics = {} as Crashlytics; - getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns(fakeCrashlytics); - captureErrorStub = stub(crashlytics, 'captureError'); + getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns( + fakeCrashlytics + ); + recordErrorStub = stub(crashlytics, 'recordError'); }); afterEach(() => { @@ -57,7 +59,7 @@ describe('FirebaseCrashlytics', () => { window.addEventListener('error', (event: ErrorEvent) => { // Registers another listener (sequential) to confirm behaviour. expect(getCrashlyticsStub).to.have.been.calledWith(fakeApp); - expect(captureErrorStub).to.have.been.calledWith(fakeCrashlytics, error); + expect(recordErrorStub).to.have.been.calledWith(fakeCrashlytics, error); done(); }); window.dispatchEvent(new ErrorEvent('error', { error })); @@ -72,6 +74,6 @@ describe('FirebaseCrashlytics', () => { new PromiseRejectionEvent('unhandledrejection', { reason, promise }) ); expect(getCrashlyticsStub).to.have.been.calledWith(fakeApp); - expect(captureErrorStub).to.have.been.calledWith(fakeCrashlytics, reason); + expect(recordErrorStub).to.have.been.calledWith(fakeCrashlytics, reason); }); }); diff --git a/packages/crashlytics/src/react/index.ts b/packages/crashlytics/src/react/index.ts index 2e2cf53a0c..995f88c17a 100644 --- a/packages/crashlytics/src/react/index.ts +++ b/packages/crashlytics/src/react/index.ts @@ -17,7 +17,7 @@ import { FirebaseApp } from '@firebase/app'; import { registerCrashlytics } from '../register'; -import { captureError, getCrashlytics } from '../api'; +import { recordError, getCrashlytics } from '../api'; import { CrashlyticsOptions } from '../public-types'; import { useEffect } from 'react'; @@ -84,11 +84,11 @@ export function FirebaseCrashlytics({ } const errorListener = (event: ErrorEvent): void => { - captureError(crashlytics, event.error, {}); + recordError(crashlytics, event.error, {}); }; const unhandledRejectionListener = (event: PromiseRejectionEvent): void => { - captureError(crashlytics, event.reason, {}); + recordError(crashlytics, event.reason, {}); }; try {