Skip to content

Commit 6561882

Browse files
authored
Add logging headers (#293)
1 parent 1de2383 commit 6561882

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

packages/app/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { name as remoteConfigCompatName } from '../../../packages/remote-config-
3838
import { name as storageName } from '../../../packages/storage/package.json';
3939
import { name as storageCompatName } from '../../../packages/storage-compat/package.json';
4040
import { name as firestoreName } from '../../../packages/firestore/package.json';
41+
import { name as vertexName } from '../../../packages/vertexai/package.json';
4142
import { name as firestoreCompatName } from '../../../packages/firestore-compat/package.json';
4243
import { name as packageName } from '../../../packages/firebase/package.json';
4344

@@ -73,6 +74,7 @@ export const PLATFORM_LOG_STRING = {
7374
[storageCompatName]: 'fire-gcs-compat',
7475
[firestoreName]: 'fire-fst',
7576
[firestoreCompatName]: 'fire-fst-compat',
77+
[vertexName]: 'fire-vertex',
7678
'fire-js': 'fire-js', // Platform identifier for JS SDK.
7779
[packageName]: 'fire-js-all'
7880
} as const;

packages/vertexai/src/constants.ts

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

18+
import { version } from '../package.json';
19+
1820
export const VERTEX_TYPE = 'vertex';
1921

2022
export const DEFAULT_LOCATION = 'us-central1';
23+
24+
export const DEFAULT_BASE_URL = 'https://firebaseml.googleapis.com';
25+
26+
export const DEFAULT_API_VERSION = 'v2beta';
27+
28+
export const PACKAGE_VERSION = version;
29+
30+
export const LANGUAGE_TAG = 'gl-js';

packages/vertexai/src/requests/request.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import { expect, use } from 'chai';
1919
import { restore, stub } from 'sinon';
2020
import sinonChai from 'sinon-chai';
2121
import chaiAsPromised from 'chai-as-promised';
22-
import { DEFAULT_API_VERSION, RequestUrl, Task, makeRequest } from './request';
22+
import { RequestUrl, Task, makeRequest } from './request';
2323
import { ApiSettings } from '../types/internal';
24+
import { DEFAULT_API_VERSION } from '../constants';
2425

2526
use(sinonChai);
2627
use(chaiAsPromised);

packages/vertexai/src/requests/request.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
import { RequestOptions } from '../types';
1919
import { ERROR_FACTORY, VertexError } from '../errors';
2020
import { ApiSettings } from '../types/internal';
21-
import { version } from '../../package.json';
22-
23-
const DEFAULT_BASE_URL = 'https://firebaseml.googleapis.com';
24-
25-
export const DEFAULT_API_VERSION = 'v2beta';
26-
27-
const PACKAGE_VERSION = version;
28-
const PACKAGE_LOG_HEADER = 'firebase-vertexai-js';
21+
import {
22+
DEFAULT_API_VERSION,
23+
DEFAULT_BASE_URL,
24+
LANGUAGE_TAG,
25+
PACKAGE_VERSION
26+
} from '../constants';
2927

3028
export enum Task {
3129
GENERATE_CONTENT = 'generateContent',
@@ -68,10 +66,13 @@ export class RequestUrl {
6866
}
6967

7068
/**
71-
* Simple, but may become more complex if we add more versions to log.
69+
* Log language and "fire/version" to x-goog-api-client
7270
*/
7371
function getClientHeaders(): string {
74-
return `${PACKAGE_LOG_HEADER}/${PACKAGE_VERSION}`;
72+
const loggingTags = [];
73+
loggingTags.push(`${LANGUAGE_TAG}/`);
74+
loggingTags.push(`fire/${PACKAGE_VERSION}`);
75+
return loggingTags.join(' ');
7576
}
7677

7778
export async function makeRequest(

0 commit comments

Comments
 (0)