forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow mysql streamable query with values array (open-telemetry#790)
Co-authored-by: Rauno Viskus <[email protected]>
- Loading branch information
Showing
2 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,28 @@ describe('[email protected]', () => { | |
}); | ||
}); | ||
|
||
it('should intercept connection.query(text: options, values: [])', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
const sql = 'SELECT 1+? as solution'; | ||
let rows = 0; | ||
const query = connection.query(sql, [1]); | ||
|
||
query.on('result', row => { | ||
assert.strictEqual(row.solution, 2); | ||
rows += 1; | ||
}); | ||
|
||
query.on('end', () => { | ||
assert.strictEqual(rows, 1); | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans.length, 1); | ||
assertSpan(spans[0], sql, [1]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should intercept connection.query(text: options, values: [], callback)', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
|
@@ -365,6 +387,28 @@ describe('[email protected]', () => { | |
}); | ||
}); | ||
|
||
it('should intercept pool.query(text: options, values: [])', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
const sql = 'SELECT 1+? as solution'; | ||
let rows = 0; | ||
const query = pool.query(sql, [1]); | ||
|
||
query.on('result', row => { | ||
assert.strictEqual(row.solution, 2); | ||
rows += 1; | ||
}); | ||
|
||
query.on('end', () => { | ||
assert.strictEqual(rows, 1); | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans.length, 1); | ||
assertSpan(spans[0], sql, [1]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should intercept pool.query(text: options, values: [], callback)', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
|
@@ -511,6 +555,31 @@ describe('[email protected]', () => { | |
}); | ||
}); | ||
|
||
it('should intercept poolClusterConnection.query(text: options, values: [])', done => { | ||
poolCluster.getConnection((err, poolClusterConnection) => { | ||
assert.ifError(err); | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
const sql = 'SELECT 1+? as solution'; | ||
const query = poolClusterConnection.query(sql, [1]); | ||
let rows = 0; | ||
|
||
query.on('result', row => { | ||
assert.strictEqual(row.solution, 2); | ||
rows += 1; | ||
}); | ||
|
||
query.on('end', () => { | ||
assert.strictEqual(rows, 1); | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans.length, 1); | ||
assertSpan(spans[0], sql, [1]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should intercept poolClusterConnection.query(text: options, values: [], callback)', done => { | ||
poolCluster.getConnection((err, poolClusterConnection) => { | ||
assert.ifError(err); | ||
|