Skip to content

Commit

Permalink
[PATCH] Ensure agent is always set for mysql/grpc (#343)
Browse files Browse the repository at this point in the history
If either of these modules switch to lazily importing any of our patched
files, we would fail to set the agent in some cases.

PR-URL: googleapis/cloud-trace-nodejs#343
  • Loading branch information
matthewloring authored and vmarchaud committed Jan 16, 2017
1 parent ef86b60 commit 76b62fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/hooks/userspace/hook-grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ module.exports = function(version_, agent_) {
return {
'src/node/src/client.js': {
patch: function(client) {
agent = agent_;
if (!agent) {
agent = agent_;
}
shimmer.wrap(client, 'makeClientConstructor',
makeClientConstructorWrap);
},
Expand All @@ -445,6 +447,9 @@ module.exports = function(version_, agent_) {
},
'src/node/src/server.js': {
patch: function(server) {
if (!agent) {
agent = agent_;
}
shimmer.wrap(server.Server.prototype, 'register', serverRegisterWrap);
},
unpatch: function(server) {
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/userspace/hook-mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ module.exports = function(version_, agent_) {
return {
'lib/Connection.js': {
patch: function(Connection) {
agent = agent_;
if (!agent) {
agent = agent_;
}
shimmer.wrap(Connection, 'createQuery', createQueryWrap);
},
unpatch: function(Connection) {
Expand All @@ -96,6 +98,9 @@ module.exports = function(version_, agent_) {
},
'lib/Pool.js': {
patch: function(Pool) {
if (!agent) {
agent = agent_;
}
shimmer.wrap(Pool.prototype, 'getConnection', wrapGetConnection);
},
unpatch: function(Pool) {
Expand Down

0 comments on commit 76b62fd

Please sign in to comment.