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 duration to mongo logging #14378

Closed
garrensmith opened this issue Jul 19, 2022 · 3 comments · Fixed by prisma/prisma-engines#3332
Closed

Add duration to mongo logging #14378

garrensmith opened this issue Jul 19, 2022 · 3 comments · Fixed by prisma/prisma-engines#3332
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: logging topic: mongodb
Milestone

Comments

@garrensmith
Copy link
Contributor

Bug description

With this code

 const prisma = newPrismaClient({
        log: [
          {
            emit: 'event',
            level: 'info',
          },
          {
            emit: 'event',
            level: 'query',
          },
        ],
      })
prisma.$on('query', onQuery)
 await prisma.user.findMany()

when using mongo I get following event:

{
      is_query: true,
      item_type: 'query',
      level: 'debug',
      module_path: 'mongodb_query_connector::query',
      params: '[]',
      query: 'db.User.aggregate([ { $project: { _id: 1, }, }, ])'
}

where with sqlite or any other provider I get someting along these lines:

{
      duration_ms: 0,
      is_query: true,
      item_type: 'query',
      level: 'debug',
      module_path: 'quaint::connector::metrics',
      params: '[-1,0]',
      query: 'SELECT `main`.`User`.`id` FROM `main`.`User` WHERE 1=1 LIMIT ? OFFSET ?',
      result: 'success'
}

How to reproduce

Expected behavior

MongoDB logs should include the duration in the log event.

Prisma information

Environment & setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version


@aqrln aqrln added team/client Issue for team Client. bug/2-confirmed Bug has been reproduced and confirmed. labels Jul 19, 2022
@janpio janpio changed the title Add duration to mongo logging. Add duration to mongo logging Aug 30, 2022
miguelff added a commit to prisma/prisma-engines that referenced this issue Oct 28, 2022
* Reproduce lack of duration information prisma/prisma#14378

* Remove dead code: All read queries are based on https://www.mongodb.com/docs/manual/core/aggregation-pipeline/ and simple collection queries are no longer supported by the mongo driver. The codebase had some dead code that I'm removing in this commit. As part of it, I'm also removing the enum MongoReadQuery and leave the PipelineQuery as ReadQuery.

* Move log tracing to observing method, thus consolidating both metrics and query logging. This means that the logger module will cease to make sense. Instead, we will have a query_strings module with functions capable of generating query strings asynchronously.

* Replaced all usages of `metrics(Future)` with `observing(None, Future)`

* Move log_* functions in the `log` module to methods that generate query strings in `query_strings` module. Centralize logging logic in `observing` as a preparatory refactoring to conditionally log depending on the engine log-level

* Add coverage to previously non-covered query-string generation
@Jolg42
Copy link
Member

Jolg42 commented Oct 31, 2022

Should we add a test in prisma/prisma about MongoDB logs? I'm not sure if we have one.

@Jolg42 Jolg42 added this to the 4.6.0 milestone Oct 31, 2022
@miguelff
Copy link
Contributor

Some are being added to prisma in #15957

On the engine side, we have a couple of integration tests covering that logs are indeed being generated and that fields contain both a duration and a query string. Then we have a complete unit test suite for the log traces' query strings. I'm in favor of adding more tests that contribute to the client's robustness, but I will defer to @danstarns on the decision of which and how many of them would constitute good enough coverage.

@danstarns
Copy link
Contributor

Coverage added in this PR & commit: 65cdef6

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/engines Issue for tech Engines. topic: logging topic: mongodb
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants