Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Daniel Starns <danielstarns@hotmail.com>
- Loading branch information
Showing
9 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
packages/client/tests/functional/tracing-no-sampling/_matrix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
import { allProviders } from '../_utils/providers' | ||
export default defineMatrix(() => [ | ||
allProviders, | ||
[ | ||
{ | ||
previewFeatures: '"tracing", "interactiveTransactions"', | ||
}, | ||
{ | ||
previewFeatures: '"interactiveTransactions"', | ||
}, | ||
], | ||
]) |
20 changes: 20 additions & 0 deletions
20
packages/client/tests/functional/tracing-no-sampling/prisma/_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { idForProvider } from '../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider, previewFeatures }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = [${previewFeatures}] | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model User { | ||
id ${idForProvider(provider)} | ||
} | ||
` | ||
}) |
94 changes: 94 additions & 0 deletions
94
packages/client/tests/functional/tracing-no-sampling/tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { context } from '@opentelemetry/api' | ||
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks' | ||
import { registerInstrumentations } from '@opentelemetry/instrumentation' | ||
import { Resource } from '@opentelemetry/resources' | ||
import { | ||
BasicTracerProvider, | ||
InMemorySpanExporter, | ||
SimpleSpanProcessor, | ||
TraceIdRatioBasedSampler, | ||
} from '@opentelemetry/sdk-trace-base' | ||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' | ||
import { PrismaInstrumentation } from '@prisma/instrumentation' | ||
|
||
import { NewPrismaClient } from '../_utils/types' | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
let prisma: PrismaClient<{ log: [{ emit: 'event'; level: 'query' }] }> | ||
declare let newPrismaClient: NewPrismaClient<typeof PrismaClient> | ||
|
||
let inMemorySpanExporter: InMemorySpanExporter | ||
|
||
beforeAll(() => { | ||
const contextManager = new AsyncHooksContextManager().enable() | ||
context.setGlobalContextManager(contextManager) | ||
|
||
inMemorySpanExporter = new InMemorySpanExporter() | ||
|
||
const basicTracerProvider = new BasicTracerProvider({ | ||
sampler: new TraceIdRatioBasedSampler(0), // 0% sampling!! | ||
resource: new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: `test-name`, | ||
[SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0', | ||
}), | ||
}) | ||
|
||
basicTracerProvider.addSpanProcessor(new SimpleSpanProcessor(inMemorySpanExporter)) | ||
basicTracerProvider.register() | ||
|
||
registerInstrumentations({ | ||
instrumentations: [new PrismaInstrumentation({ middleware: true })], | ||
}) | ||
}) | ||
|
||
afterAll(() => { | ||
context.disable() | ||
}) | ||
|
||
testMatrix.setupTestSuite( | ||
() => { | ||
const queries: string[] = [] | ||
|
||
function checkQueriesHaveNotTraceparent() { | ||
const result = !queries.some((q) => q.includes('traceparent')) | ||
|
||
queries.length = 0 | ||
|
||
return result | ||
} | ||
|
||
beforeAll(() => { | ||
prisma = newPrismaClient({ log: [{ emit: 'event', level: 'query' }] }) | ||
|
||
prisma.$on('query', (e) => queries.push(e.query)) | ||
}) | ||
|
||
test('should perform a query and assert that no spans were generated', async () => { | ||
await prisma.user.findMany() | ||
|
||
const spans = inMemorySpanExporter.getFinishedSpans() | ||
|
||
expect(spans).toHaveLength(0) | ||
expect(checkQueriesHaveNotTraceparent()).toBe(true) | ||
}) | ||
|
||
testIf(!process.env.DATA_PROXY)( | ||
'should perform a query and assert that no spans were generated via itx', | ||
async () => { | ||
await prisma.$transaction(async (prisma) => { | ||
await prisma.user.findMany() | ||
}) | ||
|
||
const spans = inMemorySpanExporter.getFinishedSpans() | ||
|
||
expect(spans).toHaveLength(0) | ||
expect(checkQueriesHaveNotTraceparent()).toBe(true) | ||
}, | ||
) | ||
}, | ||
{ | ||
skipDefaultClientInstance: true, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters