Skip to content

Commit fcad227

Browse files
committed
Fix package structure; capture client errors
1 parent 894e970 commit fcad227

File tree

6 files changed

+38
-40
lines changed

6 files changed

+38
-40
lines changed

common/api-review/telemetry.api.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { AnyValueMap } from '@opentelemetry/api-logs';
88
import { FirebaseApp } from '@firebase/app';
9+
import { Instrumentation } from 'next';
910
import { LoggerProvider } from '@opentelemetry/sdk-logs';
1011

1112
// @public
@@ -17,13 +18,7 @@ export function flush(telemetry: Telemetry): Promise<void>;
1718
// @public
1819
export function getTelemetry(app?: FirebaseApp): Telemetry;
1920

20-
// @public (undocumented)
21-
export namespace Instrumentation {
22-
// Warning: (ae-forgotten-export) The symbol "InstrumentationOnRequestError" needs to be exported by the entry point index.d.ts
23-
//
24-
// (undocumented)
25-
export type onRequestError = InstrumentationOnRequestError;
26-
}
21+
export { Instrumentation }
2722

2823
// @public
2924
export const nextOnRequestError: Instrumentation.onRequestError;

packages/telemetry/api-extractor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
88
"betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts"
99
},
10-
"bundledPackages": ["next"]
10+
"bundledPackages": ["react"]
1111
}

packages/telemetry/api-extractor.react.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "../../config/api-extractor.json",
3-
"mainEntryPointFilePath": "<projectFolder>/dist/react/index.d.ts",
3+
"mainEntryPointFilePath": "<projectFolder>/dist/react/react/index.d.ts",
44
"dtsRollup": {
55
"enabled": true,
66
"untrimmedFilePath": "<projectFolder>/dist/react/index.d.ts"

packages/telemetry/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
"./react": {
2323
"types": "./dist/react/index.d.ts",
2424
"node": {
25-
"import": "./dist/react-node-esm/index.node.esm.js",
26-
"default": "./dist/react.node.cjs.js"
25+
"import": "./dist/react/index.node.esm.js",
26+
"default": "./dist/react/index.node.cjs.js"
2727
},
2828
"browser": {
29-
"require": "./dist/react.cjs.js",
30-
"import": "./dist/react.esm.js"
29+
"require": "./dist/react/index.cjs.js",
30+
"import": "./dist/react/index.esm.js"
3131
},
32-
"default": "./dist/react.esm.js"
32+
"default": "./dist/react/index.esm.js"
3333
},
3434
"./package.json": "./package.json"
3535
},

packages/telemetry/rollup.config.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ const reactBuilds = [
8585
plugins: [
8686
typescriptPlugin({
8787
typescript,
88-
tsconfigOverride: {
89-
compilerOptions: {
90-
declarationDir: 'dist/react'
91-
}
92-
}
88+
tsconfig: 'tsconfig.react.json'
9389
}),
9490
json()
9591
],
@@ -106,11 +102,7 @@ const reactBuilds = [
106102
plugins: [
107103
typescriptPlugin({
108104
typescript,
109-
tsconfigOverride: {
110-
compilerOptions: {
111-
declarationDir: 'dist/react'
112-
}
113-
}
105+
tsconfig: 'tsconfig.react.json'
114106
}),
115107
json()
116108
],
@@ -130,11 +122,7 @@ const reactNodeBuilds = [
130122
plugins: [
131123
typescriptPlugin({
132124
typescript,
133-
tsconfigOverride: {
134-
compilerOptions: {
135-
declarationDir: 'dist/react'
136-
}
137-
}
125+
tsconfig: 'tsconfig.react.json'
138126
}),
139127
json()
140128
],
@@ -151,11 +139,7 @@ const reactNodeBuilds = [
151139
plugins: [
152140
typescriptPlugin({
153141
typescript,
154-
tsconfigOverride: {
155-
compilerOptions: {
156-
declarationDir: 'dist/react'
157-
}
158-
}
142+
tsconfig: 'tsconfig.react.json'
159143
}),
160144
json(),
161145
emitModulePackageFile()
Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
import React from 'react';
1+
import { getApp } from '@firebase/app';
2+
import { captureError, getTelemetry } from '../api';
3+
import { Component, ReactNode } from 'react';
24

35
export interface FirebaseTelemetryBoundaryProps {
4-
children: React.ReactNode;
6+
children: ReactNode;
57
}
68

7-
export class FirebaseTelemetryBoundary extends React.Component<FirebaseTelemetryBoundaryProps> {
9+
export class FirebaseTelemetryBoundary extends Component<FirebaseTelemetryBoundaryProps> {
810
constructor(public props: FirebaseTelemetryBoundaryProps) {
911
super(props);
12+
}
13+
14+
componentDidMount(): void {
15+
if (typeof window === 'undefined') {
16+
return;
17+
}
18+
19+
// TODO: This will be obsolete once the SDK has a default endpoint
20+
process.env.OTEL_ENDPOINT = window.location.origin;
21+
22+
const telemetry = getTelemetry(getApp());
23+
24+
console.info(telemetry);
25+
26+
window.addEventListener('error', (event: ErrorEvent) => {
27+
captureError(telemetry, event.error, {'example_attribute': 'hello'});
28+
});
29+
30+
// TODO: add listener for unhandledrejection
1031

11-
console.info('init firebase telemetry boundary');
1232
}
1333

14-
render(): React.ReactNode {
15-
console.info('abc');
34+
render(): ReactNode {
1635
return this.props.children;
1736
}
1837
}

0 commit comments

Comments
 (0)