Use our logger in Yoga (#770)

This commit is contained in:
Kamil Kisiela 2022-12-08 17:36:50 +01:00 committed by GitHub
parent 5d34dffb1a
commit 4e3a8d42dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View file

@ -37,6 +37,7 @@ export class BillingProvider {
}
upgradeToPro(input: StripeBillingApiInput['createSubscriptionForOrganization']) {
this.logger.debug('Upgrading to PRO (input=%o)', input);
if (!this.billingService) {
throw new Error(`Billing service is not configured!`);
}
@ -53,6 +54,7 @@ export class BillingProvider {
}
async getAvailablePrices() {
this.logger.debug('Getting available prices');
if (!this.billingService) {
return null;
}
@ -71,6 +73,7 @@ export class BillingProvider {
}
getActiveSubscription(input: StripeBillingApiInput['activeSubscription']) {
this.logger.debug('Fetching active subscription (input=%o)', input);
if (!this.billingService) {
throw new Error(`Billing service is not configured!`);
}
@ -79,6 +82,7 @@ export class BillingProvider {
}
invoices(input: StripeBillingApiInput['invoices']) {
this.logger.debug('Fetching invoices (input=%o)', input);
if (!this.billingService) {
throw new Error(`Billing service is not configured!`);
}
@ -87,6 +91,7 @@ export class BillingProvider {
}
upcomingInvoice(input: StripeBillingApiInput['upcomingInvoice']) {
this.logger.debug('Fetching upcoming invoices (input=%o)', input);
if (!this.billingService) {
throw new Error(`Billing service is not configured!`);
}
@ -95,6 +100,7 @@ export class BillingProvider {
}
async downgradeToHobby(input: StripeBillingApiInput['cancelSubscriptionForOrganization']) {
this.logger.debug('Downgrading to Hobby (input=%o)', input);
if (!this.billingService) {
throw new Error(`Billing service is not configured!`);
}

View file

@ -1,10 +1,12 @@
import { RateLimitProvider } from './providers/rate-limit.provider';
import { Logger } from './../shared/providers/logger';
import { RateLimitModule } from './__generated__/types';
export const resolvers: RateLimitModule.Resolvers = {
Organization: {
rateLimit: async (org, args, { injector }) => {
rateLimit: async (org, _args, { injector }) => {
let limitedForOperations = false;
const logger = injector.get(Logger);
try {
const operationsRateLimit = await injector.get(RateLimitProvider).checkRateLimit({
@ -13,10 +15,10 @@ export const resolvers: RateLimitModule.Resolvers = {
type: 'operations-reporting',
});
console.info('Fetched rate-limit info:', { orgId: org.id, operationsRateLimit });
logger.debug('Fetched rate-limit info:', { orgId: org.id, operationsRateLimit });
limitedForOperations = operationsRateLimit.limited;
} catch (e) {
console.warn('Failed to fetch rate-limit info:', org.id, e);
logger.error('Failed to fetch rate-limit info:', org.id, e);
}
return {

View file

@ -1,4 +1,9 @@
import type { RouteHandlerMethod, FastifyRequest, FastifyReply } from 'fastify';
import type {
RouteHandlerMethod,
FastifyRequest,
FastifyReply,
FastifyLoggerInstance,
} from 'fastify';
import { Registry } from '@hive/api';
import { cleanRequestId } from '@hive/service-common';
import { createYoga, useErrorHandler, Plugin } from 'graphql-yoga';
@ -46,6 +51,7 @@ export interface GraphQLHandlerOptions {
isProduction: boolean;
hiveConfig: HiveConfig;
release: string;
logger: FastifyLoggerInstance;
}
export type SuperTokenSessionPayload = zod.TypeOf<typeof SuperTokenAccessTokenModel>;
@ -89,6 +95,7 @@ function useNoIntrospection(params: {
export const graphqlHandler = (options: GraphQLHandlerOptions): RouteHandlerMethod => {
const server = createYoga<Context>({
logging: options.logger,
plugins: [
useSentry({
startTransaction: false,

View file

@ -241,6 +241,7 @@ export async function main() {
isProduction: env.environment === 'prod',
release: env.release,
hiveConfig: env.hive,
logger: graphqlLogger as any,
});
server.route({