Skip to content

Commit

Permalink
Merge branch 'main' into semconv-1.25
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored May 13, 2024
2 parents f72598e + 50bd460 commit e9fcfba
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "experimental/packages/otlp-proto-exporter-base/protos"]
path = experimental/packages/otlp-proto-exporter-base/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/otlp-transformer/protos"]
path = experimental/packages/otlp-transformer/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
5 changes: 5 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ All notable changes to experimental packages in this project will be documented
* (internal) OTLPExporterBrowserBase: `RequestType` has been replaced by a `ResponseType` type-argument
* (internal) OTLPExporterNodeBase: `ServiceRequest` has been replaced by a `ServiceResponse` type-argument
* (internal) the `@opentelemetry/otlp-exporter-proto-base` package has been removed, and will from now on be deprecated in `npm`
* fix(instrumentation)!: remove unused supportedVersions from Instrumentation interface [#4694](https://github.com/open-telemetry/opentelemetry-js/pull/4694) @blumamir

### :rocket: (Enhancement)

* feat(instrumentation): apply unwrap before wrap in base class [#4692](https://github.com/open-telemetry/opentelemetry-js/pull/4692)
* feat(instrumentation): add util to execute span customization hook in base class [#4663](https://github.com/open-telemetry/opentelemetry-js/pull/4663) @blumamir
* feat(instrumentation): generic config type in instrumentation base [#4659](https://github.com/open-telemetry/opentelemetry-js/pull/4659) @blumamir
* feat: support node 22 [#4666](https://github.com/open-telemetry/opentelemetry-js/pull/4666) @dyladan
Expand All @@ -29,6 +31,9 @@ All notable changes to experimental packages in this project will be documented

### :books: (Refine Doc)

* docs(instrumentation): better docs for supportedVersions option [#4693](https://github.com/open-telemetry/opentelemetry-js/pull/4693) @blumamir
* docs: align all supported versions to a common format [#4696](https://github.com/open-telemetry/opentelemetry-js/pull/4696) @blumamir

### :house: (Internal)

## 0.51.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ For automatic instrumentation see the
npm install --save @opentelemetry/instrumentation-grpc
```

## Supported Versions

- [`@grpc/grpc-js`](https://www.npmjs.com/package/@grpc/grpc-js) versions `^1.0.0`

## Usage

OpenTelemetry gRPC Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with ([grpc-js](https://www.npmjs.com/package/@grpc/grpc-js)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
} from '@opentelemetry/api';
import {
InstrumentationNodeModuleDefinition,
isWrapped,
InstrumentationBase,
} from '@opentelemetry/instrumentation';
import {
Expand Down Expand Up @@ -100,57 +99,30 @@ export class GrpcInstrumentation extends InstrumentationBase<GrpcInstrumentation
return [
new InstrumentationNodeModuleDefinition(
'@grpc/grpc-js',
['1.*'],
['^1.0.0'],
moduleExports => {
if (isWrapped(moduleExports.Server.prototype.register)) {
this._unwrap(moduleExports.Server.prototype, 'register');
}
// Patch Server methods
this._wrap(
moduleExports.Server.prototype,
'register',
this._patchServer()
);
// Patch Client methods
if (isWrapped(moduleExports.makeGenericClientConstructor)) {
this._unwrap(moduleExports, 'makeGenericClientConstructor');
}
this._wrap(
moduleExports,
'makeGenericClientConstructor',
this._patchClient(moduleExports)
);
if (isWrapped(moduleExports.makeClientConstructor)) {
this._unwrap(moduleExports, 'makeClientConstructor');
}
this._wrap(
moduleExports,
'makeClientConstructor',
this._patchClient(moduleExports)
);
if (isWrapped(moduleExports.loadPackageDefinition)) {
this._unwrap(moduleExports, 'loadPackageDefinition');
}
this._wrap(
moduleExports,
'loadPackageDefinition',
this._patchLoadPackageDefinition(moduleExports)
);
if (isWrapped(moduleExports.Client.prototype)) {
this._unwrap(moduleExports.Client.prototype, 'makeUnaryRequest');
this._unwrap(
moduleExports.Client.prototype,
'makeClientStreamRequest'
);
this._unwrap(
moduleExports.Client.prototype,
'makeServerStreamRequest'
);
this._unwrap(
moduleExports.Client.prototype,
'makeBidiStreamRequest'
);
}
this._wrap(
moduleExports.Client.prototype,
'makeUnaryRequest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ For automatic instrumentation see the
npm install --save @opentelemetry/instrumentation-http
```

## Supported Versions

- Nodejs `>=14`

## Usage

OpenTelemetry HTTP Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { VERSION } from './version';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
isWrapped,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';
Expand Down Expand Up @@ -111,25 +110,16 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
'http',
['*'],
(moduleExports: Http): Http => {
if (isWrapped(moduleExports.request)) {
this._unwrap(moduleExports, 'request');
}
this._wrap(
moduleExports,
'request',
this._getPatchOutgoingRequestFunction('http')
);
if (isWrapped(moduleExports.get)) {
this._unwrap(moduleExports, 'get');
}
this._wrap(
moduleExports,
'get',
this._getPatchOutgoingGetFunction(moduleExports.request)
);
if (isWrapped(moduleExports.Server.prototype.emit)) {
this._unwrap(moduleExports.Server.prototype, 'emit');
}
this._wrap(
moduleExports.Server.prototype,
'emit',
Expand All @@ -152,25 +142,16 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
'https',
['*'],
(moduleExports: Https): Https => {
if (isWrapped(moduleExports.request)) {
this._unwrap(moduleExports, 'request');
}
this._wrap(
moduleExports,
'request',
this._getPatchHttpsOutgoingRequestFunction('https')
);
if (isWrapped(moduleExports.get)) {
this._unwrap(moduleExports, 'get');
}
this._wrap(
moduleExports,
'get',
this._getPatchHttpsOutgoingGetFunction(moduleExports.request)
);
if (isWrapped(moduleExports.Server.prototype.emit)) {
this._unwrap(moduleExports.Server.prototype, 'emit');
}
this._wrap(
moduleExports.Server.prototype,
'emit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { diag } from '@opentelemetry/api';
import type { OnRequireFn } from 'require-in-the-middle';
import { Hook } from 'require-in-the-middle';
import { readFileSync } from 'fs';
import { isWrapped } from '../../utils';

/**
* Base abstract class for instrumenting node plugins
Expand Down Expand Up @@ -79,6 +80,9 @@ export abstract class InstrumentationBase<
}

protected override _wrap: typeof wrap = (moduleExports, name, wrapper) => {
if (isWrapped(moduleExports[name])) {
this._unwrap(moduleExports, name);
}
if (!utilTypes.isProxy(moduleExports)) {
return wrap(moduleExports, name, wrapper);
} else {
Expand Down
38 changes: 26 additions & 12 deletions experimental/packages/opentelemetry-instrumentation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ export interface Instrumentation<

/** Method to get instrumentation config */
getConfig(): ConfigType;

/**
* Contains all supported versions.
* All versions must be compatible with [semver](https://semver.org/spec/v2.0.0.html) format.
* If the version is not supported, we won't apply instrumentation patch (see `enable` method).
* If omitted, all versions of the module will be patched.
*/
supportedVersions?: string[];
}

/**
Expand Down Expand Up @@ -96,14 +88,24 @@ export interface InstrumentationModuleFile {

moduleExports?: unknown;

/** Supported version this file */
/** Supported versions for the file.
*
* A module version is supported if one of the supportedVersions in the array satisfies the module version.
* The syntax of the version is checked with the `satisfies` function of "The semantic versioner for npm", see
* [`semver` package](https://www.npmjs.com/package/semver)
* If the version is not supported, we won't apply instrumentation patch.
* If omitted, all versions of the module will be patched.
*
* It is recommended to always specify a range that is bound to a major version, to avoid breaking changes.
* New major versions should be reviewed and tested before being added to the supportedVersions array.
*
* Example: ['>=1.2.3 <3']
*/
supportedVersions: string[];

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

/** Method to patch the instrumentation */

/** Method to unpatch the instrumentation */
unpatch(moduleExports?: unknown, moduleVersion?: string): void;
}
Expand All @@ -118,7 +120,19 @@ export interface InstrumentationModuleDefinition {
/** Instrumented module version */
moduleVersion?: string;

/** Supported version of module */
/** Supported version of module.
*
* A module version is supported if one of the supportedVersions in the array satisfies the module version.
* The syntax of the version is checked with the `satisfies` function of "The semantic versioner for npm", see
* [`semver` package](https://www.npmjs.com/package/semver)
* If the version is not supported, we won't apply instrumentation patch (see `enable` method).
* If omitted, all versions of the module will be patched.
*
* It is recommended to always specify a range that is bound to a major version, to avoid breaking changes.
* New major versions should be reviewed and tested before being added to the supportedVersions array.
*
* Example: ['>=1.2.3 <3']
*/
supportedVersions: string[];

/** Module internal files to be patched */
Expand Down
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"groupName": "all patch versions",
"groupSlug": "all-patch",
"matchUpdateTypes": ["patch"],
"excludePackageNames": ["prettier", "import-in-the-middle"],
"excludePackageNames": ["prettier"],
"schedule": ["before 3am every weekday"]
},
{
Expand Down

0 comments on commit e9fcfba

Please sign in to comment.