@commercetools/ts-sdk-apm 3.3.1 → 4.0.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/CHANGELOG.md +13 -0
- package/dist/commercetools-ts-sdk-apm.browser.cjs.js +36 -65
- package/dist/commercetools-ts-sdk-apm.browser.esm.js +36 -64
- package/dist/commercetools-ts-sdk-apm.cjs.dev.js +36 -65
- package/dist/commercetools-ts-sdk-apm.cjs.prod.js +36 -65
- package/dist/commercetools-ts-sdk-apm.esm.js +36 -64
- package/dist/declarations/src/apm.d.ts.map +1 -1
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/declarations/types/types.d.ts +0 -47
- package/dist/{newRelicHelper-b7df4fbe.esm.js → newRelicHelper-0e64cc35.browser.esm.js} +1 -1
- package/dist/{newRelicHelper-ed9e1fad.browser.esm.js → newRelicHelper-86b0a261.esm.js} +1 -1
- package/dist/{newRelicHelper-7e5ab5ea.browser.cjs.js → newRelicHelper-a1299333.cjs.prod.js} +1 -1
- package/dist/{newRelicHelper-2ce5bdaf.cjs.prod.js → newRelicHelper-da9e4a44.cjs.dev.js} +1 -1
- package/dist/{newRelicHelper-76fc4f4a.cjs.dev.js → newRelicHelper-f0d942b0.browser.cjs.js} +1 -1
- package/dist/opentelemetry-8a97600d.esm.js +86 -0
- package/dist/opentelemetry-a1ac8980.browser.cjs.js +88 -0
- package/dist/opentelemetry-a32b3e9d.cjs.prod.js +79 -0
- package/dist/opentelemetry-b1e59a80.browser.esm.js +86 -0
- package/dist/opentelemetry-f4763b74.cjs.dev.js +88 -0
- package/package.json +4 -4
- package/dist/declarations/src/apm-legacy.d.ts +0 -8
- package/dist/declarations/src/apm-legacy.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @commercetools/ts-sdk-apm
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#1044](https://github.com/commercetools/commercetools-sdk-typescript/pull/1044) [`29967a3`](https://github.com/commercetools/commercetools-sdk-typescript/commit/29967a3e5957bd2fc35d90ad95d8e8f2917565e4) Thanks [@ajimae](https://github.com/ajimae)! - - fix issue with missing module
|
|
8
|
+
- remove deprecated and legacy apm modules
|
|
9
|
+
|
|
10
|
+
## 3.3.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#1002](https://github.com/commercetools/commercetools-sdk-typescript/pull/1002) [`6a842db`](https://github.com/commercetools/commercetools-sdk-typescript/commit/6a842db96c51a9ac9bf53b19050acfff961a5fa4) Thanks [@ajimae](https://github.com/ajimae)! - fix issue with tracer functions not being called
|
|
15
|
+
|
|
3
16
|
## 3.3.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -13,74 +13,27 @@ datadog__default["default"].init();
|
|
|
13
13
|
|
|
14
14
|
// Record metrics for datadog
|
|
15
15
|
const recordDatadog = (metric, tags) => {
|
|
16
|
-
datadog__default["default"].dogstatsd.gauge(`
|
|
16
|
+
datadog__default["default"].dogstatsd.gauge(`client_response_time`, metric, tags);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const time = () => performance.now();
|
|
20
20
|
|
|
21
|
-
function createTelemetryMiddleware
|
|
22
|
-
// trace
|
|
23
|
-
function trace() {
|
|
24
|
-
// validate apm and tracer
|
|
25
|
-
if (!(options?.apm && typeof options.apm == 'function')) {
|
|
26
|
-
options.apm = () => {};
|
|
27
|
-
}
|
|
28
|
-
if (!(options?.tracer && typeof options.tracer == 'function')) {
|
|
29
|
-
options.tracer = () => {};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
trace(); // expose tracing modules
|
|
33
|
-
|
|
34
|
-
return next => async request => {
|
|
35
|
-
// get start (high resolution milliseconds) timestamp
|
|
36
|
-
const start = time();
|
|
37
|
-
const nextRequest = {
|
|
38
|
-
...request,
|
|
39
|
-
...options
|
|
40
|
-
};
|
|
41
|
-
const response = await next(nextRequest);
|
|
42
|
-
const response_time = time() - start;
|
|
43
|
-
|
|
44
|
-
// send `response_time` to APM platforms
|
|
45
|
-
if (options?.customMetrics) {
|
|
46
|
-
if (options.customMetrics.datadog) {
|
|
47
|
-
recordDatadog(response_time, {
|
|
48
|
-
env: process.env.NODE_ENV || 'dev'
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (options.customMetrics.newrelic) {
|
|
52
|
-
// Lazy load New Relic only if necessary otherwise it will require to have set the env variable NEW_RELIC_APP_NAME
|
|
53
|
-
const {
|
|
54
|
-
recordNewRelic
|
|
55
|
-
} = await Promise.resolve().then(function () { return require('./newRelicHelper-7e5ab5ea.browser.cjs.js'); });
|
|
56
|
-
recordNewRelic(response_time);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return response;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* default newrelic APM and
|
|
65
|
-
* opentelemetry tracer modules
|
|
66
|
-
*/
|
|
67
|
-
const defaultOptions = {
|
|
21
|
+
function createTelemetryMiddleware(options) {
|
|
68
22
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
72
|
-
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
23
|
+
* default newrelic APM and
|
|
24
|
+
* opentelemetry tracer modules
|
|
73
25
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
const defaultOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* if this is to be used with newrelic, then
|
|
29
|
+
* pass this (apm) as an option in the `createTelemetryMiddleware`
|
|
30
|
+
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
31
|
+
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
32
|
+
*/
|
|
33
|
+
apm: () => {},
|
|
34
|
+
tracer: () => Promise.resolve().then(function () { return require('./opentelemetry-a1ac8980.browser.cjs.js'); })
|
|
35
|
+
};
|
|
77
36
|
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated use new `createTelemetryMiddleware`
|
|
80
|
-
* @param options
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
function createTelemetryMiddleware(options) {
|
|
84
37
|
// trace
|
|
85
38
|
function trace() {
|
|
86
39
|
// validate apm and tracer
|
|
@@ -94,14 +47,32 @@ function createTelemetryMiddleware(options) {
|
|
|
94
47
|
options.tracer();
|
|
95
48
|
}
|
|
96
49
|
trace(); // expose tracing modules
|
|
97
|
-
return next =>
|
|
50
|
+
return next => async request => {
|
|
98
51
|
const nextRequest = {
|
|
99
52
|
...request,
|
|
100
53
|
...options
|
|
101
54
|
};
|
|
102
|
-
|
|
55
|
+
|
|
56
|
+
// start (high resolution milliseconds) timestamp
|
|
57
|
+
const start = time();
|
|
58
|
+
const response = await next(nextRequest);
|
|
59
|
+
const response_time = time() - start;
|
|
60
|
+
|
|
61
|
+
// send `response_time` to APM platforms
|
|
62
|
+
if (options?.customMetrics && options.customMetrics.datadog) {
|
|
63
|
+
recordDatadog(response_time, {
|
|
64
|
+
env: process.env.NODE_ENV || 'dev'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (options?.customMetrics && options.customMetrics.newrelic) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
const {
|
|
70
|
+
recordNewRelic
|
|
71
|
+
} = await Promise.resolve().then(function () { return require('./newRelicHelper-f0d942b0.browser.cjs.js'); });
|
|
72
|
+
recordNewRelic(response_time);
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
103
75
|
};
|
|
104
76
|
}
|
|
105
77
|
|
|
106
|
-
exports.createTelemetryMiddleware = createTelemetryMiddleware
|
|
107
|
-
exports.createTelemetryMiddlewareLegacy = createTelemetryMiddleware;
|
|
78
|
+
exports.createTelemetryMiddleware = createTelemetryMiddleware;
|
|
@@ -5,74 +5,27 @@ datadog.init();
|
|
|
5
5
|
|
|
6
6
|
// Record metrics for datadog
|
|
7
7
|
const recordDatadog = (metric, tags) => {
|
|
8
|
-
datadog.dogstatsd.gauge(`
|
|
8
|
+
datadog.dogstatsd.gauge(`client_response_time`, metric, tags);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const time = () => performance.now();
|
|
12
12
|
|
|
13
|
-
function createTelemetryMiddleware
|
|
14
|
-
// trace
|
|
15
|
-
function trace() {
|
|
16
|
-
// validate apm and tracer
|
|
17
|
-
if (!(options?.apm && typeof options.apm == 'function')) {
|
|
18
|
-
options.apm = () => {};
|
|
19
|
-
}
|
|
20
|
-
if (!(options?.tracer && typeof options.tracer == 'function')) {
|
|
21
|
-
options.tracer = () => {};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
trace(); // expose tracing modules
|
|
25
|
-
|
|
26
|
-
return next => async request => {
|
|
27
|
-
// get start (high resolution milliseconds) timestamp
|
|
28
|
-
const start = time();
|
|
29
|
-
const nextRequest = {
|
|
30
|
-
...request,
|
|
31
|
-
...options
|
|
32
|
-
};
|
|
33
|
-
const response = await next(nextRequest);
|
|
34
|
-
const response_time = time() - start;
|
|
35
|
-
|
|
36
|
-
// send `response_time` to APM platforms
|
|
37
|
-
if (options?.customMetrics) {
|
|
38
|
-
if (options.customMetrics.datadog) {
|
|
39
|
-
recordDatadog(response_time, {
|
|
40
|
-
env: process.env.NODE_ENV || 'dev'
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (options.customMetrics.newrelic) {
|
|
44
|
-
// Lazy load New Relic only if necessary otherwise it will require to have set the env variable NEW_RELIC_APP_NAME
|
|
45
|
-
const {
|
|
46
|
-
recordNewRelic
|
|
47
|
-
} = await import('./newRelicHelper-ed9e1fad.browser.esm.js');
|
|
48
|
-
recordNewRelic(response_time);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return response;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* default newrelic APM and
|
|
57
|
-
* opentelemetry tracer modules
|
|
58
|
-
*/
|
|
59
|
-
const defaultOptions = {
|
|
13
|
+
function createTelemetryMiddleware(options) {
|
|
60
14
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
64
|
-
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
15
|
+
* default newrelic APM and
|
|
16
|
+
* opentelemetry tracer modules
|
|
65
17
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
18
|
+
const defaultOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* if this is to be used with newrelic, then
|
|
21
|
+
* pass this (apm) as an option in the `createTelemetryMiddleware`
|
|
22
|
+
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
23
|
+
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
24
|
+
*/
|
|
25
|
+
apm: () => {},
|
|
26
|
+
tracer: () => import('./opentelemetry-b1e59a80.browser.esm.js')
|
|
27
|
+
};
|
|
69
28
|
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated use new `createTelemetryMiddleware`
|
|
72
|
-
* @param options
|
|
73
|
-
* @returns
|
|
74
|
-
*/
|
|
75
|
-
function createTelemetryMiddleware(options) {
|
|
76
29
|
// trace
|
|
77
30
|
function trace() {
|
|
78
31
|
// validate apm and tracer
|
|
@@ -86,13 +39,32 @@ function createTelemetryMiddleware(options) {
|
|
|
86
39
|
options.tracer();
|
|
87
40
|
}
|
|
88
41
|
trace(); // expose tracing modules
|
|
89
|
-
return next =>
|
|
42
|
+
return next => async request => {
|
|
90
43
|
const nextRequest = {
|
|
91
44
|
...request,
|
|
92
45
|
...options
|
|
93
46
|
};
|
|
94
|
-
|
|
47
|
+
|
|
48
|
+
// start (high resolution milliseconds) timestamp
|
|
49
|
+
const start = time();
|
|
50
|
+
const response = await next(nextRequest);
|
|
51
|
+
const response_time = time() - start;
|
|
52
|
+
|
|
53
|
+
// send `response_time` to APM platforms
|
|
54
|
+
if (options?.customMetrics && options.customMetrics.datadog) {
|
|
55
|
+
recordDatadog(response_time, {
|
|
56
|
+
env: process.env.NODE_ENV || 'dev'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (options?.customMetrics && options.customMetrics.newrelic) {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const {
|
|
62
|
+
recordNewRelic
|
|
63
|
+
} = await import('./newRelicHelper-0e64cc35.browser.esm.js');
|
|
64
|
+
recordNewRelic(response_time);
|
|
65
|
+
}
|
|
66
|
+
return response;
|
|
95
67
|
};
|
|
96
68
|
}
|
|
97
69
|
|
|
98
|
-
export { createTelemetryMiddleware
|
|
70
|
+
export { createTelemetryMiddleware };
|
|
@@ -13,74 +13,27 @@ datadog__default["default"].init();
|
|
|
13
13
|
|
|
14
14
|
// Record metrics for datadog
|
|
15
15
|
const recordDatadog = (metric, tags) => {
|
|
16
|
-
datadog__default["default"].dogstatsd.gauge(`
|
|
16
|
+
datadog__default["default"].dogstatsd.gauge(`client_response_time`, metric, tags);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const time = () => performance.now();
|
|
20
20
|
|
|
21
|
-
function createTelemetryMiddleware
|
|
22
|
-
// trace
|
|
23
|
-
function trace() {
|
|
24
|
-
// validate apm and tracer
|
|
25
|
-
if (!(options?.apm && typeof options.apm == 'function')) {
|
|
26
|
-
options.apm = () => {};
|
|
27
|
-
}
|
|
28
|
-
if (!(options?.tracer && typeof options.tracer == 'function')) {
|
|
29
|
-
options.tracer = () => {};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
trace(); // expose tracing modules
|
|
33
|
-
|
|
34
|
-
return next => async request => {
|
|
35
|
-
// get start (high resolution milliseconds) timestamp
|
|
36
|
-
const start = time();
|
|
37
|
-
const nextRequest = {
|
|
38
|
-
...request,
|
|
39
|
-
...options
|
|
40
|
-
};
|
|
41
|
-
const response = await next(nextRequest);
|
|
42
|
-
const response_time = time() - start;
|
|
43
|
-
|
|
44
|
-
// send `response_time` to APM platforms
|
|
45
|
-
if (options?.customMetrics) {
|
|
46
|
-
if (options.customMetrics.datadog) {
|
|
47
|
-
recordDatadog(response_time, {
|
|
48
|
-
env: process.env.NODE_ENV || 'dev'
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (options.customMetrics.newrelic) {
|
|
52
|
-
// Lazy load New Relic only if necessary otherwise it will require to have set the env variable NEW_RELIC_APP_NAME
|
|
53
|
-
const {
|
|
54
|
-
recordNewRelic
|
|
55
|
-
} = await Promise.resolve().then(function () { return require('./newRelicHelper-76fc4f4a.cjs.dev.js'); });
|
|
56
|
-
recordNewRelic(response_time);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return response;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* default newrelic APM and
|
|
65
|
-
* opentelemetry tracer modules
|
|
66
|
-
*/
|
|
67
|
-
const defaultOptions = {
|
|
21
|
+
function createTelemetryMiddleware(options) {
|
|
68
22
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
72
|
-
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
23
|
+
* default newrelic APM and
|
|
24
|
+
* opentelemetry tracer modules
|
|
73
25
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
const defaultOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* if this is to be used with newrelic, then
|
|
29
|
+
* pass this (apm) as an option in the `createTelemetryMiddleware`
|
|
30
|
+
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
31
|
+
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
32
|
+
*/
|
|
33
|
+
apm: () => {},
|
|
34
|
+
tracer: () => Promise.resolve().then(function () { return require('./opentelemetry-f4763b74.cjs.dev.js'); })
|
|
35
|
+
};
|
|
77
36
|
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated use new `createTelemetryMiddleware`
|
|
80
|
-
* @param options
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
function createTelemetryMiddleware(options) {
|
|
84
37
|
// trace
|
|
85
38
|
function trace() {
|
|
86
39
|
// validate apm and tracer
|
|
@@ -94,14 +47,32 @@ function createTelemetryMiddleware(options) {
|
|
|
94
47
|
options.tracer();
|
|
95
48
|
}
|
|
96
49
|
trace(); // expose tracing modules
|
|
97
|
-
return next =>
|
|
50
|
+
return next => async request => {
|
|
98
51
|
const nextRequest = {
|
|
99
52
|
...request,
|
|
100
53
|
...options
|
|
101
54
|
};
|
|
102
|
-
|
|
55
|
+
|
|
56
|
+
// start (high resolution milliseconds) timestamp
|
|
57
|
+
const start = time();
|
|
58
|
+
const response = await next(nextRequest);
|
|
59
|
+
const response_time = time() - start;
|
|
60
|
+
|
|
61
|
+
// send `response_time` to APM platforms
|
|
62
|
+
if (options?.customMetrics && options.customMetrics.datadog) {
|
|
63
|
+
recordDatadog(response_time, {
|
|
64
|
+
env: process.env.NODE_ENV || 'dev'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (options?.customMetrics && options.customMetrics.newrelic) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
const {
|
|
70
|
+
recordNewRelic
|
|
71
|
+
} = await Promise.resolve().then(function () { return require('./newRelicHelper-da9e4a44.cjs.dev.js'); });
|
|
72
|
+
recordNewRelic(response_time);
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
103
75
|
};
|
|
104
76
|
}
|
|
105
77
|
|
|
106
|
-
exports.createTelemetryMiddleware = createTelemetryMiddleware
|
|
107
|
-
exports.createTelemetryMiddlewareLegacy = createTelemetryMiddleware;
|
|
78
|
+
exports.createTelemetryMiddleware = createTelemetryMiddleware;
|
|
@@ -13,74 +13,27 @@ datadog__default["default"].init();
|
|
|
13
13
|
|
|
14
14
|
// Record metrics for datadog
|
|
15
15
|
const recordDatadog = (metric, tags) => {
|
|
16
|
-
datadog__default["default"].dogstatsd.gauge(`
|
|
16
|
+
datadog__default["default"].dogstatsd.gauge(`client_response_time`, metric, tags);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const time = () => performance.now();
|
|
20
20
|
|
|
21
|
-
function createTelemetryMiddleware
|
|
22
|
-
// trace
|
|
23
|
-
function trace() {
|
|
24
|
-
// validate apm and tracer
|
|
25
|
-
if (!(options?.apm && typeof options.apm == 'function')) {
|
|
26
|
-
options.apm = () => {};
|
|
27
|
-
}
|
|
28
|
-
if (!(options?.tracer && typeof options.tracer == 'function')) {
|
|
29
|
-
options.tracer = () => {};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
trace(); // expose tracing modules
|
|
33
|
-
|
|
34
|
-
return next => async request => {
|
|
35
|
-
// get start (high resolution milliseconds) timestamp
|
|
36
|
-
const start = time();
|
|
37
|
-
const nextRequest = {
|
|
38
|
-
...request,
|
|
39
|
-
...options
|
|
40
|
-
};
|
|
41
|
-
const response = await next(nextRequest);
|
|
42
|
-
const response_time = time() - start;
|
|
43
|
-
|
|
44
|
-
// send `response_time` to APM platforms
|
|
45
|
-
if (options?.customMetrics) {
|
|
46
|
-
if (options.customMetrics.datadog) {
|
|
47
|
-
recordDatadog(response_time, {
|
|
48
|
-
env: "production"
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (options.customMetrics.newrelic) {
|
|
52
|
-
// Lazy load New Relic only if necessary otherwise it will require to have set the env variable NEW_RELIC_APP_NAME
|
|
53
|
-
const {
|
|
54
|
-
recordNewRelic
|
|
55
|
-
} = await Promise.resolve().then(function () { return require('./newRelicHelper-2ce5bdaf.cjs.prod.js'); });
|
|
56
|
-
recordNewRelic(response_time);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return response;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* default newrelic APM and
|
|
65
|
-
* opentelemetry tracer modules
|
|
66
|
-
*/
|
|
67
|
-
const defaultOptions = {
|
|
21
|
+
function createTelemetryMiddleware(options) {
|
|
68
22
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
72
|
-
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
23
|
+
* default newrelic APM and
|
|
24
|
+
* opentelemetry tracer modules
|
|
73
25
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
const defaultOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* if this is to be used with newrelic, then
|
|
29
|
+
* pass this (apm) as an option in the `createTelemetryMiddleware`
|
|
30
|
+
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
31
|
+
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
32
|
+
*/
|
|
33
|
+
apm: () => {},
|
|
34
|
+
tracer: () => Promise.resolve().then(function () { return require('./opentelemetry-a32b3e9d.cjs.prod.js'); })
|
|
35
|
+
};
|
|
77
36
|
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated use new `createTelemetryMiddleware`
|
|
80
|
-
* @param options
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
function createTelemetryMiddleware(options) {
|
|
84
37
|
// trace
|
|
85
38
|
function trace() {
|
|
86
39
|
// validate apm and tracer
|
|
@@ -94,14 +47,32 @@ function createTelemetryMiddleware(options) {
|
|
|
94
47
|
options.tracer();
|
|
95
48
|
}
|
|
96
49
|
trace(); // expose tracing modules
|
|
97
|
-
return next =>
|
|
50
|
+
return next => async request => {
|
|
98
51
|
const nextRequest = {
|
|
99
52
|
...request,
|
|
100
53
|
...options
|
|
101
54
|
};
|
|
102
|
-
|
|
55
|
+
|
|
56
|
+
// start (high resolution milliseconds) timestamp
|
|
57
|
+
const start = time();
|
|
58
|
+
const response = await next(nextRequest);
|
|
59
|
+
const response_time = time() - start;
|
|
60
|
+
|
|
61
|
+
// send `response_time` to APM platforms
|
|
62
|
+
if (options?.customMetrics && options.customMetrics.datadog) {
|
|
63
|
+
recordDatadog(response_time, {
|
|
64
|
+
env: "production"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (options?.customMetrics && options.customMetrics.newrelic) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
const {
|
|
70
|
+
recordNewRelic
|
|
71
|
+
} = await Promise.resolve().then(function () { return require('./newRelicHelper-a1299333.cjs.prod.js'); });
|
|
72
|
+
recordNewRelic(response_time);
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
103
75
|
};
|
|
104
76
|
}
|
|
105
77
|
|
|
106
|
-
exports.createTelemetryMiddleware = createTelemetryMiddleware
|
|
107
|
-
exports.createTelemetryMiddlewareLegacy = createTelemetryMiddleware;
|
|
78
|
+
exports.createTelemetryMiddleware = createTelemetryMiddleware;
|
|
@@ -5,74 +5,27 @@ datadog.init();
|
|
|
5
5
|
|
|
6
6
|
// Record metrics for datadog
|
|
7
7
|
const recordDatadog = (metric, tags) => {
|
|
8
|
-
datadog.dogstatsd.gauge(`
|
|
8
|
+
datadog.dogstatsd.gauge(`client_response_time`, metric, tags);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const time = () => performance.now();
|
|
12
12
|
|
|
13
|
-
function createTelemetryMiddleware
|
|
14
|
-
// trace
|
|
15
|
-
function trace() {
|
|
16
|
-
// validate apm and tracer
|
|
17
|
-
if (!(options?.apm && typeof options.apm == 'function')) {
|
|
18
|
-
options.apm = () => {};
|
|
19
|
-
}
|
|
20
|
-
if (!(options?.tracer && typeof options.tracer == 'function')) {
|
|
21
|
-
options.tracer = () => {};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
trace(); // expose tracing modules
|
|
25
|
-
|
|
26
|
-
return next => async request => {
|
|
27
|
-
// get start (high resolution milliseconds) timestamp
|
|
28
|
-
const start = time();
|
|
29
|
-
const nextRequest = {
|
|
30
|
-
...request,
|
|
31
|
-
...options
|
|
32
|
-
};
|
|
33
|
-
const response = await next(nextRequest);
|
|
34
|
-
const response_time = time() - start;
|
|
35
|
-
|
|
36
|
-
// send `response_time` to APM platforms
|
|
37
|
-
if (options?.customMetrics) {
|
|
38
|
-
if (options.customMetrics.datadog) {
|
|
39
|
-
recordDatadog(response_time, {
|
|
40
|
-
env: process.env.NODE_ENV || 'dev'
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (options.customMetrics.newrelic) {
|
|
44
|
-
// Lazy load New Relic only if necessary otherwise it will require to have set the env variable NEW_RELIC_APP_NAME
|
|
45
|
-
const {
|
|
46
|
-
recordNewRelic
|
|
47
|
-
} = await import('./newRelicHelper-b7df4fbe.esm.js');
|
|
48
|
-
recordNewRelic(response_time);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return response;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* default newrelic APM and
|
|
57
|
-
* opentelemetry tracer modules
|
|
58
|
-
*/
|
|
59
|
-
const defaultOptions = {
|
|
13
|
+
function createTelemetryMiddleware(options) {
|
|
60
14
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
64
|
-
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
15
|
+
* default newrelic APM and
|
|
16
|
+
* opentelemetry tracer modules
|
|
65
17
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
18
|
+
const defaultOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* if this is to be used with newrelic, then
|
|
21
|
+
* pass this (apm) as an option in the `createTelemetryMiddleware`
|
|
22
|
+
* function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
|
|
23
|
+
* Note: don't forget to install newrelic agent in your project `yarn add newrelic`
|
|
24
|
+
*/
|
|
25
|
+
apm: () => {},
|
|
26
|
+
tracer: () => import('./opentelemetry-8a97600d.esm.js')
|
|
27
|
+
};
|
|
69
28
|
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated use new `createTelemetryMiddleware`
|
|
72
|
-
* @param options
|
|
73
|
-
* @returns
|
|
74
|
-
*/
|
|
75
|
-
function createTelemetryMiddleware(options) {
|
|
76
29
|
// trace
|
|
77
30
|
function trace() {
|
|
78
31
|
// validate apm and tracer
|
|
@@ -86,13 +39,32 @@ function createTelemetryMiddleware(options) {
|
|
|
86
39
|
options.tracer();
|
|
87
40
|
}
|
|
88
41
|
trace(); // expose tracing modules
|
|
89
|
-
return next =>
|
|
42
|
+
return next => async request => {
|
|
90
43
|
const nextRequest = {
|
|
91
44
|
...request,
|
|
92
45
|
...options
|
|
93
46
|
};
|
|
94
|
-
|
|
47
|
+
|
|
48
|
+
// start (high resolution milliseconds) timestamp
|
|
49
|
+
const start = time();
|
|
50
|
+
const response = await next(nextRequest);
|
|
51
|
+
const response_time = time() - start;
|
|
52
|
+
|
|
53
|
+
// send `response_time` to APM platforms
|
|
54
|
+
if (options?.customMetrics && options.customMetrics.datadog) {
|
|
55
|
+
recordDatadog(response_time, {
|
|
56
|
+
env: process.env.NODE_ENV || 'dev'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (options?.customMetrics && options.customMetrics.newrelic) {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const {
|
|
62
|
+
recordNewRelic
|
|
63
|
+
} = await import('./newRelicHelper-86b0a261.esm.js');
|
|
64
|
+
recordNewRelic(response_time);
|
|
65
|
+
}
|
|
66
|
+
return response;
|
|
95
67
|
};
|
|
96
68
|
}
|
|
97
69
|
|
|
98
|
-
export { createTelemetryMiddleware
|
|
70
|
+
export { createTelemetryMiddleware };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apm.d.ts","sourceRoot":"../../../src","sources":["apm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAIV,2BAA2B,EAC5B,0BAAsB;AAIvB,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,OAAO,EAAE,2BAA2B,GACnC,UAAU,
|
|
1
|
+
{"version":3,"file":"apm.d.ts","sourceRoot":"../../../src","sources":["apm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAIV,2BAA2B,EAC5B,0BAAsB;AAIvB,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,OAAO,EAAE,2BAA2B,GACnC,UAAU,CAyDZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,kCAAgC;AAChC,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,iBAAa
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,kCAAgC;AAChC,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,iBAAa"}
|
|
@@ -91,50 +91,3 @@ export type TelemetryMiddlewareOptions = {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export type OTelemetryMiddlewareOptions = Omit<TelemetryMiddlewareOptions, 'createTelemetryMiddleware'>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// LEGACY TYPES
|
|
97
|
-
/**
|
|
98
|
-
* @deprecated
|
|
99
|
-
*/
|
|
100
|
-
export type NextLegacy = (
|
|
101
|
-
request: MiddlewareRequestLegacy,
|
|
102
|
-
response: MiddlewareResponseLegacy
|
|
103
|
-
) => unknown
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @deprecated
|
|
107
|
-
*/
|
|
108
|
-
export type MiddlewareResponseLegacy = {
|
|
109
|
-
resolve(response: JsonObject): void
|
|
110
|
-
reject(error: JsonObject): void
|
|
111
|
-
body?: JsonObject
|
|
112
|
-
error?: HttpErrorType
|
|
113
|
-
statusCode: number
|
|
114
|
-
headers?: JsonObject<string>
|
|
115
|
-
request?: JsonObject
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @deprecated
|
|
120
|
-
*/
|
|
121
|
-
export interface ClientRequestLegacy {
|
|
122
|
-
baseUri?: string
|
|
123
|
-
uri?: string
|
|
124
|
-
headers?: VariableMap
|
|
125
|
-
method: MethodType
|
|
126
|
-
uriTemplate?: string
|
|
127
|
-
pathVariables?: VariableMap
|
|
128
|
-
queryParams?: VariableMap
|
|
129
|
-
body?: any,
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @deprecated
|
|
134
|
-
*/
|
|
135
|
-
export type MiddlewareLegacy = (next: NextLegacy) => NextLegacy
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @deprecated
|
|
139
|
-
*/
|
|
140
|
-
export type MiddlewareRequestLegacy = ClientRequestLegacy
|
|
@@ -8,7 +8,7 @@ var newrelic__default = /*#__PURE__*/_interopDefault(newrelic);
|
|
|
8
8
|
|
|
9
9
|
// record for newrelic
|
|
10
10
|
const recordNewRelic = metric => {
|
|
11
|
-
newrelic__default["default"].recordMetric(`
|
|
11
|
+
newrelic__default["default"].recordMetric(`Client/Response/Time`, metric);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
exports.recordNewRelic = recordNewRelic;
|
|
@@ -8,7 +8,7 @@ var newrelic__default = /*#__PURE__*/_interopDefault(newrelic);
|
|
|
8
8
|
|
|
9
9
|
// record for newrelic
|
|
10
10
|
const recordNewRelic = metric => {
|
|
11
|
-
newrelic__default["default"].recordMetric(`
|
|
11
|
+
newrelic__default["default"].recordMetric(`Client/Response/Time`, metric);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
exports.recordNewRelic = recordNewRelic;
|
|
@@ -8,7 +8,7 @@ var newrelic__default = /*#__PURE__*/_interopDefault(newrelic);
|
|
|
8
8
|
|
|
9
9
|
// record for newrelic
|
|
10
10
|
const recordNewRelic = metric => {
|
|
11
|
-
newrelic__default["default"].recordMetric(`
|
|
11
|
+
newrelic__default["default"].recordMetric(`Client/Response/Time`, metric);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
exports.recordNewRelic = recordNewRelic;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const process = require('process');
|
|
3
|
+
const {
|
|
4
|
+
v4: uuidv4
|
|
5
|
+
} = require('uuid');
|
|
6
|
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
|
7
|
+
const {
|
|
8
|
+
getNodeAutoInstrumentations
|
|
9
|
+
} = require('@opentelemetry/auto-instrumentations-node');
|
|
10
|
+
const {
|
|
11
|
+
Resource
|
|
12
|
+
} = require('@opentelemetry/resources');
|
|
13
|
+
const {
|
|
14
|
+
SemanticResourceAttributes
|
|
15
|
+
} = require('@opentelemetry/semantic-conventions');
|
|
16
|
+
const {
|
|
17
|
+
OTLPTraceExporter
|
|
18
|
+
} = require('@opentelemetry/exporter-trace-otlp-http');
|
|
19
|
+
const {
|
|
20
|
+
OTLPMetricExporter
|
|
21
|
+
} = require('@opentelemetry/exporter-metrics-otlp-http');
|
|
22
|
+
const {
|
|
23
|
+
AggregationTemporality,
|
|
24
|
+
PeriodicExportingMetricReader
|
|
25
|
+
} = require('@opentelemetry/sdk-metrics');
|
|
26
|
+
const api = require('@opentelemetry/api');
|
|
27
|
+
|
|
28
|
+
// enable logging ONLY for developement
|
|
29
|
+
// this is useful for debugging instrumentation issues
|
|
30
|
+
// remove from production after issues (if any) are resolved
|
|
31
|
+
// view more logging levels here: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/src/diag/types.ts#L67
|
|
32
|
+
|
|
33
|
+
if (process.env.NODE_ENV == 'development') {
|
|
34
|
+
api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.INFO, api.DiagLogLevel.ERROR);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Declare the resource to be used.
|
|
38
|
+
// A resource represents a collection of attributes describing the
|
|
39
|
+
// service. This collection of attributes will be associated with all
|
|
40
|
+
// telemetry generated from this service (traces, metrics, logs).
|
|
41
|
+
const resource = new Resource({
|
|
42
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: uuidv4(),
|
|
43
|
+
[SemanticResourceAttributes.SERVICE_NAME]: process.env['NEW_RELIC_APP_NAME']
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Enable auto-instrumentation from the meta package.
|
|
47
|
+
const instrumentations = [getNodeAutoInstrumentations()];
|
|
48
|
+
|
|
49
|
+
// Configure the OTLP/HTTP exporters.
|
|
50
|
+
// The following assumes you've set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
51
|
+
// environment variables.
|
|
52
|
+
const traceExporter = new OTLPTraceExporter();
|
|
53
|
+
const metricExporter = new OTLPMetricExporter({
|
|
54
|
+
temporalityPreference: AggregationTemporality.DELTA
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// If you haven't set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
58
|
+
// environment variables, you can configure the OTLP exporter programmatically by
|
|
59
|
+
// uncommenting the following code:
|
|
60
|
+
|
|
61
|
+
// this endpoint contains a path since this exporter is signal specific (traces)
|
|
62
|
+
// see more details here: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-quick-start/#note-endpoints
|
|
63
|
+
// const url = "https://otlp.nr-data.net:4317/v1/traces";
|
|
64
|
+
|
|
65
|
+
// Configure PeriodicMetricReader
|
|
66
|
+
const metricReader = new PeriodicExportingMetricReader({
|
|
67
|
+
exporter: metricExporter,
|
|
68
|
+
exportIntervalMillis: 5000
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Configure the OpenTelemetry NodeSDK
|
|
72
|
+
const sdk = new opentelemetry.NodeSDK({
|
|
73
|
+
resource,
|
|
74
|
+
traceExporter,
|
|
75
|
+
metricReader,
|
|
76
|
+
instrumentations
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Initialize the SDK and register with the OpenTelemetry API:
|
|
80
|
+
// this enables the API to record telemetry
|
|
81
|
+
sdk.start();
|
|
82
|
+
|
|
83
|
+
// Gracefully shut down the SDK on process exit
|
|
84
|
+
process.on('SIGTERM', () => {
|
|
85
|
+
sdk.shutdown().then(() => console.log('OpenTelemetry terminated')).catch(error => console.log('Error terminating OpenTelemetry', error)).finally(() => process.exit(0));
|
|
86
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('dotenv').config();
|
|
4
|
+
const process = require('process');
|
|
5
|
+
const {
|
|
6
|
+
v4: uuidv4
|
|
7
|
+
} = require('uuid');
|
|
8
|
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
|
9
|
+
const {
|
|
10
|
+
getNodeAutoInstrumentations
|
|
11
|
+
} = require('@opentelemetry/auto-instrumentations-node');
|
|
12
|
+
const {
|
|
13
|
+
Resource
|
|
14
|
+
} = require('@opentelemetry/resources');
|
|
15
|
+
const {
|
|
16
|
+
SemanticResourceAttributes
|
|
17
|
+
} = require('@opentelemetry/semantic-conventions');
|
|
18
|
+
const {
|
|
19
|
+
OTLPTraceExporter
|
|
20
|
+
} = require('@opentelemetry/exporter-trace-otlp-http');
|
|
21
|
+
const {
|
|
22
|
+
OTLPMetricExporter
|
|
23
|
+
} = require('@opentelemetry/exporter-metrics-otlp-http');
|
|
24
|
+
const {
|
|
25
|
+
AggregationTemporality,
|
|
26
|
+
PeriodicExportingMetricReader
|
|
27
|
+
} = require('@opentelemetry/sdk-metrics');
|
|
28
|
+
const api = require('@opentelemetry/api');
|
|
29
|
+
|
|
30
|
+
// enable logging ONLY for developement
|
|
31
|
+
// this is useful for debugging instrumentation issues
|
|
32
|
+
// remove from production after issues (if any) are resolved
|
|
33
|
+
// view more logging levels here: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/src/diag/types.ts#L67
|
|
34
|
+
|
|
35
|
+
if (process.env.NODE_ENV == 'development') {
|
|
36
|
+
api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.INFO, api.DiagLogLevel.ERROR);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Declare the resource to be used.
|
|
40
|
+
// A resource represents a collection of attributes describing the
|
|
41
|
+
// service. This collection of attributes will be associated with all
|
|
42
|
+
// telemetry generated from this service (traces, metrics, logs).
|
|
43
|
+
const resource = new Resource({
|
|
44
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: uuidv4(),
|
|
45
|
+
[SemanticResourceAttributes.SERVICE_NAME]: process.env['NEW_RELIC_APP_NAME']
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Enable auto-instrumentation from the meta package.
|
|
49
|
+
const instrumentations = [getNodeAutoInstrumentations()];
|
|
50
|
+
|
|
51
|
+
// Configure the OTLP/HTTP exporters.
|
|
52
|
+
// The following assumes you've set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
53
|
+
// environment variables.
|
|
54
|
+
const traceExporter = new OTLPTraceExporter();
|
|
55
|
+
const metricExporter = new OTLPMetricExporter({
|
|
56
|
+
temporalityPreference: AggregationTemporality.DELTA
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// If you haven't set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
60
|
+
// environment variables, you can configure the OTLP exporter programmatically by
|
|
61
|
+
// uncommenting the following code:
|
|
62
|
+
|
|
63
|
+
// this endpoint contains a path since this exporter is signal specific (traces)
|
|
64
|
+
// see more details here: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-quick-start/#note-endpoints
|
|
65
|
+
// const url = "https://otlp.nr-data.net:4317/v1/traces";
|
|
66
|
+
|
|
67
|
+
// Configure PeriodicMetricReader
|
|
68
|
+
const metricReader = new PeriodicExportingMetricReader({
|
|
69
|
+
exporter: metricExporter,
|
|
70
|
+
exportIntervalMillis: 5000
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Configure the OpenTelemetry NodeSDK
|
|
74
|
+
const sdk = new opentelemetry.NodeSDK({
|
|
75
|
+
resource,
|
|
76
|
+
traceExporter,
|
|
77
|
+
metricReader,
|
|
78
|
+
instrumentations
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Initialize the SDK and register with the OpenTelemetry API:
|
|
82
|
+
// this enables the API to record telemetry
|
|
83
|
+
sdk.start();
|
|
84
|
+
|
|
85
|
+
// Gracefully shut down the SDK on process exit
|
|
86
|
+
process.on('SIGTERM', () => {
|
|
87
|
+
sdk.shutdown().then(() => console.log('OpenTelemetry terminated')).catch(error => console.log('Error terminating OpenTelemetry', error)).finally(() => process.exit(0));
|
|
88
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('dotenv').config();
|
|
4
|
+
const process = require('process');
|
|
5
|
+
const {
|
|
6
|
+
v4: uuidv4
|
|
7
|
+
} = require('uuid');
|
|
8
|
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
|
9
|
+
const {
|
|
10
|
+
getNodeAutoInstrumentations
|
|
11
|
+
} = require('@opentelemetry/auto-instrumentations-node');
|
|
12
|
+
const {
|
|
13
|
+
Resource
|
|
14
|
+
} = require('@opentelemetry/resources');
|
|
15
|
+
const {
|
|
16
|
+
SemanticResourceAttributes
|
|
17
|
+
} = require('@opentelemetry/semantic-conventions');
|
|
18
|
+
const {
|
|
19
|
+
OTLPTraceExporter
|
|
20
|
+
} = require('@opentelemetry/exporter-trace-otlp-http');
|
|
21
|
+
const {
|
|
22
|
+
OTLPMetricExporter
|
|
23
|
+
} = require('@opentelemetry/exporter-metrics-otlp-http');
|
|
24
|
+
const {
|
|
25
|
+
AggregationTemporality,
|
|
26
|
+
PeriodicExportingMetricReader
|
|
27
|
+
} = require('@opentelemetry/sdk-metrics');
|
|
28
|
+
require('@opentelemetry/api');
|
|
29
|
+
|
|
30
|
+
// Declare the resource to be used.
|
|
31
|
+
// A resource represents a collection of attributes describing the
|
|
32
|
+
// service. This collection of attributes will be associated with all
|
|
33
|
+
// telemetry generated from this service (traces, metrics, logs).
|
|
34
|
+
const resource = new Resource({
|
|
35
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: uuidv4(),
|
|
36
|
+
[SemanticResourceAttributes.SERVICE_NAME]: process.env['NEW_RELIC_APP_NAME']
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Enable auto-instrumentation from the meta package.
|
|
40
|
+
const instrumentations = [getNodeAutoInstrumentations()];
|
|
41
|
+
|
|
42
|
+
// Configure the OTLP/HTTP exporters.
|
|
43
|
+
// The following assumes you've set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
44
|
+
// environment variables.
|
|
45
|
+
const traceExporter = new OTLPTraceExporter();
|
|
46
|
+
const metricExporter = new OTLPMetricExporter({
|
|
47
|
+
temporalityPreference: AggregationTemporality.DELTA
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// If you haven't set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
51
|
+
// environment variables, you can configure the OTLP exporter programmatically by
|
|
52
|
+
// uncommenting the following code:
|
|
53
|
+
|
|
54
|
+
// this endpoint contains a path since this exporter is signal specific (traces)
|
|
55
|
+
// see more details here: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-quick-start/#note-endpoints
|
|
56
|
+
// const url = "https://otlp.nr-data.net:4317/v1/traces";
|
|
57
|
+
|
|
58
|
+
// Configure PeriodicMetricReader
|
|
59
|
+
const metricReader = new PeriodicExportingMetricReader({
|
|
60
|
+
exporter: metricExporter,
|
|
61
|
+
exportIntervalMillis: 5000
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Configure the OpenTelemetry NodeSDK
|
|
65
|
+
const sdk = new opentelemetry.NodeSDK({
|
|
66
|
+
resource,
|
|
67
|
+
traceExporter,
|
|
68
|
+
metricReader,
|
|
69
|
+
instrumentations
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Initialize the SDK and register with the OpenTelemetry API:
|
|
73
|
+
// this enables the API to record telemetry
|
|
74
|
+
sdk.start();
|
|
75
|
+
|
|
76
|
+
// Gracefully shut down the SDK on process exit
|
|
77
|
+
process.on('SIGTERM', () => {
|
|
78
|
+
sdk.shutdown().then(() => console.log('OpenTelemetry terminated')).catch(error => console.log('Error terminating OpenTelemetry', error)).finally(() => process.exit(0));
|
|
79
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const process = require('process');
|
|
3
|
+
const {
|
|
4
|
+
v4: uuidv4
|
|
5
|
+
} = require('uuid');
|
|
6
|
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
|
7
|
+
const {
|
|
8
|
+
getNodeAutoInstrumentations
|
|
9
|
+
} = require('@opentelemetry/auto-instrumentations-node');
|
|
10
|
+
const {
|
|
11
|
+
Resource
|
|
12
|
+
} = require('@opentelemetry/resources');
|
|
13
|
+
const {
|
|
14
|
+
SemanticResourceAttributes
|
|
15
|
+
} = require('@opentelemetry/semantic-conventions');
|
|
16
|
+
const {
|
|
17
|
+
OTLPTraceExporter
|
|
18
|
+
} = require('@opentelemetry/exporter-trace-otlp-http');
|
|
19
|
+
const {
|
|
20
|
+
OTLPMetricExporter
|
|
21
|
+
} = require('@opentelemetry/exporter-metrics-otlp-http');
|
|
22
|
+
const {
|
|
23
|
+
AggregationTemporality,
|
|
24
|
+
PeriodicExportingMetricReader
|
|
25
|
+
} = require('@opentelemetry/sdk-metrics');
|
|
26
|
+
const api = require('@opentelemetry/api');
|
|
27
|
+
|
|
28
|
+
// enable logging ONLY for developement
|
|
29
|
+
// this is useful for debugging instrumentation issues
|
|
30
|
+
// remove from production after issues (if any) are resolved
|
|
31
|
+
// view more logging levels here: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/src/diag/types.ts#L67
|
|
32
|
+
|
|
33
|
+
if (process.env.NODE_ENV == 'development') {
|
|
34
|
+
api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.INFO, api.DiagLogLevel.ERROR);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Declare the resource to be used.
|
|
38
|
+
// A resource represents a collection of attributes describing the
|
|
39
|
+
// service. This collection of attributes will be associated with all
|
|
40
|
+
// telemetry generated from this service (traces, metrics, logs).
|
|
41
|
+
const resource = new Resource({
|
|
42
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: uuidv4(),
|
|
43
|
+
[SemanticResourceAttributes.SERVICE_NAME]: process.env['NEW_RELIC_APP_NAME']
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Enable auto-instrumentation from the meta package.
|
|
47
|
+
const instrumentations = [getNodeAutoInstrumentations()];
|
|
48
|
+
|
|
49
|
+
// Configure the OTLP/HTTP exporters.
|
|
50
|
+
// The following assumes you've set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
51
|
+
// environment variables.
|
|
52
|
+
const traceExporter = new OTLPTraceExporter();
|
|
53
|
+
const metricExporter = new OTLPMetricExporter({
|
|
54
|
+
temporalityPreference: AggregationTemporality.DELTA
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// If you haven't set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
58
|
+
// environment variables, you can configure the OTLP exporter programmatically by
|
|
59
|
+
// uncommenting the following code:
|
|
60
|
+
|
|
61
|
+
// this endpoint contains a path since this exporter is signal specific (traces)
|
|
62
|
+
// see more details here: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-quick-start/#note-endpoints
|
|
63
|
+
// const url = "https://otlp.nr-data.net:4317/v1/traces";
|
|
64
|
+
|
|
65
|
+
// Configure PeriodicMetricReader
|
|
66
|
+
const metricReader = new PeriodicExportingMetricReader({
|
|
67
|
+
exporter: metricExporter,
|
|
68
|
+
exportIntervalMillis: 5000
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Configure the OpenTelemetry NodeSDK
|
|
72
|
+
const sdk = new opentelemetry.NodeSDK({
|
|
73
|
+
resource,
|
|
74
|
+
traceExporter,
|
|
75
|
+
metricReader,
|
|
76
|
+
instrumentations
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Initialize the SDK and register with the OpenTelemetry API:
|
|
80
|
+
// this enables the API to record telemetry
|
|
81
|
+
sdk.start();
|
|
82
|
+
|
|
83
|
+
// Gracefully shut down the SDK on process exit
|
|
84
|
+
process.on('SIGTERM', () => {
|
|
85
|
+
sdk.shutdown().then(() => console.log('OpenTelemetry terminated')).catch(error => console.log('Error terminating OpenTelemetry', error)).finally(() => process.exit(0));
|
|
86
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('dotenv').config();
|
|
4
|
+
const process = require('process');
|
|
5
|
+
const {
|
|
6
|
+
v4: uuidv4
|
|
7
|
+
} = require('uuid');
|
|
8
|
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
|
9
|
+
const {
|
|
10
|
+
getNodeAutoInstrumentations
|
|
11
|
+
} = require('@opentelemetry/auto-instrumentations-node');
|
|
12
|
+
const {
|
|
13
|
+
Resource
|
|
14
|
+
} = require('@opentelemetry/resources');
|
|
15
|
+
const {
|
|
16
|
+
SemanticResourceAttributes
|
|
17
|
+
} = require('@opentelemetry/semantic-conventions');
|
|
18
|
+
const {
|
|
19
|
+
OTLPTraceExporter
|
|
20
|
+
} = require('@opentelemetry/exporter-trace-otlp-http');
|
|
21
|
+
const {
|
|
22
|
+
OTLPMetricExporter
|
|
23
|
+
} = require('@opentelemetry/exporter-metrics-otlp-http');
|
|
24
|
+
const {
|
|
25
|
+
AggregationTemporality,
|
|
26
|
+
PeriodicExportingMetricReader
|
|
27
|
+
} = require('@opentelemetry/sdk-metrics');
|
|
28
|
+
const api = require('@opentelemetry/api');
|
|
29
|
+
|
|
30
|
+
// enable logging ONLY for developement
|
|
31
|
+
// this is useful for debugging instrumentation issues
|
|
32
|
+
// remove from production after issues (if any) are resolved
|
|
33
|
+
// view more logging levels here: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/src/diag/types.ts#L67
|
|
34
|
+
|
|
35
|
+
if (process.env.NODE_ENV == 'development') {
|
|
36
|
+
api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.INFO, api.DiagLogLevel.ERROR);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Declare the resource to be used.
|
|
40
|
+
// A resource represents a collection of attributes describing the
|
|
41
|
+
// service. This collection of attributes will be associated with all
|
|
42
|
+
// telemetry generated from this service (traces, metrics, logs).
|
|
43
|
+
const resource = new Resource({
|
|
44
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: uuidv4(),
|
|
45
|
+
[SemanticResourceAttributes.SERVICE_NAME]: process.env['NEW_RELIC_APP_NAME']
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Enable auto-instrumentation from the meta package.
|
|
49
|
+
const instrumentations = [getNodeAutoInstrumentations()];
|
|
50
|
+
|
|
51
|
+
// Configure the OTLP/HTTP exporters.
|
|
52
|
+
// The following assumes you've set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
53
|
+
// environment variables.
|
|
54
|
+
const traceExporter = new OTLPTraceExporter();
|
|
55
|
+
const metricExporter = new OTLPMetricExporter({
|
|
56
|
+
temporalityPreference: AggregationTemporality.DELTA
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// If you haven't set the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OLTP_HEADERS
|
|
60
|
+
// environment variables, you can configure the OTLP exporter programmatically by
|
|
61
|
+
// uncommenting the following code:
|
|
62
|
+
|
|
63
|
+
// this endpoint contains a path since this exporter is signal specific (traces)
|
|
64
|
+
// see more details here: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-quick-start/#note-endpoints
|
|
65
|
+
// const url = "https://otlp.nr-data.net:4317/v1/traces";
|
|
66
|
+
|
|
67
|
+
// Configure PeriodicMetricReader
|
|
68
|
+
const metricReader = new PeriodicExportingMetricReader({
|
|
69
|
+
exporter: metricExporter,
|
|
70
|
+
exportIntervalMillis: 5000
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Configure the OpenTelemetry NodeSDK
|
|
74
|
+
const sdk = new opentelemetry.NodeSDK({
|
|
75
|
+
resource,
|
|
76
|
+
traceExporter,
|
|
77
|
+
metricReader,
|
|
78
|
+
instrumentations
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Initialize the SDK and register with the OpenTelemetry API:
|
|
82
|
+
// this enables the API to record telemetry
|
|
83
|
+
sdk.start();
|
|
84
|
+
|
|
85
|
+
// Gracefully shut down the SDK on process exit
|
|
86
|
+
process.on('SIGTERM', () => {
|
|
87
|
+
sdk.shutdown().then(() => console.log('OpenTelemetry terminated')).catch(error => console.log('Error terminating OpenTelemetry', error)).finally(() => process.exit(0));
|
|
88
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/ts-sdk-apm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "commercetools typescript SDK application performance monitoring.",
|
|
5
5
|
"main": "dist/commercetools-ts-sdk-apm.cjs.js",
|
|
6
6
|
"module": "dist/commercetools-ts-sdk-apm.esm.js",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"private": false,
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@opentelemetry/api": "^1.4.1",
|
|
12
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
13
|
-
"@opentelemetry/exporter-metrics-otlp-http": "^0.
|
|
14
|
-
"@opentelemetry/sdk-node": "^0.
|
|
12
|
+
"@opentelemetry/auto-instrumentations-node": "^0.58.0",
|
|
13
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.200.0",
|
|
14
|
+
"@opentelemetry/sdk-node": "^0.200.0",
|
|
15
15
|
"dd-trace": "^5.31.0",
|
|
16
16
|
"newrelic": "^12.10.0",
|
|
17
17
|
"uuid": "11.1.0"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { MiddlewareLegacy, OTelemetryMiddlewareOptions } from "../types/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated use new `createTelemetryMiddleware`
|
|
4
|
-
* @param options
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export default function createTelemetryMiddleware(options: OTelemetryMiddlewareOptions): MiddlewareLegacy;
|
|
8
|
-
//# sourceMappingURL=apm-legacy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apm-legacy.d.ts","sourceRoot":"../../../src","sources":["apm-legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAIhB,2BAA2B,EAC5B,0BAAsB;AAiBvB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,OAAO,EAAE,2BAA2B,GACnC,gBAAgB,CA0BlB"}
|