Skip to content

Commit

Permalink
feat(client): Tracing Client Side Serialization (#14670)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre-Antoine Mills <pierreantoine.urvoy@gmail.com>
  • Loading branch information
danstarns and millsp committed Aug 8, 2022
1 parent 6037abf commit d978dbf
Show file tree
Hide file tree
Showing 4 changed files with 1,367 additions and 252 deletions.
31 changes: 20 additions & 11 deletions packages/client/src/runtime/getPrismaClient.ts
Expand Up @@ -38,7 +38,7 @@ import { getLogLevel } from './getLogLevel'
import { mergeBy } from './mergeBy'
import type { EngineMiddleware, Namespace, QueryMiddleware, QueryMiddlewareParams } from './MiddlewareHandler'
import { Middlewares } from './MiddlewareHandler'
import { makeDocument, transformDocument } from './query'
import { Document, makeDocument, transformDocument } from './query'
import { RequestHandler } from './RequestHandler'
import { clientVersion } from './utils/clientVersion'
import { getOutputTypeName } from './utils/common'
Expand Down Expand Up @@ -1153,24 +1153,33 @@ new PrismaClient({

const { isList } = field.outputType
const typeName = getOutputTypeName(field.outputType.type)

const rejectOnNotFound: RejectOnNotFound = getRejectOnNotFound(action, typeName, args, this._rejectOnNotFound)
warnAboutRejectOnNotFound(rejectOnNotFound, jsModelName, action)
let document = makeDocument({
dmmf: this._dmmf,
rootField: rootField!,
rootTypeName: operation,
select: args,
})

document.validate(args, false, clientMethod, this._errorFormat, callsite)
const serializationFn = () => {
const document = makeDocument({
dmmf: this._dmmf!,
rootField: rootField!,
rootTypeName: operation,
select: args,
})

document.validate(args, false, clientMethod, this._errorFormat, callsite)

return transformDocument(document)
}

const spanOptions: SpanOptions = {
name: 'serialize',
enabled: this._tracingConfig.enabled,
}

document = transformDocument(document)
const document = await runInChildSpan(spanOptions, serializationFn)

// as printJsonWithErrors takes a bit of compute
// we only want to do it, if debug is enabled for 'prisma-client'
if (Debug.enabled('prisma:client')) {
const query = String(document)
const query = String(document!)
debug(`Prisma Client call:`)
debug(
`prisma.${clientMethod}(${printJsonWithErrors({
Expand Down

0 comments on commit d978dbf

Please sign in to comment.