Skip to content

Commit 537cd34

Browse files
committed
chore: lint:fix
1 parent 4ecf3a8 commit 537cd34

File tree

5 files changed

+115
-94
lines changed

5 files changed

+115
-94
lines changed
Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,84 @@
1-
import { InstrumentationBase } from "@opentelemetry/instrumentation";
2-
import { RedisInstrumentationConfig } from "./types";
3-
import { PACKAGE_NAME, PACKAGE_VERSION } from "./version";
4-
import { RedisInstrumentationV2_3 } from "./v2-3/instrumentation";
5-
import { TracerProvider } from "@opentelemetry/api";
6-
import { RedisInstrumentationV4 } from "./v4/instrumentation";
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { InstrumentationBase } from '@opentelemetry/instrumentation';
17+
import { RedisInstrumentationConfig } from './types';
18+
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
19+
import { RedisInstrumentationV2_3 } from './v2-3/instrumentation';
20+
import { TracerProvider } from '@opentelemetry/api';
21+
import { RedisInstrumentationV4 } from './v4/instrumentation';
722

823
const DEFAULT_CONFIG: RedisInstrumentationConfig = {
9-
requireParentSpan: false,
24+
requireParentSpan: false,
1025
};
1126

1227
// Wrapper RedisInstrumentation that address all supported versions
1328
export class RedisInstrumentation extends InstrumentationBase<RedisInstrumentationConfig> {
29+
private instrumentationV2_3: RedisInstrumentationV2_3;
30+
private instrumentationV4: RedisInstrumentationV4;
1431

15-
private instrumentationV2_3: RedisInstrumentationV2_3;
16-
private instrumentationV4: RedisInstrumentationV4;
32+
// this is used to bypass a flaw in the base class constructor, which is calling
33+
// member functions before the constructor has a chance to fully initialize the member variables.
34+
private initialized = false;
1735

18-
// this is used to bypass a flaw in the base class constructor, which is calling
19-
// member functions before the constructor has a chance to fully initialize the member variables.
20-
private initialized = false;
36+
constructor(config: RedisInstrumentationConfig = {}) {
37+
const resolvedConfig = { ...DEFAULT_CONFIG, ...config };
38+
super(PACKAGE_NAME, PACKAGE_VERSION, resolvedConfig);
2139

22-
constructor(config: RedisInstrumentationConfig = {}) {
23-
const resolvedConfig = { ...DEFAULT_CONFIG, ...config };
24-
super(PACKAGE_NAME, PACKAGE_VERSION, resolvedConfig);
40+
this.instrumentationV2_3 = new RedisInstrumentationV2_3(this.getConfig());
41+
this.instrumentationV4 = new RedisInstrumentationV4(this.getConfig());
42+
this.initialized = true;
43+
}
2544

26-
this.instrumentationV2_3 = new RedisInstrumentationV2_3(this.getConfig());
27-
this.instrumentationV4 = new RedisInstrumentationV4(this.getConfig());
28-
this.initialized = true;
45+
override setConfig(config: RedisInstrumentationConfig = {}) {
46+
const newConfig = { ...DEFAULT_CONFIG, ...config };
47+
super.setConfig(newConfig);
48+
if (!this.initialized) {
49+
return;
2950
}
3051

31-
override setConfig(config: RedisInstrumentationConfig = {}) {
32-
const newConfig = { ...DEFAULT_CONFIG, ...config };
33-
super.setConfig(newConfig);
34-
if (!this.initialized) {
35-
return
36-
}
52+
this.instrumentationV2_3.setConfig(newConfig);
53+
this.instrumentationV4.setConfig(newConfig);
54+
}
3755

38-
this.instrumentationV2_3.setConfig(newConfig);
39-
this.instrumentationV4.setConfig(newConfig);
40-
}
41-
42-
override init() {
43-
}
56+
override init() {}
4457

45-
override setTracerProvider(tracerProvider: TracerProvider) {
46-
super.setTracerProvider(tracerProvider);
47-
if (!this.initialized) {
48-
return
49-
}
50-
this.instrumentationV2_3.setTracerProvider(tracerProvider);
51-
this.instrumentationV4.setTracerProvider(tracerProvider);
58+
override setTracerProvider(tracerProvider: TracerProvider) {
59+
super.setTracerProvider(tracerProvider);
60+
if (!this.initialized) {
61+
return;
5262
}
63+
this.instrumentationV2_3.setTracerProvider(tracerProvider);
64+
this.instrumentationV4.setTracerProvider(tracerProvider);
65+
}
5366

54-
override enable() {
55-
super.enable();
56-
if (!this.initialized) {
57-
return
58-
}
59-
this.instrumentationV2_3.enable();
60-
this.instrumentationV4.enable();
67+
override enable() {
68+
super.enable();
69+
if (!this.initialized) {
70+
return;
6171
}
72+
this.instrumentationV2_3.enable();
73+
this.instrumentationV4.enable();
74+
}
6275

63-
override disable() {
64-
super.disable();
65-
if (!this.initialized) {
66-
return
67-
}
68-
this.instrumentationV2_3.disable();
69-
this.instrumentationV4.disable();
76+
override disable() {
77+
super.disable();
78+
if (!this.initialized) {
79+
return;
7080
}
71-
}
81+
this.instrumentationV2_3.disable();
82+
this.instrumentationV4.disable();
83+
}
84+
}

plugins/node/opentelemetry-instrumentation-redis/src/v2-3/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,4 @@ export class RedisInstrumentationV2_3 extends InstrumentationBase<RedisInstrumen
212212
return getTracedCreateStreamTrace(original);
213213
};
214214
}
215-
}
215+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ export const getTracedCreateStreamTrace = (original: Function) => {
5050
}
5151
return original.apply(this, arguments);
5252
};
53-
};
53+
};

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,30 @@ describe('[email protected]', () => {
124124
expectedDbStatement: string;
125125
method: (cb: redisTypes.Callback<unknown>) => unknown;
126126
}> = [
127-
{
128-
description: 'insert',
129-
command: 'hset',
130-
args: ['hash', 'random', 'random'],
131-
expectedDbStatement: 'hash random [1 other arguments]',
132-
method: (cb: redisTypes.Callback<number>) =>
133-
client.hset('hash', 'random', 'random', cb),
134-
},
135-
{
136-
description: 'get',
137-
command: 'get',
138-
args: ['test'],
139-
expectedDbStatement: 'test',
140-
method: (cb: redisTypes.Callback<string | null>) =>
141-
client.get('test', cb),
142-
},
143-
{
144-
description: 'delete',
145-
command: 'del',
146-
args: ['test'],
147-
expectedDbStatement: 'test',
148-
method: (cb: redisTypes.Callback<number>) => client.del('test', cb),
149-
},
150-
];
127+
{
128+
description: 'insert',
129+
command: 'hset',
130+
args: ['hash', 'random', 'random'],
131+
expectedDbStatement: 'hash random [1 other arguments]',
132+
method: (cb: redisTypes.Callback<number>) =>
133+
client.hset('hash', 'random', 'random', cb),
134+
},
135+
{
136+
description: 'get',
137+
command: 'get',
138+
args: ['test'],
139+
expectedDbStatement: 'test',
140+
method: (cb: redisTypes.Callback<string | null>) =>
141+
client.get('test', cb),
142+
},
143+
{
144+
description: 'delete',
145+
command: 'del',
146+
args: ['test'],
147+
expectedDbStatement: 'test',
148+
method: (cb: redisTypes.Callback<number>) => client.del('test', cb),
149+
},
150+
];
151151

