-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mysql] fix: ensure span name is a string to avoid [object Object] as…
… span name (#208) * fix: ensure span name is a string to avoid [object Object] as span name Signed-off-by: Naseem <[email protected]> * fix: make test read better Signed-off-by: Naseem <[email protected]>
- Loading branch information
Naseem
authored
Oct 9, 2020
1 parent
807346b
commit cd24cdf
Showing
3 changed files
with
54 additions
and
9 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
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 |
---|---|---|
|
@@ -124,6 +124,38 @@ describe('[email protected]', () => { | |
assert.strictEqual(plugin.moduleName, 'mysql'); | ||
}); | ||
|
||
describe('when the query is a string', () => { | ||
it('should name the span accordingly ', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
provider.getTracer('default').withSpan(span, () => { | ||
const sql = 'SELECT 1+1 as solution'; | ||
const query = connection.query(sql); | ||
|
||
query.on('end', () => { | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans[0].name, 'SELECT'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the query is an object', () => { | ||
it('should name the span accordingly ', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
provider.getTracer('default').withSpan(span, () => { | ||
const sql = 'SELECT 1+? as solution'; | ||
const query = connection.query({ sql, values: [1] }); | ||
|
||
query.on('end', () => { | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans[0].name, sql); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#Connection', () => { | ||
it('should intercept connection.query(text: string)', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
|
@@ -585,17 +617,17 @@ function assertSpan( | |
values?: any, | ||
errorMessage?: string | ||
) { | ||
assert.equal(span.attributes[DatabaseAttribute.DB_SYSTEM], 'mysql'); | ||
assert.equal(span.attributes[DatabaseAttribute.DB_NAME], database); | ||
assert.equal(span.attributes[GeneralAttribute.NET_PEER_PORT], port); | ||
assert.equal(span.attributes[GeneralAttribute.NET_PEER_HOSTNAME], host); | ||
assert.equal(span.attributes[DatabaseAttribute.DB_USER], user); | ||
assert.strictEqual(span.attributes[DatabaseAttribute.DB_SYSTEM], 'mysql'); | ||
assert.strictEqual(span.attributes[DatabaseAttribute.DB_NAME], database); | ||
assert.strictEqual(span.attributes[GeneralAttribute.NET_PEER_PORT], port); | ||
assert.strictEqual(span.attributes[GeneralAttribute.NET_PEER_HOSTNAME], host); | ||
assert.strictEqual(span.attributes[DatabaseAttribute.DB_USER], user); | ||
assert.strictEqual( | ||
span.attributes[DatabaseAttribute.DB_STATEMENT], | ||
mysql.format(sql, values) | ||
); | ||
if (errorMessage) { | ||
assert.equal(span.status.message, errorMessage); | ||
assert.equal(span.status.code, CanonicalCode.UNKNOWN); | ||
assert.strictEqual(span.status.message, errorMessage); | ||
assert.strictEqual(span.status.code, CanonicalCode.UNKNOWN); | ||
} | ||
} |