Skip to content
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
6 changes: 3 additions & 3 deletions common/api-review/crashlytics.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)

Expand Down
26 changes: 13 additions & 13 deletions docs-devsite/crashlytics_.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ https://github.com/firebase/firebase-js-sdk
| <b>function(app, ...)</b> |
| [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. |
| <b>function(crashlytics, ...)</b> |
| [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. |
| <b>function(crashlyticsOptions, ...)</b> |
| [nextOnRequestError(crashlyticsOptions)](./crashlytics_.md#nextonrequesterror_3caf5de) | Automatically report uncaught errors from server routes to Firebase Crashlytics. |

Expand Down Expand Up @@ -71,49 +71,49 @@ 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.

<b>Signature:</b>

```typescript
export declare function captureError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void;
export declare function flush(crashlytics: Crashlytics): Promise<void>;
```

#### Parameters

| 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 |

<b>Returns:</b>

void
Promise&lt;void&gt;

### 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.

<b>Signature:</b>

```typescript
export declare function flush(crashlytics: Crashlytics): Promise<void>;
export declare function recordError(crashlytics: Crashlytics, error: unknown, attributes?: AnyValueMap): void;
```

#### Parameters

| 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 |

<b>Returns:</b>

Promise&lt;void&gt;

a promise which is resolved when all flushes are complete
void

## function(crashlyticsOptions, ...)

Expand Down
10 changes: 5 additions & 5 deletions packages/crashlytics/src/angular/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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,
{
Expand All @@ -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,
{
Expand Down
4 changes: 2 additions & 2 deletions packages/crashlytics/src/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}

/**
Expand Down
30 changes: 15 additions & 15 deletions packages/crashlytics/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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();
});

Expand All @@ -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,
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions packages/crashlytics/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/crashlytics/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,7 +42,7 @@ describe('nextOnRequestError', () => {
getCrashlyticsStub = stub(crashlytics, 'getCrashlytics').returns(
fakeCrashlytics
);
captureErrorStub = stub(crashlytics, 'captureError');
recordErrorStub = stub(crashlytics, 'recordError');
});

afterEach(() => {
Expand Down Expand Up @@ -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,
{
Expand Down
4 changes: 2 additions & 2 deletions packages/crashlytics/src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,6 +52,6 @@ export function nextOnRequestError(
'nextjs_route_type': errorContext.routeType
};

captureError(crashlytics, error, attributes);
recordError(crashlytics, error, attributes);
};
}
12 changes: 7 additions & 5 deletions packages/crashlytics/src/react/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ use(chaiAsPromised);

describe('FirebaseCrashlytics', () => {
let getCrashlyticsStub: sinon.SinonStub;
let captureErrorStub: sinon.SinonStub;
let recordErrorStub: sinon.SinonStub;
let fakeApp: FirebaseApp;
let fakeCrashlytics: Crashlytics;

beforeEach(() => {
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(() => {
Expand All @@ -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 }));
Expand All @@ -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);
});
});
6 changes: 3 additions & 3 deletions packages/crashlytics/src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand Down
Loading