Skip to content

Commit c6756b8

Browse files
committed
Basic scaffolding to init telemetry package
1 parent 119b78e commit c6756b8

File tree

10 files changed

+222
-6
lines changed

10 files changed

+222
-6
lines changed

packages/telemetry/index.node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
* just use index.ts
2323
*/
2424

25-
import { testFxn } from './src';
25+
import { registerTelemetry } from './src/index';
2626

2727
console.log('Hi Node.js Users!');
28-
testFxn();
28+
registerTelemetry();
29+
30+
export * from './src/api';
31+
export * from './src/public-types';

packages/telemetry/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { testFxn } from './src';
18+
import { registerTelemetry } from './src';
1919

20-
testFxn();
20+
registerTelemetry();
21+
22+
export * from './src/api';
23+
export * from './src/public-types';

packages/telemetry/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@
4343
"@firebase/app-types": "0.x"
4444
},
4545
"dependencies": {
46-
"tslib": "^2.1.0"
46+
"tslib": "^2.1.0",
47+
"@firebase/component": "0.7.0"
4748
},
4849
"license": "Apache-2.0",
4950
"devDependencies": {
5051
"@firebase/app": "0.14.1",
52+
"@rollup/plugin-json": "6.1.0",
5153
"rollup": "2.79.2",
54+
"rollup-plugin-replace": "2.2.0",
5255
"rollup-plugin-typescript2": "0.36.0",
5356
"typescript": "5.5.4"
5457
},

packages/telemetry/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import json from '@rollup/plugin-json';
1819
import typescriptPlugin from 'rollup-plugin-typescript2';
1920
import typescript from 'typescript';
2021
import pkg from './package.json';
@@ -24,7 +25,7 @@ const deps = Object.keys(
2425
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
2526
);
2627

27-
const buildPlugins = [typescriptPlugin({ typescript })];
28+
const buildPlugins = [typescriptPlugin({ typescript }), json()];
2829

2930
const browserBuilds = [
3031
{

packages/telemetry/src/api.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { _getProvider, FirebaseApp, getApp } from '@firebase/app';
19+
import { TELEMETRY_TYPE } from './constants';
20+
import { Telemetry } from './public-types';
21+
import { Provider } from '@firebase/component';
22+
23+
/**
24+
* Returns the default {@link Telemetry} instance that is associated with the provided
25+
* {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new instance with the
26+
* default settings.
27+
*
28+
* @example
29+
* ```javascript
30+
* const telemetry = getTelemetry(app);
31+
* ```
32+
*
33+
* @param app - The {@link @firebase/app#FirebaseApp} to use.
34+
* @returns The default {@link Telemetry} instance for the given {@link @firebase/app#FirebaseApp}.
35+
*
36+
* @public
37+
*/
38+
export function getTelemetry(app: FirebaseApp = getApp()): Telemetry {
39+
// Dependencies
40+
const telemetryProvider: Provider<'telemetry'> = _getProvider(
41+
app,
42+
TELEMETRY_TYPE
43+
);
44+
45+
return telemetryProvider.getImmediate();
46+
}

packages/telemetry/src/constants.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/** Type constant for Firebase Telemetry. */
19+
export const TELEMETRY_TYPE = 'telemetry';

packages/telemetry/src/index.node.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { _registerComponent, registerVersion } from '@firebase/app';
19+
import { TestType } from './types/index';
20+
import { Component, ComponentType } from '@firebase/component';
21+
import { TELEMETRY_TYPE } from './constants';
22+
import { name, version } from '../package.json';
23+
import { TelemetryService } from './service';
24+
25+
export function testFxn(): number {
26+
const _thing: TestType = {};
27+
console.log('hi');
28+
return 42;
29+
}
30+
31+
declare module '@firebase/component' {
32+
interface NameServiceMapping {
33+
[TELEMETRY_TYPE]: TelemetryService;
34+
}
35+
}
36+
37+
export function registerTelemetry(): void {
38+
_registerComponent(
39+
new Component(
40+
TELEMETRY_TYPE,
41+
container => {
42+
// getImmediate for FirebaseApp will always succeed
43+
const app = container.getProvider('app').getImmediate();
44+
return new TelemetryService(app);
45+
},
46+
ComponentType.PUBLIC
47+
)
48+
);
49+
50+
registerVersion(name, version, 'node');
51+
// BUILD_TARGET will be replaced by values like esm, cjs, etc during the compilation
52+
registerVersion(name, version, '__BUILD_TARGET__');
53+
}

packages/telemetry/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,39 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { _registerComponent, registerVersion } from '@firebase/app';
1819
import { TestType } from './types/index';
20+
import { Component, ComponentType } from '@firebase/component';
21+
import { TELEMETRY_TYPE } from './constants';
22+
import { name, version } from '../package.json';
23+
import { TelemetryService } from './service';
1924

2025
export function testFxn(): number {
2126
const _thing: TestType = {};
2227
console.log('hi');
2328
return 42;
2429
}
30+
31+
declare module '@firebase/component' {
32+
interface NameServiceMapping {
33+
[TELEMETRY_TYPE]: TelemetryService;
34+
}
35+
}
36+
37+
export function registerTelemetry(): void {
38+
_registerComponent(
39+
new Component(
40+
TELEMETRY_TYPE,
41+
(container, {}) => {
42+
// getImmediate for FirebaseApp will always succeed
43+
const app = container.getProvider('app').getImmediate();
44+
return new TelemetryService(app);
45+
},
46+
ComponentType.PUBLIC
47+
)
48+
);
49+
50+
registerVersion(name, version);
51+
// BUILD_TARGET will be replaced by values like esm, cjs, etc during the compilation
52+
registerVersion(name, version, '__BUILD_TARGET__');
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { FirebaseApp } from '@firebase/app';
19+
20+
/**
21+
* An instance of the Firebase Telemetry SDK.
22+
*
23+
* Do not create this instance directly. Instead, use {@link getTelemetry | getTelemetry()}.
24+
*
25+
* @public
26+
*/
27+
export interface Telemetry {
28+
/**
29+
* The {@link @firebase/app#FirebaseApp} this {@link Telemetry} instance is associated with.
30+
*/
31+
app: FirebaseApp;
32+
}

packages/telemetry/src/service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { _FirebaseService, FirebaseApp } from '@firebase/app';
19+
import { Telemetry } from './public-types';
20+
21+
export class TelemetryService implements Telemetry, _FirebaseService {
22+
constructor(public app: FirebaseApp) {}
23+
24+
_delete(): Promise<void> {
25+
return Promise.resolve();
26+
}
27+
}

0 commit comments

Comments
 (0)