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

Some issue when record tracing log on guard #66

Open
angle319 opened this issue May 9, 2023 · 2 comments
Open

Some issue when record tracing log on guard #66

angle319 opened this issue May 9, 2023 · 2 comments

Comments

@angle319
Copy link

angle319 commented May 9, 2023

Hey owner,
I found some problem. It's happend when same guard been use on different controller.
my zipkin will receive so many guard event, like following.
image
image
The root cause is rewrite "canActivate" which been used on guard instance.
image
It will loop rewriting until load all controller.

@angle319
Copy link
Author

angle319 commented May 9, 2023

My solution is using other flag to condition only execution once time.

const guards = this.getGuards(controller.metatype.prototype[key]).map(
            (guard) => {
              const prototype = guard['prototype'] ?? guard;
              const traceName = `Guard->${controller.name}.${controller.metatype.prototype[key].name}.${prototype.constructor.name}`;
              const isDerGuard = /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(prototype.constructor.name)
              const guardName = (isDerGuard) ? `Sub-Guard(Auto generate)`: prototype.constructor.name
              // same guard will loop overwrite canActivate method
              if (!prototype['singleton']) {
                prototype.canActivate = this.wrap(
                  prototype.canActivate,
                  guardName,
                  {
                    controller: controller.name,
                    guard: prototype.constructor.name,
                    method: controller.metatype.prototype[key].name,
                    scope: 'CONTROLLER_METHOD',
                  },
                );
                prototype['singleton']=true
              }
              Object.assign(prototype, this);
              this.loggerService.log(
                `Mapped ${traceName}`,
                this.constructor.name,
              );
              return guard;
            },
          );

provide for you, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants