Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node 20 to test matrix #4336

Merged
merged 8 commits into from Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/unit-test.yml
Expand Up @@ -15,6 +15,7 @@ jobs:
- "14"
- "16"
- "18"
- "20"
runs-on: ubuntu-latest
env:
NPM_CONFIG_UNSAFE_PERM: true
Expand Down Expand Up @@ -42,7 +43,7 @@ jobs:
- name: Unit tests
run: |
# TODO(legendecas): webpack https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
if [ "${{ matrix.node_version }}" = "18" ]; then
if [ "${{ matrix.node_version }}" = "18" ] || [ "${{ matrix.node_version }}" == "20" ]; then
export NODE_OPTIONS=--openssl-legacy-provider
fi
npm run test
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

* chore: type reference on zone.js [#4257](https://github.com/open-telemetry/opentelemetry-js/pull/4257) @legendecas
* chore: no need for 'packages' in lerna.json [#4264](https://github.com/open-telemetry/opentelemetry-js/pull/4264) @trentm
* test: add node 20 to test matrix [#4336](https://github.com/open-telemetry/opentelemetry-js/pull/4336) @dyladan

### :bug: (Bug Fix)

Expand Down
Expand Up @@ -360,8 +360,8 @@ describe('PrometheusExporter', () => {
.get('http://localhost:9464/metrics', res => {
errorHandler(done)(new Error('unreachable'));
})
.on('error', err => {
assert(`${err}`.match('ECONNREFUSED'));
.on('error', (err: any) => {
assert.equal(err.code, 'ECONNREFUSED');
done();
});
});
Expand Down
Expand Up @@ -15,7 +15,9 @@
*/

export * from './autoLoader';
export * from './platform/index';
export { InstrumentationBase } from './platform/index';
export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition';
export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile';
export * from './types';
export * from './types_internal';
export * from './utils';
Expand Up @@ -25,16 +25,19 @@ import {
TracerProvider,
} from '@opentelemetry/api';
import * as shimmer from 'shimmer';
import { InstrumentationModuleDefinition } from './platform/node';
import * as types from './types';
import {
InstrumentationModuleDefinition,
Instrumentation,
InstrumentationConfig,
} from './types';

/**
* Base abstract internal class for instrumenting node and web plugins
*/
export abstract class InstrumentationAbstract<T = any>
implements types.Instrumentation
implements Instrumentation
{
protected _config: types.InstrumentationConfig;
protected _config: InstrumentationConfig;

private _tracer: Tracer;
private _meter: Meter;
Expand All @@ -43,7 +46,7 @@ export abstract class InstrumentationAbstract<T = any>
constructor(
public readonly instrumentationName: string,
public readonly instrumentationVersion: string,
config: types.InstrumentationConfig = {}
config: InstrumentationConfig = {}
) {
this._config = {
enabled: true,
Expand Down Expand Up @@ -95,15 +98,15 @@ export abstract class InstrumentationAbstract<T = any>
}

/* Returns InstrumentationConfig */
public getConfig(): types.InstrumentationConfig {
public getConfig(): InstrumentationConfig {
return this._config;
}

/**
* Sets InstrumentationConfig to this plugin
* @param InstrumentationConfig
*/
public setConfig(config: types.InstrumentationConfig = {}): void {
public setConfig(config: InstrumentationConfig = {}): void {
this._config = Object.assign({}, config);
}

Expand Down
@@ -0,0 +1,35 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
InstrumentationModuleDefinition,
InstrumentationModuleFile,
} from './types';

export class InstrumentationNodeModuleDefinition<T>
implements InstrumentationModuleDefinition<T>
{
files: InstrumentationModuleFile<T>[];
constructor(
public name: string,
public supportedVersions: string[],
public patch?: (exports: T, moduleVersion?: string) => T,
public unpatch?: (exports: T, moduleVersion?: string) => void,
files?: InstrumentationModuleFile<any>[]

Check warning on line 31 in experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts#L27-L31

Added lines #L27 - L31 were not covered by tests
) {
this.files = files || [];

Check warning on line 33 in experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts#L33

Added line #L33 was not covered by tests
}
}
@@ -0,0 +1,32 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { InstrumentationModuleFile } from './types';
import { normalize } from 'path';

export class InstrumentationNodeModuleFile<T>
implements InstrumentationModuleFile<T>
{
public name: string;
constructor(
name: string,
public supportedVersions: string[],
public patch: (moduleExports: T, moduleVersion?: string) => T,
public unpatch: (moduleExports?: T, moduleVersion?: string) => void

Check warning on line 28 in experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts#L26-L28

Added lines #L26 - L28 were not covered by tests
) {
this.name = normalize(name);

Check warning on line 30 in experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts#L30

Added line #L30 was not covered by tests
}
}
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './instrumentation';
export { InstrumentationBase } from './instrumentation';
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './node';
export { InstrumentationBase } from './node';
dyladan marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -13,7 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './instrumentation';
export * from './instrumentationNodeModuleDefinition';
export * from './instrumentationNodeModuleFile';
export * from './types';
export { InstrumentationBase } from './instrumentation';
Expand Up @@ -26,7 +26,7 @@ import {
} from './RequireInTheMiddleSingleton';
import type { HookFn } from 'import-in-the-middle';
import * as ImportInTheMiddle from 'import-in-the-middle';
import { InstrumentationModuleDefinition } from './types';
import { InstrumentationModuleDefinition } from '../../types';
import { diag } from '@opentelemetry/api';
import type { OnRequireFn } from 'require-in-the-middle';
import { Hook } from 'require-in-the-middle';
Expand Down
Expand Up @@ -77,3 +77,47 @@ export interface ShimWrapped extends Function {
// eslint-disable-next-line @typescript-eslint/ban-types
__original: Function;
}

export interface InstrumentationModuleFile<T> {
/** Name of file to be patched with relative path */
name: string;

moduleExports?: T;

/** Supported version this file */
supportedVersions: string[];

/** Method to patch the instrumentation */
patch(moduleExports: T, moduleVersion?: string): T;

/** Method to patch the instrumentation */

/** Method to unpatch the instrumentation */
unpatch(moduleExports?: T, moduleVersion?: string): void;
}

export interface InstrumentationModuleDefinition<T> {
/** Module name or path */
name: string;

moduleExports?: T;

/** Instrumented module version */
moduleVersion?: string;

/** Supported version of module */
supportedVersions: string[];

/** Module internal files to be patched */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
files: InstrumentationModuleFile<any>[];

/** If set to true, the includePrerelease check will be included when calling semver.satisfies */
includePrerelease?: boolean;

/** Method to patch the instrumentation */
patch?: (moduleExports: T, moduleVersion?: string) => T;

/** Method to unpatch the instrumentation */
unpatch?: (moduleExports: T, moduleVersion?: string) => void;
}
Expand Up @@ -17,12 +17,12 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as path from 'path';
import { InstrumentationBase } from '../../src';
import {
InstrumentationBase,
InstrumentationModuleDefinition,
InstrumentationNodeModuleDefinition,
InstrumentationModuleDefinition,
InstrumentationNodeModuleFile,
} from '../../src';
} from '../../src/';
dyladan marked this conversation as resolved.
Show resolved Hide resolved

const MODULE_NAME = 'test-module';
const MODULE_FILE_NAME = 'test-module-file';
Expand Down