Skip to content

Commit 976dcd2

Browse files
authored
fix(instrumentation-redis): properly implement getModuleDefinitions() in the merged-from-two RedisInstrumentation (#3025)
1 parent d60ff3a commit 976dcd2

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

packages/instrumentation-redis/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"prepublishOnly": "npm run compile",
2020
"tdd": "npm run test -- --watch-extensions ts --watch",
2121
"test-v2-v3": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/v2-v3/*.test.ts'",
22-
"test": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/v4-v5/*.test.ts'",
22+
"test": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/v4-v5/*.test.ts' 'test/*.test.ts'",
2323
"test:debug": "cross-env RUN_REDIS_TESTS=true mocha --inspect-brk --no-timeouts 'test/**/*.test.ts'",
2424
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
2525
"test-all-versions": "tav",

packages/instrumentation-redis/src/redis.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { InstrumentationBase } from '@opentelemetry/instrumentation';
16+
import {
17+
InstrumentationBase,
18+
InstrumentationModuleDefinition,
19+
} from '@opentelemetry/instrumentation';
1720
import { RedisInstrumentationConfig } from './types';
1821
/** @knipignore */
1922
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
@@ -56,6 +59,15 @@ export class RedisInstrumentation extends InstrumentationBase<RedisInstrumentati
5659

5760
override init() {}
5861

62+
// Return underlying modules, as consumers (like https://github.com/DrewCorlin/opentelemetry-node-bundler-plugins) may
63+
// expect them to be populated without knowing that this module wraps 2 instrumentations
64+
override getModuleDefinitions(): InstrumentationModuleDefinition[] {
65+
return [
66+
...this.instrumentationV2_V3.getModuleDefinitions(),
67+
...this.instrumentationV4_V5.getModuleDefinitions(),
68+
];
69+
}
70+
5971
override setTracerProvider(tracerProvider: TracerProvider) {
6072
super.setTracerProvider(tracerProvider);
6173
if (!this.initialized) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
17+
import { RedisInstrumentation } from '../src';
18+
import * as assert from 'assert';
19+
20+
describe('redis', () => {
21+
it('Returns module definitions of sub-instrumentations', () => {
22+
const instrumentation = new RedisInstrumentation();
23+
const moduleDefinitions = instrumentation.getModuleDefinitions();
24+
assert.ok(moduleDefinitions.length >= 1);
25+
});
26+
});

0 commit comments

Comments
 (0)