From 91213fa349f95236fcd2eb85e392ba980f852e99 Mon Sep 17 00:00:00 2001 From: Naseem Date: Wed, 2 Sep 2020 01:37:21 -0400 Subject: [PATCH 1/2] fix: prefer import type, remove unneeded type and only import required type where applicable Signed-off-by: Naseem --- .../node/opentelemetry-plugin-redis/src/redis.ts | 4 ++-- .../node/opentelemetry-plugin-redis/src/types.ts | 9 ++------- .../node/opentelemetry-plugin-redis/src/utils.ts | 16 ++++++---------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/plugins/node/opentelemetry-plugin-redis/src/redis.ts b/plugins/node/opentelemetry-plugin-redis/src/redis.ts index c0458c6861..525edd0a58 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/redis.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/redis.ts @@ -15,7 +15,7 @@ */ import { BasePlugin } from '@opentelemetry/core'; -import * as redisTypes from 'redis'; +import type * as redis from 'redis'; import * as shimmer from 'shimmer'; import { getTracedCreateClient, @@ -24,7 +24,7 @@ import { } from './utils'; import { VERSION } from './version'; -export class RedisPlugin extends BasePlugin { +export class RedisPlugin extends BasePlugin { static readonly COMPONENT = 'redis'; readonly supportedVersions = ['^2.6.0']; // equivalent to >= 2.6.0 <3 diff --git a/plugins/node/opentelemetry-plugin-redis/src/types.ts b/plugins/node/opentelemetry-plugin-redis/src/types.ts index 4d9daafe98..2b8e35647b 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/types.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import * as redisTypes from 'redis'; -import { EventEmitter } from 'events'; +import type { Callback } from 'redis'; // exported from // https://github.com/NodeRedis/node_redis/blob/master/lib/command.js @@ -23,7 +22,7 @@ export interface RedisCommand { command: string; args: string[]; buffer_args: boolean; - callback: redisTypes.Callback; + callback: Callback; call_on_write: boolean; } @@ -35,7 +34,3 @@ export interface RedisPluginClientTypes { address?: string; } - -export interface RedisPluginStreamTypes { - stream?: { get(): EventEmitter; set(val: EventEmitter): void }; -} diff --git a/plugins/node/opentelemetry-plugin-redis/src/utils.ts b/plugins/node/opentelemetry-plugin-redis/src/utils.ts index 6d486d5324..106d778d59 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/utils.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/utils.ts @@ -14,13 +14,9 @@ * limitations under the License. */ -import * as redisTypes from 'redis'; +import type { RedisClient } from 'redis'; import { Tracer, SpanKind, Span, CanonicalCode } from '@opentelemetry/api'; -import { - RedisPluginStreamTypes, - RedisPluginClientTypes, - RedisCommand, -} from './types'; +import { RedisCommand, RedisPluginClientTypes } from './types'; import { EventEmitter } from 'events'; import { RedisPlugin } from './redis'; import { @@ -41,8 +37,8 @@ const endSpan = (span: Span, err?: Error | null) => { }; export const getTracedCreateClient = (tracer: Tracer, original: Function) => { - return function createClientTrace(this: redisTypes.RedisClient) { - const client: redisTypes.RedisClient = original.apply(this, arguments); + return function createClientTrace(this: RedisClient) { + const client: RedisClient = original.apply(this, arguments); return tracer.bind(client); }; }; @@ -51,7 +47,7 @@ export const getTracedCreateStreamTrace = ( tracer: Tracer, original: Function ) => { - return function create_stream_trace(this: RedisPluginStreamTypes) { + return function create_stream_trace(this: RedisClient) { if (!this.stream) { Object.defineProperty(this, 'stream', { get() { @@ -72,7 +68,7 @@ export const getTracedInternalSendCommand = ( original: Function ) => { return function internal_send_command_trace( - this: redisTypes.RedisClient & RedisPluginClientTypes, + this: RedisPluginClientTypes, cmd?: RedisCommand ) { // New versions of redis (2.4+) use a single options object From 806663bb2b376f557ab146fc68f5e11c64a2d043 Mon Sep 17 00:00:00 2001 From: Naseem Date: Mon, 7 Sep 2020 20:41:06 -0400 Subject: [PATCH 2/2] fix: address cr -- import entire module rather than only used exports Signed-off-by: Naseem --- plugins/node/opentelemetry-plugin-redis/src/redis.ts | 4 ++-- plugins/node/opentelemetry-plugin-redis/src/types.ts | 4 ++-- plugins/node/opentelemetry-plugin-redis/src/utils.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/node/opentelemetry-plugin-redis/src/redis.ts b/plugins/node/opentelemetry-plugin-redis/src/redis.ts index 525edd0a58..a6a908746e 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/redis.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/redis.ts @@ -15,7 +15,7 @@ */ import { BasePlugin } from '@opentelemetry/core'; -import type * as redis from 'redis'; +import type * as redisTypes from 'redis'; import * as shimmer from 'shimmer'; import { getTracedCreateClient, @@ -24,7 +24,7 @@ import { } from './utils'; import { VERSION } from './version'; -export class RedisPlugin extends BasePlugin { +export class RedisPlugin extends BasePlugin { static readonly COMPONENT = 'redis'; readonly supportedVersions = ['^2.6.0']; // equivalent to >= 2.6.0 <3 diff --git a/plugins/node/opentelemetry-plugin-redis/src/types.ts b/plugins/node/opentelemetry-plugin-redis/src/types.ts index 2b8e35647b..2c3be48ba4 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/types.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Callback } from 'redis'; +import type * as redisTypes from 'redis'; // exported from // https://github.com/NodeRedis/node_redis/blob/master/lib/command.js @@ -22,7 +22,7 @@ export interface RedisCommand { command: string; args: string[]; buffer_args: boolean; - callback: Callback; + callback: redisTypes.Callback; call_on_write: boolean; } diff --git a/plugins/node/opentelemetry-plugin-redis/src/utils.ts b/plugins/node/opentelemetry-plugin-redis/src/utils.ts index 106d778d59..bee33d287b 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/utils.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/utils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { RedisClient } from 'redis'; +import type * as redisTypes from 'redis'; import { Tracer, SpanKind, Span, CanonicalCode } from '@opentelemetry/api'; import { RedisCommand, RedisPluginClientTypes } from './types'; import { EventEmitter } from 'events'; @@ -37,8 +37,8 @@ const endSpan = (span: Span, err?: Error | null) => { }; export const getTracedCreateClient = (tracer: Tracer, original: Function) => { - return function createClientTrace(this: RedisClient) { - const client: RedisClient = original.apply(this, arguments); + return function createClientTrace(this: redisTypes.RedisClient) { + const client: redisTypes.RedisClient = original.apply(this, arguments); return tracer.bind(client); }; }; @@ -47,7 +47,7 @@ export const getTracedCreateStreamTrace = ( tracer: Tracer, original: Function ) => { - return function create_stream_trace(this: RedisClient) { + return function create_stream_trace(this: redisTypes.RedisClient) { if (!this.stream) { Object.defineProperty(this, 'stream', { get() {