Skip to content

Commit

Permalink
fix(instrumentation): do not throw
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc committed Jan 3, 2024
1 parent b4a193d commit aa42161
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*/

export { InstrumentationBase } from './instrumentation';
export { normalize } from './throwing-normalize';
export { normalize } from './noop-normalize';
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
* limitations under the License.
*/

import { diag } from '@opentelemetry/api';

/**
* Placeholder normalize function to replace the node variant in browser runtimes,
* this should never be called and will throw if it is called.
* this should never be called and will perform a no-op and warn if it is called regardless.
*
* This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/4373 until the instrumentation
* package can be made node-only.
*
* @param _path unused input path
* @param path input path
* @return unmodified path
* @internal
*/
export function normalize(_path: string): string {
throw new Error('Not implemented');
export function normalize(path: string): string {
diag.warn(
'Path normalization is not implemented for this platform. To silence this warning, ensure no node-specific instrumentations are loaded, and node-specific types (e.g. InstrumentationNodeModuleFile), are not used in a browser context)'
);
return path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import * as assert from 'assert';
import { normalize } from '../../src/platform/browser';

describe('throwing-normalize', () => {
assert.throws(() => {
normalize('foo');
describe('noop-normalize', function () {
it('should not normalize input', function () {
assert.strictEqual(normalize('/tmp/foo/../bar'), '/tmp/foo/../bar');
});
});

0 comments on commit aa42161

Please sign in to comment.