Skip to content

Commit

Permalink
style(instrumentation-ioredis): use default config
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Blum committed Mar 4, 2021
1 parent 060da2f commit 245efa3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 10 additions & 2 deletions plugins/node/opentelemetry-instrumentation-ioredis/src/ioredis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ import { IORedisInstrumentationConfig } from './types';
import { traceConnection, traceSendCommand } from './utils';
import { VERSION } from './version';

const DEFAULT_CONFIG: IORedisInstrumentationConfig = {
requireParentSpan: true,
};

export class IORedisInstrumentation extends InstrumentationBase<
typeof ioredisTypes
> {
static readonly DB_SYSTEM = 'redis';
readonly supportedVersions = ['>1 <5'];

constructor(protected _config: IORedisInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-ioredis', VERSION, _config);
constructor(_config: IORedisInstrumentationConfig = {}) {
super(
'@opentelemetry/instrumentation-ioredis',
VERSION,
Object.assign({}, DEFAULT_CONFIG, _config)
);
}

init(): InstrumentationNodeModuleDefinition<typeof ioredisTypes>[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ export const traceSendCommand = (
if (arguments.length < 1 || typeof cmd !== 'object') {
return original.apply(this, arguments);
}
// Do not trace if there is not parent span
if (
config?.requireParentSpan !== false &&
getSpan(context.active()) === undefined
) {

const hasNoParentSpan = getSpan(context.active()) === undefined;
if (config?.requireParentSpan === true && hasNoParentSpan) {
return original.apply(this, arguments);
}

Expand Down

0 comments on commit 245efa3

Please sign in to comment.