nestjs-otel 6.1.1 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +69 -0
- package/README.md +3 -4
- package/lib/feature-detection.utils.d.ts +24 -0
- package/lib/feature-detection.utils.js +59 -0
- package/lib/feature-detection.utils.spec.d.ts +1 -0
- package/lib/feature-detection.utils.spec.js +87 -0
- package/lib/metrics/decorators/common.d.ts +3 -1
- package/lib/metrics/injector.js +1 -2
- package/lib/metrics/metric-data.js +7 -7
- package/lib/metrics/utils.js +1 -2
- package/lib/middleware.utils.d.ts +2 -0
- package/lib/middleware.utils.js +23 -0
- package/lib/opentelemetry-core.module.d.ts +3 -1
- package/lib/opentelemetry-core.module.js +9 -4
- package/lib/tracing/decorators/span.js +1 -2
- package/package.json +32 -33
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Contributing Guide
|
|
2
|
+
|
|
3
|
+
We'd love your help!
|
|
4
|
+
|
|
5
|
+
- [Contributing Guide](#contributing-guide)
|
|
6
|
+
- [Development Quick Start](#development-quick-start)
|
|
7
|
+
- [Report a bug or requesting feature](#report-a-bug-or-requesting-feature)
|
|
8
|
+
- [How to contribute](#how-to-contribute)
|
|
9
|
+
- [Conventional commit](#conventional-commit)
|
|
10
|
+
- [Fork](#fork)
|
|
11
|
+
|
|
12
|
+
## Development Quick Start
|
|
13
|
+
|
|
14
|
+
To get the project started quickly, you can follow these steps. For more
|
|
15
|
+
detailed instructions, see [development](#development) below.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
git clone https://github.com/pragmaticivan/nestjs-otel.git
|
|
19
|
+
cd nestjs-otel
|
|
20
|
+
npm ci
|
|
21
|
+
npm run test
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Report a bug or requesting feature
|
|
25
|
+
|
|
26
|
+
Reporting bugs is an important contribution. Please make sure to include:
|
|
27
|
+
|
|
28
|
+
- expected and actual behavior.
|
|
29
|
+
- Node version that application is running.
|
|
30
|
+
- OpenTelemetry version that application is using.
|
|
31
|
+
- if possible - repro application and steps to reproduce.
|
|
32
|
+
|
|
33
|
+
## How to contribute
|
|
34
|
+
|
|
35
|
+
#### Conventional commit
|
|
36
|
+
|
|
37
|
+
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages. You can see examples [here](https://www.conventionalcommits.org/en/v1.0.0-beta.4/#examples).
|
|
38
|
+
We use [commitlint](https://github.com/conventional-changelog/commitlint) and [husky](https://github.com/typicode/husky) to prevent bad commit message.
|
|
39
|
+
For example, you want to submit the following commit message `git commit -s -am "my bad commit"`.
|
|
40
|
+
You will receive the following error :
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
✖ type must be one of [ci, feat, fix, docs, style, refactor, perf, test, revert, chore] [type-enum]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Here an example that will pass the verification: `git commit -s -am "chore(opentelemetry): update deps"`
|
|
47
|
+
|
|
48
|
+
### Fork
|
|
49
|
+
|
|
50
|
+
In the interest of keeping this repository clean and manageable, you should work from a fork. To create a fork, click the 'Fork' button at the top of the repository, then clone the fork locally using `git clone git@github.com:USERNAME/nestjs-otel.git`.
|
|
51
|
+
|
|
52
|
+
You should also add this repository as an "upstream" repo to your local copy, in order to keep it up to date. You can add this as a remote like so:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
git remote add upstream https://github.com/pragmaticivan/nestjs-otel.git
|
|
56
|
+
|
|
57
|
+
#verify that the upstream exists
|
|
58
|
+
git remote -v
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
To update your fork, fetch the upstream repo's branches and commits, then merge your main with upstream's main:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
git fetch upstream
|
|
65
|
+
git checkout main
|
|
66
|
+
git merge upstream/main
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Remember to always work in a branch of your local copy, as you might otherwise have to contend with conflicts in main.
|
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
</p>
|
|
1
|
+

|
|
2
|
+
|
|
4
3
|
|
|
5
4
|
# NestJS OpenTelemetry (OTEL)
|
|
6
5
|
|
|
@@ -186,7 +185,7 @@ export class BookService {
|
|
|
186
185
|
|
|
187
186
|
## Metric Service
|
|
188
187
|
|
|
189
|
-
[OpenTelemetry Metrics](https://www.npmjs.com/package/@opentelemetry/api
|
|
188
|
+
[OpenTelemetry Metrics](https://www.npmjs.com/package/@opentelemetry/api) allow a user to collect data and export it to metrics backend like Prometheus.
|
|
190
189
|
|
|
191
190
|
```ts
|
|
192
191
|
import { MetricService } from 'nestjs-otel';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HttpServer } from '@nestjs/common';
|
|
2
|
+
export declare enum ExpressVersion {
|
|
3
|
+
V4 = "4.x",
|
|
4
|
+
V5 = "5.x"
|
|
5
|
+
}
|
|
6
|
+
export declare enum FastifyVersion {
|
|
7
|
+
V4 = "4.x",
|
|
8
|
+
V5 = "5.x"
|
|
9
|
+
}
|
|
10
|
+
export declare enum HttpAdapterType {
|
|
11
|
+
EXPRESS = "express",
|
|
12
|
+
FASTIFY = "fastify"
|
|
13
|
+
}
|
|
14
|
+
type HttpExpresAdapterResponse = {
|
|
15
|
+
adapterType: HttpAdapterType.EXPRESS;
|
|
16
|
+
version: ExpressVersion;
|
|
17
|
+
};
|
|
18
|
+
type HttpFastifyAdapterResponse = {
|
|
19
|
+
adapterType: HttpAdapterType.FASTIFY;
|
|
20
|
+
version: FastifyVersion;
|
|
21
|
+
};
|
|
22
|
+
type HttpAdapterTypeAndVersion = HttpExpresAdapterResponse | HttpFastifyAdapterResponse;
|
|
23
|
+
export declare function detectHttpAdapterTypeAndVersion(httpAdapter: HttpServer): HttpAdapterTypeAndVersion;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpAdapterType = exports.FastifyVersion = exports.ExpressVersion = void 0;
|
|
4
|
+
exports.detectHttpAdapterTypeAndVersion = detectHttpAdapterTypeAndVersion;
|
|
5
|
+
var ExpressVersion;
|
|
6
|
+
(function (ExpressVersion) {
|
|
7
|
+
ExpressVersion["V4"] = "4.x";
|
|
8
|
+
ExpressVersion["V5"] = "5.x";
|
|
9
|
+
})(ExpressVersion || (exports.ExpressVersion = ExpressVersion = {}));
|
|
10
|
+
var FastifyVersion;
|
|
11
|
+
(function (FastifyVersion) {
|
|
12
|
+
FastifyVersion["V4"] = "4.x";
|
|
13
|
+
FastifyVersion["V5"] = "5.x";
|
|
14
|
+
})(FastifyVersion || (exports.FastifyVersion = FastifyVersion = {}));
|
|
15
|
+
var HttpAdapterType;
|
|
16
|
+
(function (HttpAdapterType) {
|
|
17
|
+
HttpAdapterType["EXPRESS"] = "express";
|
|
18
|
+
HttpAdapterType["FASTIFY"] = "fastify";
|
|
19
|
+
})(HttpAdapterType || (exports.HttpAdapterType = HttpAdapterType = {}));
|
|
20
|
+
function detectHttpAdapterTypeAndVersion(httpAdapter) {
|
|
21
|
+
const adapterType = detectHttpAdapterType(httpAdapter);
|
|
22
|
+
if (adapterType === HttpAdapterType.FASTIFY) {
|
|
23
|
+
return {
|
|
24
|
+
adapterType: HttpAdapterType.FASTIFY,
|
|
25
|
+
version: detectFastifyVersion(httpAdapter.getInstance()),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return {
|
|
30
|
+
adapterType: HttpAdapterType.EXPRESS,
|
|
31
|
+
version: detectExpressVersion(httpAdapter.getInstance()),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function detectHttpAdapterType(httpAdapter) {
|
|
36
|
+
if (httpAdapter.constructor.name === 'FastifyAdapter') {
|
|
37
|
+
return HttpAdapterType.FASTIFY;
|
|
38
|
+
}
|
|
39
|
+
return HttpAdapterType.EXPRESS;
|
|
40
|
+
}
|
|
41
|
+
function detectExpressVersion(expressApp) {
|
|
42
|
+
// feature detection based on https://expressjs.com/en/guide/migrating-5.html
|
|
43
|
+
if (
|
|
44
|
+
// app.del is removed in Express 5
|
|
45
|
+
typeof expressApp.del === 'undefined') {
|
|
46
|
+
return ExpressVersion.V5;
|
|
47
|
+
}
|
|
48
|
+
return ExpressVersion.V4;
|
|
49
|
+
}
|
|
50
|
+
function detectFastifyVersion(fastifyApp) {
|
|
51
|
+
// feature detection based on https://fastify.dev/docs/v5.1.x/Guides/Migration-Guide-V5/
|
|
52
|
+
if (
|
|
53
|
+
// these methods are removed in Fastify 5
|
|
54
|
+
typeof fastifyApp.getDefaultRoute === 'undefined' &&
|
|
55
|
+
typeof fastifyApp.setDefaultRoute === 'undefined') {
|
|
56
|
+
return FastifyVersion.V5;
|
|
57
|
+
}
|
|
58
|
+
return FastifyVersion.V4;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const feature_detection_utils_1 = require("./feature-detection.utils");
|
|
5
|
+
function useNest10() {
|
|
6
|
+
jest.mock('@nestjs/testing', () => jest.requireActual('@nestjs/testing10'));
|
|
7
|
+
jest.mock('@nestjs/common', () => jest.requireActual('@nestjs/common10'));
|
|
8
|
+
jest.mock('@nestjs/core', () => jest.requireActual('@nestjs/core10'));
|
|
9
|
+
jest.mock('@nestjs/platform-express', () => jest.requireActual('@nestjs/platform-express10'));
|
|
10
|
+
jest.mock('@nestjs/platform-fastify', () => jest.requireActual('@nestjs/platform-fastify10'));
|
|
11
|
+
}
|
|
12
|
+
function useNest11() {
|
|
13
|
+
jest.unmock('@nestjs/testing');
|
|
14
|
+
jest.unmock('@nestjs/common');
|
|
15
|
+
jest.unmock('@nestjs/core');
|
|
16
|
+
jest.unmock('@nestjs/platform-express');
|
|
17
|
+
jest.unmock('@nestjs/platform-fastify');
|
|
18
|
+
}
|
|
19
|
+
describe('FeatureDetectionUtils', () => {
|
|
20
|
+
describe('When using Express adapter', () => {
|
|
21
|
+
async function getExpressApp() {
|
|
22
|
+
const { Module } = await Promise.resolve().then(() => tslib_1.__importStar(require('@nestjs/common')));
|
|
23
|
+
const { Test } = await Promise.resolve().then(() => tslib_1.__importStar(require('@nestjs/testing')));
|
|
24
|
+
let TestModule = class TestModule {
|
|
25
|
+
};
|
|
26
|
+
TestModule = tslib_1.__decorate([
|
|
27
|
+
Module({})
|
|
28
|
+
], TestModule);
|
|
29
|
+
const module = await Test.createTestingModule({
|
|
30
|
+
imports: [TestModule],
|
|
31
|
+
}).compile();
|
|
32
|
+
return module.createNestApplication();
|
|
33
|
+
}
|
|
34
|
+
it('should detect Express version 4 on Nest 10', async () => {
|
|
35
|
+
useNest10();
|
|
36
|
+
const app = await getExpressApp();
|
|
37
|
+
const features = (0, feature_detection_utils_1.detectHttpAdapterTypeAndVersion)(app.getHttpAdapter());
|
|
38
|
+
expect(features).toEqual({
|
|
39
|
+
adapterType: feature_detection_utils_1.HttpAdapterType.EXPRESS,
|
|
40
|
+
version: feature_detection_utils_1.ExpressVersion.V4,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('should detect Express version 5 on Nest 11', async () => {
|
|
44
|
+
useNest11();
|
|
45
|
+
const app = await getExpressApp();
|
|
46
|
+
const features = (0, feature_detection_utils_1.detectHttpAdapterTypeAndVersion)(app.getHttpAdapter());
|
|
47
|
+
expect(features).toEqual({
|
|
48
|
+
adapterType: feature_detection_utils_1.HttpAdapterType.EXPRESS,
|
|
49
|
+
version: feature_detection_utils_1.ExpressVersion.V5,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('When using Fastify adapter', () => {
|
|
54
|
+
async function getFastifyApp() {
|
|
55
|
+
const { Module } = await Promise.resolve().then(() => tslib_1.__importStar(require('@nestjs/common')));
|
|
56
|
+
const { Test } = await Promise.resolve().then(() => tslib_1.__importStar(require('@nestjs/testing')));
|
|
57
|
+
const { FastifyAdapter } = await Promise.resolve().then(() => tslib_1.__importStar(require('@nestjs/platform-fastify')));
|
|
58
|
+
let TestModule = class TestModule {
|
|
59
|
+
};
|
|
60
|
+
TestModule = tslib_1.__decorate([
|
|
61
|
+
Module({})
|
|
62
|
+
], TestModule);
|
|
63
|
+
const module = await Test.createTestingModule({
|
|
64
|
+
imports: [TestModule],
|
|
65
|
+
}).compile();
|
|
66
|
+
return module.createNestApplication(new FastifyAdapter());
|
|
67
|
+
}
|
|
68
|
+
it('should detect Fastify version 4 on Nest 10', async () => {
|
|
69
|
+
useNest10();
|
|
70
|
+
const app = await getFastifyApp();
|
|
71
|
+
const features = (0, feature_detection_utils_1.detectHttpAdapterTypeAndVersion)(app.getHttpAdapter());
|
|
72
|
+
expect(features).toEqual({
|
|
73
|
+
adapterType: feature_detection_utils_1.HttpAdapterType.FASTIFY,
|
|
74
|
+
version: feature_detection_utils_1.FastifyVersion.V4,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it('should detect Fastify version 5 on Nest 11', async () => {
|
|
78
|
+
useNest11();
|
|
79
|
+
const app = await getFastifyApp();
|
|
80
|
+
const features = (0, feature_detection_utils_1.detectHttpAdapterTypeAndVersion)(app.getHttpAdapter());
|
|
81
|
+
expect(features).toEqual({
|
|
82
|
+
adapterType: feature_detection_utils_1.HttpAdapterType.FASTIFY,
|
|
83
|
+
version: feature_detection_utils_1.FastifyVersion.V5,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -4,7 +4,9 @@ import { OtelMetricOptions } from '../../interfaces/metric-options.interface';
|
|
|
4
4
|
*
|
|
5
5
|
* @param originalClass
|
|
6
6
|
*/
|
|
7
|
-
export declare const OtelInstanceCounter: (options?: OtelMetricOptions) => <T extends
|
|
7
|
+
export declare const OtelInstanceCounter: (options?: OtelMetricOptions) => <T extends {
|
|
8
|
+
new (...args: any[]): {};
|
|
9
|
+
}>(originalClass: T) => {
|
|
8
10
|
new (...args: any[]): {};
|
|
9
11
|
} & T;
|
|
10
12
|
/**
|
package/lib/metrics/injector.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InjectMetric =
|
|
3
|
+
exports.InjectMetric = InjectMetric;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
function InjectMetric(name) {
|
|
7
7
|
const token = (0, utils_1.getToken)(name);
|
|
8
8
|
return (0, common_1.Inject)(token);
|
|
9
9
|
}
|
|
10
|
-
exports.InjectMetric = InjectMetric;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.meterData = exports.MetricType = void 0;
|
|
4
|
+
exports.getOrCreateHistogram = getOrCreateHistogram;
|
|
5
|
+
exports.getOrCreateCounter = getOrCreateCounter;
|
|
6
|
+
exports.getOrCreateUpDownCounter = getOrCreateUpDownCounter;
|
|
7
|
+
exports.getOrCreateObservableGauge = getOrCreateObservableGauge;
|
|
8
|
+
exports.getOrCreateObservableCounter = getOrCreateObservableCounter;
|
|
9
|
+
exports.getOrCreateObservableUpDownCounter = getOrCreateObservableUpDownCounter;
|
|
4
10
|
const api_1 = require("@opentelemetry/api");
|
|
5
11
|
const opentelemetry_constants_1 = require("../opentelemetry.constants");
|
|
6
12
|
var MetricType;
|
|
@@ -26,24 +32,18 @@ function getOrCreate(name, options = {}, type) {
|
|
|
26
32
|
function getOrCreateHistogram(name, options = {}) {
|
|
27
33
|
return getOrCreate(name, options, MetricType.Histogram);
|
|
28
34
|
}
|
|
29
|
-
exports.getOrCreateHistogram = getOrCreateHistogram;
|
|
30
35
|
function getOrCreateCounter(name, options = {}) {
|
|
31
36
|
return getOrCreate(name, options, MetricType.Counter);
|
|
32
37
|
}
|
|
33
|
-
exports.getOrCreateCounter = getOrCreateCounter;
|
|
34
38
|
function getOrCreateUpDownCounter(name, options = {}) {
|
|
35
39
|
return getOrCreate(name, options, MetricType.UpDownCounter);
|
|
36
40
|
}
|
|
37
|
-
exports.getOrCreateUpDownCounter = getOrCreateUpDownCounter;
|
|
38
41
|
function getOrCreateObservableGauge(name, options = {}) {
|
|
39
42
|
return getOrCreate(name, options, MetricType.ObservableGauge);
|
|
40
43
|
}
|
|
41
|
-
exports.getOrCreateObservableGauge = getOrCreateObservableGauge;
|
|
42
44
|
function getOrCreateObservableCounter(name, options = {}) {
|
|
43
45
|
return getOrCreate(name, options, MetricType.ObservableCounter);
|
|
44
46
|
}
|
|
45
|
-
exports.getOrCreateObservableCounter = getOrCreateObservableCounter;
|
|
46
47
|
function getOrCreateObservableUpDownCounter(name, options = {}) {
|
|
47
48
|
return getOrCreate(name, options, MetricType.ObservableUpDownCounter);
|
|
48
49
|
}
|
|
49
|
-
exports.getOrCreateObservableUpDownCounter = getOrCreateObservableUpDownCounter;
|
package/lib/metrics/utils.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getToken =
|
|
3
|
+
exports.getToken = getToken;
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
7
|
function getToken(name) {
|
|
8
8
|
return `OTEL_METRIC_${name.toUpperCase()}`;
|
|
9
9
|
}
|
|
10
|
-
exports.getToken = getToken;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMiddlewareMountPoint = getMiddlewareMountPoint;
|
|
4
|
+
const feature_detection_utils_1 = require("./feature-detection.utils");
|
|
5
|
+
const MOUNT_POINT_EXPRESS_5 = '/';
|
|
6
|
+
const MOUNT_POINT_EXPRESS_4 = '*';
|
|
7
|
+
const MOUNT_POINT_FASTIFY_5 = '{*path}';
|
|
8
|
+
const MOUNT_POINT_FASTIFY_4 = '(.*)';
|
|
9
|
+
function getMiddlewareMountPoint(adapter) {
|
|
10
|
+
const features = (0, feature_detection_utils_1.detectHttpAdapterTypeAndVersion)(adapter);
|
|
11
|
+
if (features.adapterType === feature_detection_utils_1.HttpAdapterType.FASTIFY) {
|
|
12
|
+
if (features.version === feature_detection_utils_1.FastifyVersion.V5) {
|
|
13
|
+
return MOUNT_POINT_FASTIFY_5;
|
|
14
|
+
}
|
|
15
|
+
return MOUNT_POINT_FASTIFY_4;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (features.version === feature_detection_utils_1.ExpressVersion.V5) {
|
|
19
|
+
return MOUNT_POINT_EXPRESS_5;
|
|
20
|
+
}
|
|
21
|
+
return MOUNT_POINT_EXPRESS_4;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DynamicModule, MiddlewareConsumer, OnApplicationBootstrap } from '@nestjs/common';
|
|
2
2
|
import { OpenTelemetryModuleAsyncOptions, OpenTelemetryModuleOptions } from './interfaces';
|
|
3
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
4
|
/**
|
|
4
5
|
* The internal OpenTelemetry Module which handles the integration
|
|
5
6
|
* with the third party OpenTelemetry library and Nest
|
|
@@ -8,8 +9,9 @@ import { OpenTelemetryModuleAsyncOptions, OpenTelemetryModuleOptions } from './i
|
|
|
8
9
|
*/
|
|
9
10
|
export declare class OpenTelemetryCoreModule implements OnApplicationBootstrap {
|
|
10
11
|
private readonly options;
|
|
12
|
+
private readonly adapterHost;
|
|
11
13
|
private readonly logger;
|
|
12
|
-
constructor(options
|
|
14
|
+
constructor(options: OpenTelemetryModuleOptions | undefined, adapterHost: HttpAdapterHost);
|
|
13
15
|
/**
|
|
14
16
|
* Bootstraps the internal OpenTelemetry Module with the given options
|
|
15
17
|
* synchronously and sets the correct providers
|
|
@@ -10,6 +10,8 @@ const metric_service_1 = require("./metrics/metric.service");
|
|
|
10
10
|
const middleware_1 = require("./middleware");
|
|
11
11
|
const opentelemetry_constants_1 = require("./opentelemetry.constants");
|
|
12
12
|
const trace_service_1 = require("./tracing/trace.service");
|
|
13
|
+
const core_1 = require("@nestjs/core");
|
|
14
|
+
const middleware_utils_1 = require("./middleware.utils");
|
|
13
15
|
/**
|
|
14
16
|
* The internal OpenTelemetry Module which handles the integration
|
|
15
17
|
* with the third party OpenTelemetry library and Nest
|
|
@@ -17,8 +19,9 @@ const trace_service_1 = require("./tracing/trace.service");
|
|
|
17
19
|
* @internal
|
|
18
20
|
*/
|
|
19
21
|
let OpenTelemetryCoreModule = OpenTelemetryCoreModule_1 = class OpenTelemetryCoreModule {
|
|
20
|
-
constructor(options = {}) {
|
|
22
|
+
constructor(options = {}, adapterHost) {
|
|
21
23
|
this.options = options;
|
|
24
|
+
this.adapterHost = adapterHost;
|
|
22
25
|
this.logger = new common_1.Logger('OpenTelemetryModule');
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
@@ -54,14 +57,16 @@ let OpenTelemetryCoreModule = OpenTelemetryCoreModule_1 = class OpenTelemetryCor
|
|
|
54
57
|
configure(consumer) {
|
|
55
58
|
const { apiMetrics = { enable: false } } = this.options?.metrics ?? {};
|
|
56
59
|
if (apiMetrics.enable === true) {
|
|
60
|
+
const adapter = this.adapterHost.httpAdapter;
|
|
61
|
+
const mountPoint = (0, middleware_utils_1.getMiddlewareMountPoint)(adapter);
|
|
57
62
|
if (apiMetrics?.ignoreRoutes && apiMetrics?.ignoreRoutes.length > 0) {
|
|
58
63
|
consumer
|
|
59
64
|
.apply(middleware_1.ApiMetricsMiddleware)
|
|
60
65
|
.exclude(...apiMetrics.ignoreRoutes)
|
|
61
|
-
.forRoutes(
|
|
66
|
+
.forRoutes(mountPoint);
|
|
62
67
|
}
|
|
63
68
|
else {
|
|
64
|
-
consumer.apply(middleware_1.ApiMetricsMiddleware).forRoutes(
|
|
69
|
+
consumer.apply(middleware_1.ApiMetricsMiddleware).forRoutes(mountPoint);
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
}
|
|
@@ -126,5 +131,5 @@ exports.OpenTelemetryCoreModule = OpenTelemetryCoreModule = OpenTelemetryCoreMod
|
|
|
126
131
|
(0, common_1.Global)(),
|
|
127
132
|
(0, common_1.Module)({}),
|
|
128
133
|
tslib_1.__param(0, (0, common_1.Inject)(opentelemetry_constants_1.OPENTELEMETRY_MODULE_OPTIONS)),
|
|
129
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
134
|
+
tslib_1.__metadata("design:paramtypes", [Object, core_1.HttpAdapterHost])
|
|
130
135
|
], OpenTelemetryCoreModule);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Span =
|
|
3
|
+
exports.Span = Span;
|
|
4
4
|
const api_1 = require("@opentelemetry/api");
|
|
5
5
|
const opentelemetry_utils_1 = require("../../opentelemetry.utils");
|
|
6
6
|
const recordException = (span, error) => {
|
|
@@ -46,4 +46,3 @@ function Span(name, options = {}) {
|
|
|
46
46
|
(0, opentelemetry_utils_1.copyMetadataFromFunctionToFunction)(originalFunction, wrappedFunction);
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
exports.Span = Span;
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-otel",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "NestJS OpenTelemetry Library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"prebuild": "rimraf lib",
|
|
9
|
-
"prepare": "husky install",
|
|
10
9
|
"build": "tsc",
|
|
11
10
|
"lint": "prettier --check ./**/*.{js,json,ts}",
|
|
12
11
|
"format": "prettier --write ./**/*.{js,json,ts}",
|
|
@@ -15,7 +14,8 @@
|
|
|
15
14
|
"test:unit": "jest --passWithNoTests",
|
|
16
15
|
"test:watch": "jest --watch",
|
|
17
16
|
"test:e2e": "jest --config ./tests/jest-e2e.json --runInBand --forceExit",
|
|
18
|
-
"test:e2e:watch": "jest --config ./tests/jest-e2e.json --runInBand --watch"
|
|
17
|
+
"test:e2e:watch": "jest --config ./tests/jest-e2e.json --runInBand --watch",
|
|
18
|
+
"prepare": "husky"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
@@ -36,40 +36,44 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/pragmaticivan/nestjs-otel#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@opentelemetry/api": "^1.
|
|
40
|
-
"@opentelemetry/host-metrics": "^0.35.
|
|
41
|
-
"response-time": "^2.3.
|
|
39
|
+
"@opentelemetry/api": "^1.9.0",
|
|
40
|
+
"@opentelemetry/host-metrics": "^0.35.5",
|
|
41
|
+
"response-time": "^2.3.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^19.
|
|
45
|
-
"@commitlint/config-conventional": "^19.
|
|
46
|
-
"@nestjs/common": "^
|
|
47
|
-
"@nestjs/
|
|
48
|
-
"@nestjs/
|
|
49
|
-
"@nestjs/
|
|
50
|
-
"@nestjs/
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
44
|
+
"@commitlint/cli": "^19.7.1",
|
|
45
|
+
"@commitlint/config-conventional": "^19.7.1",
|
|
46
|
+
"@nestjs/common": "^11.0.11",
|
|
47
|
+
"@nestjs/common10": "npm:@nestjs/common@10",
|
|
48
|
+
"@nestjs/core": "^11.0.11",
|
|
49
|
+
"@nestjs/core10": "npm:@nestjs/core@10",
|
|
50
|
+
"@nestjs/platform-express": "^11.0.11",
|
|
51
|
+
"@nestjs/platform-express10": "npm:@nestjs/platform-express@10",
|
|
52
|
+
"@nestjs/platform-fastify": "^11.0.11",
|
|
53
|
+
"@nestjs/platform-fastify10": "npm:@nestjs/platform-fastify@10",
|
|
54
|
+
"@nestjs/testing": "^11.0.11",
|
|
55
|
+
"@nestjs/testing10": "npm:@nestjs/testing@10",
|
|
56
|
+
"@opentelemetry/exporter-prometheus": "^0.57.2",
|
|
57
|
+
"@opentelemetry/sdk-metrics": "^1.30.1",
|
|
58
|
+
"@opentelemetry/sdk-trace-node": "^1.30.1",
|
|
59
|
+
"@types/jest": "^29.5.14",
|
|
60
|
+
"@types/node": "^22.13.8",
|
|
56
61
|
"@types/response-time": "^2.3.8",
|
|
57
62
|
"@types/supertest": "^6.0.2",
|
|
58
|
-
"
|
|
59
|
-
"husky": "^9.0.11",
|
|
63
|
+
"husky": "^9.1.7",
|
|
60
64
|
"jest": "^29.7.0",
|
|
61
|
-
"lint-staged": "^15.
|
|
62
|
-
"prettier": "^3.2
|
|
65
|
+
"lint-staged": "^15.4.3",
|
|
66
|
+
"prettier": "^3.5.2",
|
|
63
67
|
"reflect-metadata": "^0.2.2",
|
|
64
|
-
"rimraf": "^
|
|
65
|
-
"rxjs": "^7.8.
|
|
68
|
+
"rimraf": "^6.0.1",
|
|
69
|
+
"rxjs": "^7.8.2",
|
|
66
70
|
"supertest": "^7.0.0",
|
|
67
|
-
"ts-jest": "^29.
|
|
68
|
-
"typescript": "5.
|
|
71
|
+
"ts-jest": "^29.2.6",
|
|
72
|
+
"typescript": "5.8.2"
|
|
69
73
|
},
|
|
70
74
|
"peerDependencies": {
|
|
71
|
-
"@nestjs/common": "
|
|
72
|
-
"@nestjs/core": "
|
|
75
|
+
"@nestjs/common": ">= 10 < 12",
|
|
76
|
+
"@nestjs/core": ">= 10 < 12"
|
|
73
77
|
},
|
|
74
78
|
"jest": {
|
|
75
79
|
"moduleFileExtensions": [
|
|
@@ -93,10 +97,5 @@
|
|
|
93
97
|
"**/*.{js,ts,json}": [
|
|
94
98
|
"prettier --write"
|
|
95
99
|
]
|
|
96
|
-
},
|
|
97
|
-
"commitlint": {
|
|
98
|
-
"extends": [
|
|
99
|
-
"@commitlint/config-conventional"
|
|
100
|
-
]
|
|
101
100
|
}
|
|
102
101
|
}
|