152152
before(done => {
153153
client = redis.createClient(URL);
@@ -159,7 +159,7 @@ describe('[email protected]', () => {
159159

160160
beforeEach(done => {
161161
client.set('test', 'data', () => {
162-
testUtils.resetMemoryExporter()
162+
testUtils.resetMemoryExporter();
163163
done();
164164
});
165165
});
@@ -220,7 +220,10 @@ describe('[email protected]', () => {
220220
});
221221

222222
describe('dbStatementSerializer config', () => {
223-
const dbStatementSerializer = (cmdName: string, cmdArgs: Array<string | Buffer>) => {
223+
const dbStatementSerializer = (
224+
cmdName: string,
225+
cmdArgs: Array<string | Buffer>
226+
) => {
224227
return Array.isArray(cmdArgs) && cmdArgs.length
225228
? `${cmdName} ${cmdArgs.join(' ')}`
226229
: cmdName;

plugins/node/opentelemetry-instrumentation-redis/test/v4/redis.test.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ describe('redis@^4.0.0', () => {
218218
});
219219

220220
it('sets error status on connection failure', async () => {
221-
const redisURL = `redis://${redisTestConfig.host}:${redisTestConfig.port + 1
222-
}`;
221+
const redisURL = `redis://${redisTestConfig.host}:${
222+
redisTestConfig.port + 1
223+
}`;
223224
const newClient = createClient({
224225
url: redisURL,
225226
});
@@ -237,10 +238,12 @@ describe('redis@^4.0.0', () => {
237238
});
238239

239240
it('omits basic auth from DB_CONNECTION_STRING span attribute', async () => {
240-
const redisURL = `redis://myuser:mypassword@${redisTestConfig.host}:${redisTestConfig.port + 1
241-
}`;
242-
const expectAttributeConnString = `redis://${redisTestConfig.host}:${redisTestConfig.port + 1
243-
}`;
241+
const redisURL = `redis://myuser:mypassword@${redisTestConfig.host}:${
242+
redisTestConfig.port + 1
243+
}`;
244+
const expectAttributeConnString = `redis://${redisTestConfig.host}:${
245+
redisTestConfig.port + 1
246+
}`;
244247
const newClient = createClient({
245248
url: redisURL,
246249
});
@@ -262,10 +265,12 @@ describe('redis@^4.0.0', () => {
262265
});
263266

264267
it('omits user_pwd query parameter from DB_CONNECTION_STRING span attribute', async () => {
265-
const redisURL = `redis://${redisTestConfig.host}:${redisTestConfig.port + 1
266-
}?db=mydb&user_pwd=mypassword`;
267-
const expectAttributeConnString = `redis://${redisTestConfig.host}:${redisTestConfig.port + 1
268-
}?db=mydb`;
268+
const redisURL = `redis://${redisTestConfig.host}:${
269+
redisTestConfig.port + 1
270+
}?db=mydb&user_pwd=mypassword`;
271+
const expectAttributeConnString = `redis://${redisTestConfig.host}:${
272+
redisTestConfig.port + 1
273+
}?db=mydb`;
269274
const newClient = createClient({
270275
url: redisURL,
271276
});
@@ -291,10 +296,10 @@ describe('redis@^4.0.0', () => {
291296
const diagErrors = [] as any;
292297
diag.setLogger(
293298
{
294-
verbose() { },
295-
debug() { },
296-
info() { },
297-
warn() { },
299+
verbose() {},
300+
debug() {},
301+
info() {},
302+
warn() {},
298303
error(...args) {
299304
diagErrors.push(args);
300305
},

0 commit comments

Comments
 (0)