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

PCE: $on applied to an extended client is also bound to the parent client #19552

Closed
millsp opened this issue Jun 1, 2023 · 1 comment · Fixed by #19697
Closed

PCE: $on applied to an extended client is also bound to the parent client #19552

millsp opened this issue Jun 1, 2023 · 1 comment · Fixed by #19697
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: clientExtensions
Milestone

Comments

@millsp
Copy link
Member

millsp commented Jun 1, 2023

Originally posted by @realSergiy in #16500 (comment)

Hi,
I am using extended client, so that I could capture request id for every api call:

const extended = prismaClient.$extends({});
extended.$on('query', (e) => {
  log.debug('prisma_query', e);      
});

in the above snippet log would have all the request-specific information captured.
This works but it seems event subscriptions still happen on the original client and not the extended one. Therefore piling up subscriptions and logs with every request.

I was hoping to workaround with $use middleware, however it's not exposed on extended clients.

Any help on how to setup custom per request prisma logs (in nodejs server context) would be highly appreciated.

@millsp millsp added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. team/client Issue for team Client. topic: clientExtensions labels Jun 1, 2023
@SevInf
Copy link
Contributor

SevInf commented Jun 7, 2023

From the discussions: we agreed that the way forwaard for GA is to disallow $on on extended client (similar to how we do it for middlewares and $use) thus requiring all event handlers to be added before any extensions.

For future, we'd like to introduce non-destructive extension component that would allow you to subscribe to query events for local fork. Sketch:

const xprisma = prisma.$extends({
   logging: {
       query: () => {}
   }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: clientExtensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants