Skip to content

Commit

Permalink
chore(client): remove engine connect/disconnect span (#14705)
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Aug 8, 2022
1 parent d978dbf commit f6d1a65
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 113 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Expand Up @@ -140,7 +140,7 @@
}
},
"dependencies": {
"@prisma/engines-version": "4.2.0-31.659227f6781053b4a24d241ede6c3dd2d88d254f"
"@prisma/engines-version": "4.2.0-33.2920a97877e12e055c1333079b8d19cee7f33826"
},
"sideEffects": false
}
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`tracing (provider=cockroachdb) Tracing connect should trace the implict $connect call 1`] = `
exports[`tracing (provider=cockroachdb) tracing connect should trace the implicit $connect call 1`] = `
Object {
children: Array [
Object {
Expand All @@ -14,18 +14,7 @@ Object {
},
},
Object {
children: Array [
Object {
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
links: Array [],
name: prisma:engine:connect,
parentSpanId: <parentSpanId>,
},
},
],
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
Expand Down Expand Up @@ -1354,7 +1343,7 @@ Object {
}
`;

exports[`tracing (provider=mongodb) Tracing connect should trace the implict $connect call 1`] = `
exports[`tracing (provider=mongodb) tracing connect should trace the implicit $connect call 1`] = `
Object {
children: Array [
Object {
Expand All @@ -1368,18 +1357,7 @@ Object {
},
},
Object {
children: Array [
Object {
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
links: Array [],
name: prisma:engine:connect,
parentSpanId: <parentSpanId>,
},
},
],
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
Expand Down Expand Up @@ -2398,7 +2376,7 @@ Object {
}
`;

exports[`tracing (provider=mysql) Tracing connect should trace the implict $connect call 1`] = `
exports[`tracing (provider=mysql) tracing connect should trace the implicit $connect call 1`] = `
Object {
children: Array [
Object {
Expand All @@ -2412,18 +2390,7 @@ Object {
},
},
Object {
children: Array [
Object {
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
links: Array [],
name: prisma:engine:connect,
parentSpanId: <parentSpanId>,
},
},
],
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
Expand Down Expand Up @@ -3752,7 +3719,7 @@ Object {
}
`;

exports[`tracing (provider=postgresql) Tracing connect should trace the implict $connect call 1`] = `
exports[`tracing (provider=postgresql) tracing connect should trace the implicit $connect call 1`] = `
Object {
children: Array [
Object {
Expand All @@ -3766,18 +3733,7 @@ Object {
},
},
Object {
children: Array [
Object {
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
links: Array [],
name: prisma:engine:connect,
parentSpanId: <parentSpanId>,
},
},
],
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
Expand Down Expand Up @@ -5106,7 +5062,7 @@ Object {
}
`;

exports[`tracing (provider=sqlite) Tracing connect should trace the implict $connect call 1`] = `
exports[`tracing (provider=sqlite) tracing connect should trace the implicit $connect call 1`] = `
Object {
children: Array [
Object {
Expand All @@ -5120,18 +5076,7 @@ Object {
},
},
Object {
children: Array [
Object {
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
links: Array [],
name: prisma:engine:connect,
parentSpanId: <parentSpanId>,
},
},
],
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
Expand Down Expand Up @@ -6389,7 +6334,7 @@ Object {
}
`;

exports[`tracing (provider=sqlserver) Tracing connect should trace the implict $connect call 1`] = `
exports[`tracing (provider=sqlserver) tracing connect should trace the implicit $connect call 1`] = `
Object {
children: Array [
Object {
Expand All @@ -6403,18 +6348,7 @@ Object {
},
},
Object {
children: Array [
Object {
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
links: Array [],
name: prisma:engine:connect,
parentSpanId: <parentSpanId>,
},
},
],
children: Array [],
span: Object {
attributes: Object {},
kind: 0,
Expand Down
21 changes: 4 additions & 17 deletions packages/client/tests/functional/tracing/tests.ts
Expand Up @@ -747,7 +747,7 @@ testMatrix.setupTestSuite(({ provider }) => {
})
})

describe('Tracing connect', () => {
describe('tracing connect', () => {
// @ts-ignore
let _prisma: PrismaClient

Expand All @@ -759,7 +759,7 @@ testMatrix.setupTestSuite(({ provider }) => {
await _prisma.$disconnect()
})

test('should trace the implict $connect call', async () => {
test('should trace the implicit $connect call', async () => {
const email = faker.internet.email()

await _prisma.user.findMany({
Expand All @@ -784,10 +784,7 @@ testMatrix.setupTestSuite(({ provider }) => {
const connect = (tree?.children || [])[1] as unknown as Tree
expect(connect.span.name).toEqual('prisma:client:connect')

expect(connect.children).toHaveLength(1)

const engineConnect = (connect?.children || [])[0] as unknown as Tree
expect(engineConnect.span.name).toEqual('prisma:engine:connect')
expect(connect.children).toHaveLength(0)

const engine = (tree?.children || [])[2] as unknown as Tree
expect(engine.span.name).toEqual('prisma:engine')
Expand Down Expand Up @@ -819,7 +816,7 @@ testMatrix.setupTestSuite(({ provider }) => {
})
})

describe('Tracing disconnect', () => {
describe('tracing disconnect', () => {
// @ts-ignore
let _prisma: PrismaClient

Expand All @@ -834,16 +831,6 @@ testMatrix.setupTestSuite(({ provider }) => {
const tree = await waitForSpanTree()

expect(tree.span.name).toEqual('prisma:client:disconnect')

// No binary disconnect because we simply kill the process
if (getClientEngineType() === ClientEngineType.Binary) {
return
}

expect(tree.children).toHaveLength(1)

const engineDisconnect = (tree.children || [])[0]
expect(engineDisconnect.span.name).toEqual('prisma:engine:disconnect')
})
})
})
3 changes: 2 additions & 1 deletion packages/engine-core/src/binary/BinaryEngine.ts
Expand Up @@ -578,7 +578,8 @@ ${chalk.dim("In case we're mistaken, please report this to us 🙏.")}`)
tracingHeaders.traceparent = getTraceParent()
}

flags.push('--tracing-headers', JSON.stringify(tracingHeaders))
// TODO: not used yet by the engine
// flags.push('--tracing-headers', JSON.stringify(tracingHeaders))

debug({ flags })

Expand Down
1 change: 1 addition & 0 deletions packages/engine-core/src/library/LibraryEngine.ts
Expand Up @@ -335,6 +335,7 @@ You may have to run ${chalk.greenBright('prisma generate')} for your changes to
traceparent: getTraceParent(),
}

// TODO: not used yet by the engine
await this.engine?.connect(JSON.stringify(headers))

this.libraryStarted = true
Expand Down
9 changes: 6 additions & 3 deletions packages/engine-core/src/tracing/createSpan.ts
@@ -1,4 +1,4 @@
import { ROOT_CONTEXT, SpanContext, SpanKind, trace, TraceFlags } from '@opentelemetry/api'
import { context, ROOT_CONTEXT, SpanContext, SpanKind, trace, TraceFlags } from '@opentelemetry/api'
import { Span, Tracer } from '@opentelemetry/sdk-trace-base'

import { EngineSpanEvent } from '../common/types/QueryEngine'
Expand All @@ -10,19 +10,22 @@ export async function createSpan(engineSpanEvent: EngineSpanEvent) {

const tracer = trace.getTracer('prisma') as Tracer

// TODO: workaround for the engines always sending spans even when not traced
const traceFlags = trace.getSpan(context.active())?.spanContext().traceFlags

engineSpanEvent.spans.forEach((engineSpan) => {
const spanContext: SpanContext = {
traceId: engineSpan.trace_id,
spanId: engineSpan.span_id,
traceFlags: TraceFlags.SAMPLED,
traceFlags: traceFlags ?? TraceFlags.SAMPLED,
}

const links = engineSpan.links?.map((link) => {
return {
context: {
traceId: link.trace_id,
spanId: link.span_id,
traceFlags: TraceFlags.SAMPLED,
traceFlags: traceFlags ?? TraceFlags.SAMPLED,
},
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/engines/package.json
Expand Up @@ -7,7 +7,7 @@
"author": "Tim Suchanek <suchanek@prisma.io>",
"devDependencies": {
"@prisma/debug": "workspace:*",
"@prisma/engines-version": "4.2.0-31.659227f6781053b4a24d241ede6c3dd2d88d254f",
"@prisma/engines-version": "4.2.0-33.2920a97877e12e055c1333079b8d19cee7f33826",
"@prisma/fetch-engine": "workspace:*",
"@prisma/get-platform": "workspace:*",
"@swc/core": "1.2.197",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetch-engine/package.json
Expand Up @@ -13,7 +13,7 @@
},
"bugs": "https://github.com/prisma/prisma/issues",
"devDependencies": {
"@prisma/engines-version": "4.2.0-31.659227f6781053b4a24d241ede6c3dd2d88d254f",
"@prisma/engines-version": "4.2.0-33.2920a97877e12e055c1333079b8d19cee7f33826",
"@swc/core": "1.2.197",
"@swc/jest": "0.2.22",
"@types/jest": "28.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/package.json
Expand Up @@ -16,7 +16,7 @@
"version": "latest"
},
"devDependencies": {
"@prisma/engines-version": "4.2.0-31.659227f6781053b4a24d241ede6c3dd2d88d254f",
"@prisma/engines-version": "4.2.0-33.2920a97877e12e055c1333079b8d19cee7f33826",
"@prisma/generator-helper": "workspace:*",
"@prisma/internals": "workspace:*",
"@swc/core": "1.2.204",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6d1a65

Please sign in to comment.