Skip to content

Commit

Permalink
Merge pull request #17696 from mozilla/fix-firestore-dev-start
Browse files Browse the repository at this point in the history
fix(payments-next): fix duplicate glean logs
  • Loading branch information
StaberindeZA authored Sep 25, 2024
2 parents 6d3edcf + 8173bfe commit 3da291f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 10 additions & 1 deletion libs/payments/metrics/src/lib/glean/glean.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Provider } from '@nestjs/common';
import { createEventsServerEventLogger } from './__generated__/server_events';
import { PaymentsGleanConfig } from './glean.config';

const getRandomValue = () => Math.floor(Math.random() * 10000);

export type PaymentsGleanServerEventsLogger = ReturnType<
typeof createEventsServerEventLogger
>;
Expand All @@ -13,12 +15,19 @@ export const PaymentsGleanProvider = Symbol('GleanServerEventsProvider');
export const PaymentsGleanFactory: Provider<PaymentsGleanServerEventsLogger> = {
provide: PaymentsGleanProvider,
useFactory: (config: PaymentsGleanConfig) => {
// In development, we want to have a unique logger name. Without it, each time the
// nestapp restarts, a new logger handler is added and the events will be logged
// multiple times, once per handler.
const loggerAppName =
process.env['NODE_ENV'] === 'development'
? `${config.loggerAppName}-${getRandomValue()}`
: config.loggerAppName;
return createEventsServerEventLogger({
applicationId: config.applicationId,
appDisplayVersion: config.version,
channel: config.channel,
logger_options: {
app: config.loggerAppName,
app: loggerAppName,
},
});
},
Expand Down
12 changes: 8 additions & 4 deletions libs/shared/db/firestore/src/lib/firestore.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ export const FirestoreService = Symbol('FIRESTORE');
export const FirestoreProvider: Provider<Firestore> = {
provide: FirestoreService,
useFactory: (config: FirestoreConfig) => {
const credentials =
config.credentials?.clientEmail && config.credentials?.privateKey
? {
client_email: config.credentials?.clientEmail,
private_key: config.credentials?.privateKey,
}
: undefined;
const firestoreConfig: FirebaseFirestore.Settings = {
...config,
credentials: {
client_email: config.credentials?.clientEmail,
private_key: config.credentials?.privateKey,
},
credentials,
};
return setupFirestore(firestoreConfig);
},
Expand Down

0 comments on commit 3da291f

Please sign in to comment.