Skip to content

Commit d50bc22

Browse files
committed
loosen types on v2/v3 tests (mostly) to not have to have v3 redis types around to compile
1 parent 79cd098 commit d50bc22

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

plugins/node/opentelemetry-instrumentation-redis/src/v2-v3/internal-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ export interface RedisCommand {
3131
callback: (err: Error | null, reply: unknown) => void;
3232
call_on_write: boolean;
3333
}
34+
35+
// Exported from "@types/[email protected]".
36+
export type Callback<T> = (err: Error | null, reply: T) => void;

plugins/node/opentelemetry-instrumentation-redis/src/v2-v3/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type * as redisTypes from 'redis';
1817
import { context, Span, SpanStatusCode } from '@opentelemetry/api';
1918
import { EventEmitter } from 'events';
2019

@@ -29,14 +28,14 @@ export const endSpan = (span: Span, err?: Error | null) => {
2928
};
3029

3130
export const getTracedCreateClient = (original: Function) => {
32-
return function createClientTrace(this: redisTypes.RedisClient) {
33-
const client: redisTypes.RedisClient = original.apply(this, arguments);
31+
return function createClientTrace(this: any) {
32+
const client = original.apply(this, arguments);
3433
return context.bind(context.active(), client);
3534
};
3635
};
3736

3837
export const getTracedCreateStreamTrace = (original: Function) => {
39-
return function create_stream_trace(this: redisTypes.RedisClient) {
38+
return function create_stream_trace(this: any) {
4039
if (!Object.prototype.hasOwnProperty.call(this, 'stream')) {
4140
Object.defineProperty(this, 'stream', {
4241
get() {

plugins/node/opentelemetry-instrumentation-redis/test/v2-v3/redis.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const instrumentation = registerInstrumentationTesting(
4343
new RedisInstrumentation()
4444
);
4545

46-
import * as redisTypes from 'redis';
46+
import type { Callback } from '../../src/v2-v3/internal-types';
4747
import { RedisResponseCustomAttributeFunction } from '../../src/types';
4848

4949
const CONFIG = {
@@ -65,7 +65,7 @@ const unsetStatus: SpanStatus = {
6565
};
6666

6767
describe('redis v2-v3', () => {
68-
let redis: typeof redisTypes;
68+
let redis: any;
6969
const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL;
7070
const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal;
7171
const tracer = trace.getTracer('external');
@@ -95,7 +95,7 @@ describe('redis v2-v3', () => {
9595
describe('#createClient()', () => {
9696
it('should propagate the current span to event handlers', done => {
9797
const span = tracer.startSpan('test span');
98-
let client: redisTypes.RedisClient;
98+
let client: any;
9999
const readyHandler = () => {
100100
assert.strictEqual(trace.getSpan(context.active()), span);
101101
client.quit(done);
@@ -114,43 +114,42 @@ describe('redis v2-v3', () => {
114114
});
115115

116116
describe('#send_internal_message()', () => {
117-
let client: redisTypes.RedisClient;
117+
let client: any;
118118

119119
const REDIS_OPERATIONS: Array<{
120120
description: string;
121121
command: string;
122122
args: string[];
123123
expectedDbStatement: string;
124-
method: (cb: redisTypes.Callback<unknown>) => unknown;
124+
method: (cb: Callback<unknown>) => unknown;
125125
}> = [
126126
{
127127
description: 'insert',
128128
command: 'hset',
129129
args: ['hash', 'random', 'random'],
130130
expectedDbStatement: 'hash random [1 other arguments]',
131-
method: (cb: redisTypes.Callback<number>) =>
131+
method: (cb: Callback<number>) =>
132132
client.hset('hash', 'random', 'random', cb),
133133
},
134134
{
135135
description: 'get',
136136
command: 'get',
137137
args: ['test'],
138138
expectedDbStatement: 'test',
139-
method: (cb: redisTypes.Callback<string | null>) =>
140-
client.get('test', cb),
139+
method: (cb: Callback<string | null>) => client.get('test', cb),
141140
},
142141
{
143142
description: 'delete',
144143
command: 'del',
145144
args: ['test'],
146145
expectedDbStatement: 'test',
147-
method: (cb: redisTypes.Callback<number>) => client.del('test', cb),
146+
method: (cb: Callback<number>) => client.del('test', cb),
148147
},
149148
];
150149

151150
before(done => {
152151
client = redis.createClient(URL);
153-
client.on('error', err => {
152+
client.on('error', (err: any) => {
154153
done(err);
155154
});
156155
client.on('ready', done);

0 commit comments

Comments
 (0)