Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logging to Api, Mail, Webhook, and Websocket #2755

Merged
merged 55 commits into from
Mar 17, 2023

Conversation

Cliftonz
Copy link
Contributor

What change does this PR introduce?

This PR introduces standardized logging for the application. The creation of the loggers can be found in packages -> application-generic where a logger can be instantiated with either createLogger for non-nest apps and create NestLogger for nest based apps.

Why was this change needed?

This change will allow us to start creating quality logs for better remediation of issues on premise and in novu cloud.

Notes

This PR also introduces the env variable LOGGING_LEVEL to all backends and we will need to ensure that new relic licenses, app name, and logging level to all deployments.

This deployment is also blocked by the eu pr as it contains updates to the workflow.

We will also want to look at being able to dynamically update the logging level while the system is running so we can collect debug or verbose logs while the system is running without redeploying it.

Copy link
Contributor

@djabarovgeorge djabarovgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like awesome work, left a couple of questions in order to understand better.

apps/api/package.json Outdated Show resolved Hide resolved
apps/api/src/app/auth/auth.controller.ts Show resolved Hide resolved
apps/api/src/app/auth/auth.controller.ts Outdated Show resolved Hide resolved
apps/api/src/app/auth/auth.controller.ts Outdated Show resolved Hide resolved
apps/api/src/newrelic.ts Outdated Show resolved Hide resolved
apps/api/src/newrelic.ts Outdated Show resolved Hide resolved
@@ -88,7 +83,6 @@ export function createNestLoggingModuleOptions(settings: ILoggerSettings) {
return {
pinoHttp: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cliftonz probably lost in my previous comments, but why are we implementing masking from scratch and not using the built in redact for pino? https://github.com/pinojs/pino/blob/master/docs/redaction.md

Copy link
Contributor Author

@Cliftonz Cliftonz Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to implement this but the wildcard pathing was not working. @scopsy If you can take a look at this I think that would be best.
In this pr, I have kept my original implementation and made sure that the request logging processing is only done if log level is set to debug and uses promises to ensure some level of multi-processing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this removed by mistake? @Cliftonz

await this.workflowQueueService.addToQueue(job._id, job, delay);

if (delay) {
this.createExecutionDetails.execute(
Logger.verbose('Delay is active, Creating execution details');
await this.createExecutionDetails.execute(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cliftonz those are not awaited by design here to avoid blocking the response to the user


@Controller({
path: 'events',
scope: Scope.REQUEST,
})
@ApiTags('Events')
@LogDecorator()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cliftonz not sure if you have answered this previously but couldn't find it, if nest-pino already have an auto logger for HTTP requests, why do we need the LogDecorator?

})
);
return await new Promise(async (resolve, reject) => {
storage.run(new Store(PinoLogger.root), () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cliftonz this what was missing and caused the unit tests to fail ^

Comment on lines 144 to 146
createNestLoggingModuleOptions({
serviceName: 'novu/api',
version: '0.12.0',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cliftonz why are we initializing it here twice? Once in the app module and the shared module? Should be only once, and if it's here let's make sure not to hard code those values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the log decorator is breaking a lot of existing modules, as it converts all non promise methods to be promise methods. For example the toArray method provided by in widgets.controller.ts file.

Mine suggestion is, Don't do a global decorator to decorate ALL methods in a class, but have a more targeted decorator that will decorate individual methods to unwanted side effects.

@scopsy scopsy enabled auto-merge March 17, 2023 13:15
@scopsy scopsy disabled auto-merge March 17, 2023 13:18
@scopsy scopsy merged commit e26d998 into next Mar 17, 2023
@scopsy scopsy deleted the winston-logger-implementation branch March 17, 2023 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants