-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrument multiple versions of the same module (#397)
PR-URL: #397
- Loading branch information
1 parent
6f05b15
commit 58b3dd4
Showing
2 changed files
with
75 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
// Prereqs: | ||
// Start docker daemon | ||
// ex) docker -d | ||
// Run a redis image binding the redis port | ||
// ex) docker run -p 6379:6379 -d redis | ||
var assert = require('assert'); | ||
var common = require('./common.js'); | ||
|
||
describe('multiple instrumentations of the same module', function() { | ||
var agent; | ||
var clientv0; | ||
var clientv2; | ||
|
||
before(function() { | ||
agent = require('../..').start({ | ||
enhancedDatabaseReporting: true, | ||
samplingRate: 0 | ||
}).get(); | ||
clientv0 = require('./fixtures/redis0.12').createClient(); | ||
clientv0.on('error', function(err) { | ||
assert(false, 'redisv0 error ' + err); | ||
}); | ||
clientv2 = require('./fixtures/redis2.x').createClient(); | ||
clientv2.on('error', function(err) { | ||
assert(false, 'redisv2 error ' + err); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
clientv0.quit(function() { | ||
clientv2.quit(function() { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should record spans', function(done) { | ||
common.runInTransaction(agent, function(endTransaction) { | ||
clientv0.get('v0', function(err, n) { | ||
clientv2.get('v2', function(err, n) { | ||
endTransaction(); | ||
var spans = common.getMatchingSpans(agent, redisPredicate.bind(null, 'redis-get')); | ||
assert.equal(spans.length, 2); | ||
assert.equal(spans[0].labels.arguments, '["v0"]'); | ||
assert.equal(spans[0].labels.command, 'get'); | ||
assert.equal(spans[1].labels.arguments, '["v2"]'); | ||
assert.equal(spans[1].labels.command, 'get'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function redisPredicate(id, span) { | ||
return span.name.length >= id.length && | ||
span.name.substr(0, id.length) === id; | ||
} |
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