-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(node): Streamline generic-pool #21363
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3fa893
ref(node): Streamline generic-pool
nicohrubec 8384e78
test(node): Add generic-pool unit tests for parent span and disabled …
nicohrubec 45b6ae8
ref(node): Tidy generic-pool vendored types
nicohrubec 4934d05
test(node): Add ported-test header and faithful names for generic-poo…
nicohrubec eff3478
remove comment
nicohrubec 9ab9813
ref(node): Drop dead generic-pool span-name typo handling
nicohrubec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/genericPool-v2/instrument.mjs
This file contains hidden or 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,9 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| }); |
42 changes: 42 additions & 0 deletions
42
dev-packages/node-integration-tests/suites/tracing/genericPool-v2/scenario.mjs
This file contains hidden or 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,42 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import genericPool from 'generic-pool'; | ||
|
|
||
| // generic-pool v2 uses the callback-based API: `new Pool(factory)` with `factory.create(callback)` | ||
| // and `pool.acquire((err, client) => ...)`. | ||
| const Pool = genericPool.Pool; | ||
|
|
||
| const pool = new Pool({ | ||
| name: 'test', | ||
| create: callback => callback(null, { id: Math.random() }), | ||
| destroy: () => {}, | ||
| max: 10, | ||
| min: 2, | ||
| }); | ||
|
|
||
| function acquire() { | ||
| return new Promise((resolve, reject) => { | ||
| pool.acquire((err, client) => { | ||
| if (err) { | ||
| reject(err); | ||
| return; | ||
| } | ||
| pool.release(client); | ||
| resolve(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function run() { | ||
| await Sentry.startSpan( | ||
| { | ||
| op: 'transaction', | ||
| name: 'Test Transaction', | ||
| }, | ||
| async () => { | ||
| await acquire(); | ||
| await acquire(); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| run(); |
43 changes: 43 additions & 0 deletions
43
dev-packages/node-integration-tests/suites/tracing/genericPool-v2/test.ts
This file contains hidden or 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,43 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| describe('genericPool v2 auto instrumentation', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests( | ||
| __dirname, | ||
| 'scenario.mjs', | ||
| 'instrument.mjs', | ||
| (createRunner, test) => { | ||
| test('should auto-instrument `generic-pool` v2 when calling pool.acquire()', async () => { | ||
| const EXPECTED_TRANSACTION = { | ||
| transaction: 'Test Transaction', | ||
| spans: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| description: 'generic-pool.acquire', | ||
| origin: 'auto.db.otel.generic_pool', | ||
| data: { | ||
| 'sentry.origin': 'auto.db.otel.generic_pool', | ||
| }, | ||
| status: 'ok', | ||
| }), | ||
|
|
||
| expect.objectContaining({ | ||
| description: 'generic-pool.acquire', | ||
| origin: 'auto.db.otel.generic_pool', | ||
| data: { | ||
| 'sentry.origin': 'auto.db.otel.generic_pool', | ||
| }, | ||
| status: 'ok', | ||
| }), | ||
| ]), | ||
| }; | ||
|
|
||
| await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed(); | ||
| }); | ||
| }, | ||
| { additionalDependencies: { 'generic-pool': '^2.5.0' } }, | ||
| ); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
packages/node/test/integrations/tracing/genericPool.test.ts
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Tests ported from @opentelemetry/instrumentation-generic-pool@0.61.0 | ||
| * Original source: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-generic-pool | ||
| * Licensed under the Apache License, Version 2.0 | ||
| */ | ||
|
|
||
| import { context, trace } from '@opentelemetry/api'; | ||
| import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
| import { GenericPoolInstrumentation } from '../../../src/integrations/tracing/genericPool/vendored/instrumentation'; | ||
| import { cleanupOtel, mockSdkInit } from '../../helpers/mockSdkInit'; | ||
|
|
||
| // Create a fake `generic-pool` module. | ||
| function createPoolModule(): { Pool: new () => { acquire: () => Promise<string> } } { | ||
| class FakePool { | ||
| public acquire(): Promise<string> { | ||
| return Promise.resolve('client'); | ||
| } | ||
| } | ||
| return { Pool: FakePool }; | ||
| } | ||
|
|
||
| describe('GenericPoolInstrumentation', () => { | ||
| const memoryExporter = new InMemorySpanExporter(); | ||
| const provider = new BasicTracerProvider({ spanProcessors: [new SimpleSpanProcessor(memoryExporter)] }); | ||
|
|
||
| let instrumentation: GenericPoolInstrumentation; | ||
|
|
||
| beforeEach(() => { | ||
| mockSdkInit({ tracesSampleRate: 1 }); | ||
| instrumentation = new GenericPoolInstrumentation(); | ||
| instrumentation.setTracerProvider(provider); | ||
| memoryExporter.reset(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| instrumentation.disable(); | ||
| cleanupOtel(); | ||
| }); | ||
|
|
||
| it('should attach it to the parent span', async () => { | ||
| const moduleExports = createPoolModule(); | ||
| const def = instrumentation.getModuleDefinitions()[0]!; | ||
| def.patch!(moduleExports); | ||
|
|
||
| const parent = provider.getTracer('test').startSpan('parent'); | ||
| await context.with(trace.setSpan(context.active(), parent), async () => { | ||
| await new moduleExports.Pool().acquire(); | ||
| }); | ||
| parent.end(); | ||
|
|
||
| const acquireSpan = memoryExporter.getFinishedSpans().find(span => span.name === 'generic-pool.acquire'); | ||
| expect(acquireSpan).toBeDefined(); | ||
| expect(acquireSpan!.parentSpanContext?.spanId).toBe(parent.spanContext().spanId); | ||
| }); | ||
|
|
||
| it('should not create anything if disabled', async () => { | ||
| const moduleExports = createPoolModule(); | ||
| const def = instrumentation.getModuleDefinitions()[0]!; | ||
| // Patch then unpatch to mimic the instrumentation being disabled. | ||
| def.patch!(moduleExports); | ||
| def.unpatch!(moduleExports); | ||
|
|
||
| await new moduleExports.Pool().acquire(); | ||
|
|
||
| expect(memoryExporter.getFinishedSpans()).toHaveLength(0); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.