Skip to content

Commit 0c7fef7

Browse files
authored
chore: fixing path of instrumentation file for different systems (#1999)
1 parent d6e9654 commit 0c7fef7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
*/
1616

1717
import { InstrumentationModuleFile } from './types';
18+
import { normalize } from 'path';
1819

1920
export class InstrumentationNodeModuleFile<T>
2021
implements InstrumentationModuleFile<T> {
22+
public name: string;
2123
constructor(
22-
public name: string,
24+
name: string,
2325
public supportedVersions: string[],
2426
public patch: (moduleExports: T, moduleVersion?: string) => T,
2527
public unpatch: (moduleExports?: T, moduleVersion?: string) => void
26-
) {}
28+
) {
29+
this.name = normalize(name);
30+
}
2731
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 * as assert from 'assert';
18+
import { normalize } from 'path';
19+
import { InstrumentationNodeModuleFile } from '../../src';
20+
21+
describe('InstrumentationNodeModuleFile', () => {
22+
it('should convert path', () => {
23+
const tests = ['c:\\\\foo\\\\bar\\aa', '///home//foo/bar///aa'];
24+
tests.forEach(name => {
25+
const instrumentationNodeModuleFile = new InstrumentationNodeModuleFile(
26+
name,
27+
[],
28+
() => {},
29+
() => {}
30+
);
31+
assert.strictEqual(instrumentationNodeModuleFile.name, normalize(name));
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)