Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions packages/telemetry/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
* just use index.ts
*/

import { testFxn } from './src';
import { registerTelemetry } from './src/index';

console.log('Hi Node.js Users!');
testFxn();
registerTelemetry();

export * from './src/api';
export * from './src/public-types';
7 changes: 5 additions & 2 deletions packages/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

import { testFxn } from './src';
import { registerTelemetry } from './src';

testFxn();
registerTelemetry();

export * from './src/api';
export * from './src/public-types';
5 changes: 4 additions & 1 deletion packages/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@
"@firebase/app-types": "0.x"
},
"dependencies": {
"tslib": "^2.1.0"
"tslib": "^2.1.0",
"@firebase/component": "0.7.0"
},
"license": "Apache-2.0",
"devDependencies": {
"@firebase/app": "0.14.1",
"@rollup/plugin-json": "6.1.0",
"rollup": "2.79.2",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.36.0",
"typescript": "5.5.4"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/telemetry/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import json from '@rollup/plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import pkg from './package.json';
Expand All @@ -24,7 +25,7 @@ const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

const buildPlugins = [typescriptPlugin({ typescript })];
const buildPlugins = [typescriptPlugin({ typescript }), json()];

const browserBuilds = [
{
Expand Down
46 changes: 46 additions & 0 deletions packages/telemetry/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { _getProvider, FirebaseApp, getApp } from '@firebase/app';
import { TELEMETRY_TYPE } from './constants';
import { Telemetry } from './public-types';
import { Provider } from '@firebase/component';

/**
* Returns the default {@link Telemetry} instance that is associated with the provided
* {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new instance with the
* default settings.
*
* @example
* ```javascript
* const telemetry = getTelemetry(app);
* ```
*
* @param app - The {@link @firebase/app#FirebaseApp} to use.
* @returns The default {@link Telemetry} instance for the given {@link @firebase/app#FirebaseApp}.
*
* @public
*/
export function getTelemetry(app: FirebaseApp = getApp()): Telemetry {
// Dependencies
const telemetryProvider: Provider<'telemetry'> = _getProvider(
app,
TELEMETRY_TYPE
);

return telemetryProvider.getImmediate();
}
19 changes: 19 additions & 0 deletions packages/telemetry/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** Type constant for Firebase Telemetry. */
export const TELEMETRY_TYPE = 'telemetry';
53 changes: 53 additions & 0 deletions packages/telemetry/src/index.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { _registerComponent, registerVersion } from '@firebase/app';
import { TestType } from './types/index';
import { Component, ComponentType } from '@firebase/component';
import { TELEMETRY_TYPE } from './constants';
import { name, version } from '../package.json';
import { TelemetryService } from './service';

export function testFxn(): number {
const _thing: TestType = {};
console.log('hi');
return 42;
}

declare module '@firebase/component' {
interface NameServiceMapping {
[TELEMETRY_TYPE]: TelemetryService;
}
}

export function registerTelemetry(): void {
_registerComponent(
new Component(
TELEMETRY_TYPE,
container => {
// getImmediate for FirebaseApp will always succeed
const app = container.getProvider('app').getImmediate();
return new TelemetryService(app);
},
ComponentType.PUBLIC
)
);

registerVersion(name, version, 'node');
// BUILD_TARGET will be replaced by values like esm, cjs, etc during the compilation
registerVersion(name, version, '__BUILD_TARGET__');
}
29 changes: 29 additions & 0 deletions packages/telemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,39 @@
* limitations under the License.
*/

import { _registerComponent, registerVersion } from '@firebase/app';
import { TestType } from './types/index';
import { Component, ComponentType } from '@firebase/component';
import { TELEMETRY_TYPE } from './constants';
import { name, version } from '../package.json';
import { TelemetryService } from './service';

export function testFxn(): number {
const _thing: TestType = {};
console.log('hi');
return 42;
}

declare module '@firebase/component' {
interface NameServiceMapping {
[TELEMETRY_TYPE]: TelemetryService;
}
}

export function registerTelemetry(): void {
_registerComponent(
new Component(
TELEMETRY_TYPE,
(container, {}) => {
// getImmediate for FirebaseApp will always succeed
const app = container.getProvider('app').getImmediate();
return new TelemetryService(app);
},
ComponentType.PUBLIC
)
);

registerVersion(name, version);
// BUILD_TARGET will be replaced by values like esm, cjs, etc during the compilation
registerVersion(name, version, '__BUILD_TARGET__');
}
32 changes: 32 additions & 0 deletions packages/telemetry/src/public-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { FirebaseApp } from '@firebase/app';

/**
* An instance of the Firebase Telemetry SDK.
*
* Do not create this instance directly. Instead, use {@link getTelemetry | getTelemetry()}.
*
* @public
*/
export interface Telemetry {
/**
* The {@link @firebase/app#FirebaseApp} this {@link Telemetry} instance is associated with.
*/
app: FirebaseApp;
}
27 changes: 27 additions & 0 deletions packages/telemetry/src/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { _FirebaseService, FirebaseApp } from '@firebase/app';
import { Telemetry } from './public-types';

export class TelemetryService implements Telemetry, _FirebaseService {
constructor(public app: FirebaseApp) {}

_delete(): Promise<void> {
return Promise.resolve();
}
}
Loading