Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Sep 4, 2024
1 parent 282433f commit e2cce47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/collector/test/tracing/database/ioredis/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const mochaSuiteFn =

function checkConnection(span, setupType) {
if (setupType === 'cluster') {
// Internal IP of azure cluster.
expect(span.data.redis.connection).to.equal(process.env.AZURE_REDIS_CLUSTER);
} else {
expect(span.data.redis.connection).to.equal(process.env.REDIS);
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/tracing/instrumentation/database/ioredis.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function instrument(ioredis) {
constructor() {
super(...arguments);

clusterConnectionString = this.startupNodes.map(node => `${node.host}:${node.port}`).join(',');
try {
clusterConnectionString = this.startupNodes.map(node => `${node.host}:${node.port}`).join(',');
} catch (e) {
// ignore
}
}
}

Expand All @@ -47,8 +51,9 @@ function instrument(ioredis) {
enumerable: true
});

// The "sendCommand" is called on the cluster instance as well, but `client.isCluster` is false.
// We need to workaround and getting the cluster connection via the class constructor.
// We cannot register `ioredis.Cluster.prototype.sendCommand` otherwise we produce two spans for the same command.
// Because `ioredis.prototype.sendCommand` is triggerd when using a cluster, but `client.isCluster` is false.
// Thats why we override the Cluster Class and extract the connection string.
shimmer.wrap(ioredis.prototype, 'sendCommand', instrumentSendCommand);
shimmer.wrap(ioredis.prototype, 'multi', instrumentMultiCommand);
shimmer.wrap(ioredis.prototype, 'pipeline', instrumentPipelineCommand);
Expand Down

0 comments on commit e2cce47

Please sign in to comment.