@commercetools/ts-sdk-apm 2.0.0 → 3.1.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @commercetools/ts-sdk-apm
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#861](https://github.com/commercetools/commercetools-sdk-typescript/pull/861) [`e8a0e92`](https://github.com/commercetools/commercetools-sdk-typescript/commit/e8a0e928e2ab48bd47d6ff6384f385b24e485755) Thanks [@ajimae](https://github.com/ajimae)! - Add custom metric
8
+
9
+ ## 3.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#896](https://github.com/commercetools/commercetools-sdk-typescript/pull/896) [`f9b8cb6`](https://github.com/commercetools/commercetools-sdk-typescript/commit/f9b8cb605d99fe5ece13bdc3c152eb4818e19b3b) Thanks [@lojzatran](https://github.com/lojzatran)! - Remove support of nodejs 16
14
+
3
15
  ## 2.0.0
4
16
 
5
17
  ### Major Changes
package/README.md CHANGED
@@ -63,12 +63,9 @@ Example
63
63
  const telemetryOptions = {
64
64
  createTelemetryMiddleware, // coming from the `@commercetools/ts-sdk-apm or a custom implementation
65
65
  tracer: () =>
66
- require(require('path').join(
67
- __dirname,
68
- '..',
69
- '..',
70
- 'custom-telemetry-module.js'
71
- )), // make sure the require takes in an absolute path to the custom tracer module.
66
+ require(
67
+ require('path').join(__dirname, '..', '..', 'custom-telemetry-module.js')
68
+ ), // make sure the require takes in an absolute path to the custom tracer module.
72
69
  }
73
70
  ```
74
71
 
@@ -2,6 +2,74 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var datadog = require('dd-trace');
6
+ var newrelic = require('newrelic');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
+
10
+ var datadog__default = /*#__PURE__*/_interopDefault(datadog);
11
+ var newrelic__default = /*#__PURE__*/_interopDefault(newrelic);
12
+
13
+ const time = () => performance.now();
14
+
15
+ // record for datadog
16
+ const recordDatadog = (metric, tags) => {
17
+ datadog__default["default"].init().dogstatsd.gauge(`Commercetools_Client_Response_Total`, metric, tags);
18
+ };
19
+
20
+ // record for newrelic
21
+ const recordNewrelic = metric => {
22
+ newrelic__default["default"].recordMetric(`Commercetools/Client/Response/Total`, metric);
23
+ };
24
+
25
+ /**
26
+ * default newrelic APM and
27
+ * opentelemetry tracer modules
28
+ */
29
+ const defaultOptions$1 = {
30
+ /**
31
+ * if this is to be used with newrelic, then
32
+ * pass this (apm) as an option in the `createTelemetryMiddleware`
33
+ * function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
34
+ */
35
+ apm: () => require('newrelic'),
36
+ tracer: () => require('../opentelemetry')
37
+ };
38
+ function createTelemetryMiddleware$1(options) {
39
+ // trace
40
+ function trace() {
41
+ // validate apm and tracer
42
+ if (!(options?.apm && typeof options.apm == 'function')) {
43
+ options.apm = defaultOptions$1.apm;
44
+ }
45
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
46
+ options.tracer = defaultOptions$1.tracer;
47
+ }
48
+ options.apm();
49
+ options.tracer();
50
+ }
51
+ trace(); // expose tracing modules
52
+ return next => async request => {
53
+ // get start (high resolution milliseconds) timestamp
54
+ const start = time();
55
+ const nextRequest = {
56
+ ...request,
57
+ ...options
58
+ };
59
+ const response = await next(nextRequest);
60
+ const response_time = time() - start;
61
+
62
+ // send `response_time` to APM platforms
63
+ if (options?.customMetrics) {
64
+ options.customMetrics.newrelic && recordNewrelic(response_time);
65
+ options.customMetrics.datadog && recordDatadog(response_time, {
66
+ env: 'dev'
67
+ });
68
+ }
69
+ return response;
70
+ };
71
+ }
72
+
5
73
  /**
6
74
  * default newrelic APM and
7
75
  * opentelemetry tracer modules
@@ -16,14 +84,20 @@ const defaultOptions = {
16
84
  apm: () => {},
17
85
  tracer: () => require('../opentelemetry')
18
86
  };
87
+
88
+ /**
89
+ * @deprecated use new `createTelemetryMiddleware`
90
+ * @param options
91
+ * @returns
92
+ */
19
93
  function createTelemetryMiddleware(options) {
20
94
  // trace
21
95
  function trace() {
22
96
  // validate apm and tracer
23
- if (!(options !== null && options !== void 0 && options.apm && typeof options.apm == 'function')) {
97
+ if (!(options?.apm && typeof options.apm == 'function')) {
24
98
  options.apm = defaultOptions.apm;
25
99
  }
26
- if (!(options !== null && options !== void 0 && options.tracer && typeof options.tracer == 'function')) {
100
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
27
101
  options.tracer = defaultOptions.tracer;
28
102
  }
29
103
  options.apm();
@@ -39,4 +113,13 @@ function createTelemetryMiddleware(options) {
39
113
  };
40
114
  }
41
115
 
42
- exports.createTelemetryMiddleware = createTelemetryMiddleware;
116
+ Object.defineProperty(exports, 'datadog', {
117
+ enumerable: true,
118
+ get: function () { return datadog__default["default"]; }
119
+ });
120
+ Object.defineProperty(exports, 'newrelic', {
121
+ enumerable: true,
122
+ get: function () { return newrelic__default["default"]; }
123
+ });
124
+ exports.createTelemetryMiddleware = createTelemetryMiddleware$1;
125
+ exports.createTelemetryMiddlewareLegacy = createTelemetryMiddleware;
@@ -1,3 +1,68 @@
1
+ import datadog from 'dd-trace';
2
+ export { default as datadog } from 'dd-trace';
3
+ import newrelic from 'newrelic';
4
+ export { default as newrelic } from 'newrelic';
5
+
6
+ const time = () => performance.now();
7
+
8
+ // record for datadog
9
+ const recordDatadog = (metric, tags) => {
10
+ datadog.init().dogstatsd.gauge(`Commercetools_Client_Response_Total`, metric, tags);
11
+ };
12
+
13
+ // record for newrelic
14
+ const recordNewrelic = metric => {
15
+ newrelic.recordMetric(`Commercetools/Client/Response/Total`, metric);
16
+ };
17
+
18
+ /**
19
+ * default newrelic APM and
20
+ * opentelemetry tracer modules
21
+ */
22
+ const defaultOptions$1 = {
23
+ /**
24
+ * if this is to be used with newrelic, then
25
+ * pass this (apm) as an option in the `createTelemetryMiddleware`
26
+ * function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
27
+ */
28
+ apm: () => require('newrelic'),
29
+ tracer: () => require('../opentelemetry')
30
+ };
31
+ function createTelemetryMiddleware$1(options) {
32
+ // trace
33
+ function trace() {
34
+ // validate apm and tracer
35
+ if (!(options?.apm && typeof options.apm == 'function')) {
36
+ options.apm = defaultOptions$1.apm;
37
+ }
38
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
39
+ options.tracer = defaultOptions$1.tracer;
40
+ }
41
+ options.apm();
42
+ options.tracer();
43
+ }
44
+ trace(); // expose tracing modules
45
+ return next => async request => {
46
+ // get start (high resolution milliseconds) timestamp
47
+ const start = time();
48
+ const nextRequest = {
49
+ ...request,
50
+ ...options
51
+ };
52
+ const response = await next(nextRequest);
53
+ const response_time = time() - start;
54
+
55
+ // send `response_time` to APM platforms
56
+ if (options?.customMetrics) {
57
+ options.customMetrics.newrelic && recordNewrelic(response_time);
58
+ options.customMetrics.datadog && recordDatadog(response_time, {
59
+ env: 'dev'
60
+ });
61
+ }
62
+ return response;
63
+ };
64
+ }
65
+
1
66
  /**
2
67
  * default newrelic APM and
3
68
  * opentelemetry tracer modules
@@ -12,14 +77,20 @@ const defaultOptions = {
12
77
  apm: () => {},
13
78
  tracer: () => require('../opentelemetry')
14
79
  };
80
+
81
+ /**
82
+ * @deprecated use new `createTelemetryMiddleware`
83
+ * @param options
84
+ * @returns
85
+ */
15
86
  function createTelemetryMiddleware(options) {
16
87
  // trace
17
88
  function trace() {
18
89
  // validate apm and tracer
19
- if (!(options !== null && options !== void 0 && options.apm && typeof options.apm == 'function')) {
90
+ if (!(options?.apm && typeof options.apm == 'function')) {
20
91
  options.apm = defaultOptions.apm;
21
92
  }
22
- if (!(options !== null && options !== void 0 && options.tracer && typeof options.tracer == 'function')) {
93
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
23
94
  options.tracer = defaultOptions.tracer;
24
95
  }
25
96
  options.apm();
@@ -35,4 +106,4 @@ function createTelemetryMiddleware(options) {
35
106
  };
36
107
  }
37
108
 
38
- export { createTelemetryMiddleware };
109
+ export { createTelemetryMiddleware$1 as createTelemetryMiddleware, createTelemetryMiddleware as createTelemetryMiddlewareLegacy };
@@ -1,2 +1,2 @@
1
- export * from "./declarations/src/index";
2
- //# sourceMappingURL=commercetools-ts-sdk-apm.cjs.d.ts.map
1
+ export * from "./declarations/src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy10cy1zZGstYXBtLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -2,6 +2,74 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var datadog = require('dd-trace');
6
+ var newrelic = require('newrelic');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
+
10
+ var datadog__default = /*#__PURE__*/_interopDefault(datadog);
11
+ var newrelic__default = /*#__PURE__*/_interopDefault(newrelic);
12
+
13
+ const time = () => performance.now();
14
+
15
+ // record for datadog
16
+ const recordDatadog = (metric, tags) => {
17
+ datadog__default["default"].init().dogstatsd.gauge(`Commercetools_Client_Response_Total`, metric, tags);
18
+ };
19
+
20
+ // record for newrelic
21
+ const recordNewrelic = metric => {
22
+ newrelic__default["default"].recordMetric(`Commercetools/Client/Response/Total`, metric);
23
+ };
24
+
25
+ /**
26
+ * default newrelic APM and
27
+ * opentelemetry tracer modules
28
+ */
29
+ const defaultOptions$1 = {
30
+ /**
31
+ * if this is to be used with newrelic, then
32
+ * pass this (apm) as an option in the `createTelemetryMiddleware`
33
+ * function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
34
+ */
35
+ apm: () => require('newrelic'),
36
+ tracer: () => require('../opentelemetry')
37
+ };
38
+ function createTelemetryMiddleware$1(options) {
39
+ // trace
40
+ function trace() {
41
+ // validate apm and tracer
42
+ if (!(options?.apm && typeof options.apm == 'function')) {
43
+ options.apm = defaultOptions$1.apm;
44
+ }
45
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
46
+ options.tracer = defaultOptions$1.tracer;
47
+ }
48
+ options.apm();
49
+ options.tracer();
50
+ }
51
+ trace(); // expose tracing modules
52
+ return next => async request => {
53
+ // get start (high resolution milliseconds) timestamp
54
+ const start = time();
55
+ const nextRequest = {
56
+ ...request,
57
+ ...options
58
+ };
59
+ const response = await next(nextRequest);
60
+ const response_time = time() - start;
61
+
62
+ // send `response_time` to APM platforms
63
+ if (options?.customMetrics) {
64
+ options.customMetrics.newrelic && recordNewrelic(response_time);
65
+ options.customMetrics.datadog && recordDatadog(response_time, {
66
+ env: 'dev'
67
+ });
68
+ }
69
+ return response;
70
+ };
71
+ }
72
+
5
73
  /**
6
74
  * default newrelic APM and
7
75
  * opentelemetry tracer modules
@@ -16,14 +84,20 @@ const defaultOptions = {
16
84
  apm: () => {},
17
85
  tracer: () => require('../opentelemetry')
18
86
  };
87
+
88
+ /**
89
+ * @deprecated use new `createTelemetryMiddleware`
90
+ * @param options
91
+ * @returns
92
+ */
19
93
  function createTelemetryMiddleware(options) {
20
94
  // trace
21
95
  function trace() {
22
96
  // validate apm and tracer
23
- if (!(options !== null && options !== void 0 && options.apm && typeof options.apm == 'function')) {
97
+ if (!(options?.apm && typeof options.apm == 'function')) {
24
98
  options.apm = defaultOptions.apm;
25
99
  }
26
- if (!(options !== null && options !== void 0 && options.tracer && typeof options.tracer == 'function')) {
100
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
27
101
  options.tracer = defaultOptions.tracer;
28
102
  }
29
103
  options.apm();
@@ -39,4 +113,13 @@ function createTelemetryMiddleware(options) {
39
113
  };
40
114
  }
41
115
 
42
- exports.createTelemetryMiddleware = createTelemetryMiddleware;
116
+ Object.defineProperty(exports, 'datadog', {
117
+ enumerable: true,
118
+ get: function () { return datadog__default["default"]; }
119
+ });
120
+ Object.defineProperty(exports, 'newrelic', {
121
+ enumerable: true,
122
+ get: function () { return newrelic__default["default"]; }
123
+ });
124
+ exports.createTelemetryMiddleware = createTelemetryMiddleware$1;
125
+ exports.createTelemetryMiddlewareLegacy = createTelemetryMiddleware;
@@ -2,6 +2,74 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var datadog = require('dd-trace');
6
+ var newrelic = require('newrelic');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
+
10
+ var datadog__default = /*#__PURE__*/_interopDefault(datadog);
11
+ var newrelic__default = /*#__PURE__*/_interopDefault(newrelic);
12
+
13
+ const time = () => performance.now();
14
+
15
+ // record for datadog
16
+ const recordDatadog = (metric, tags) => {
17
+ datadog__default["default"].init().dogstatsd.gauge(`Commercetools_Client_Response_Total`, metric, tags);
18
+ };
19
+
20
+ // record for newrelic
21
+ const recordNewrelic = metric => {
22
+ newrelic__default["default"].recordMetric(`Commercetools/Client/Response/Total`, metric);
23
+ };
24
+
25
+ /**
26
+ * default newrelic APM and
27
+ * opentelemetry tracer modules
28
+ */
29
+ const defaultOptions$1 = {
30
+ /**
31
+ * if this is to be used with newrelic, then
32
+ * pass this (apm) as an option in the `createTelemetryMiddleware`
33
+ * function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
34
+ */
35
+ apm: () => require('newrelic'),
36
+ tracer: () => require('../opentelemetry')
37
+ };
38
+ function createTelemetryMiddleware$1(options) {
39
+ // trace
40
+ function trace() {
41
+ // validate apm and tracer
42
+ if (!(options?.apm && typeof options.apm == 'function')) {
43
+ options.apm = defaultOptions$1.apm;
44
+ }
45
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
46
+ options.tracer = defaultOptions$1.tracer;
47
+ }
48
+ options.apm();
49
+ options.tracer();
50
+ }
51
+ trace(); // expose tracing modules
52
+ return next => async request => {
53
+ // get start (high resolution milliseconds) timestamp
54
+ const start = time();
55
+ const nextRequest = {
56
+ ...request,
57
+ ...options
58
+ };
59
+ const response = await next(nextRequest);
60
+ const response_time = time() - start;
61
+
62
+ // send `response_time` to APM platforms
63
+ if (options?.customMetrics) {
64
+ options.customMetrics.newrelic && recordNewrelic(response_time);
65
+ options.customMetrics.datadog && recordDatadog(response_time, {
66
+ env: 'dev'
67
+ });
68
+ }
69
+ return response;
70
+ };
71
+ }
72
+
5
73
  /**
6
74
  * default newrelic APM and
7
75
  * opentelemetry tracer modules
@@ -16,14 +84,20 @@ const defaultOptions = {
16
84
  apm: () => {},
17
85
  tracer: () => require('../opentelemetry')
18
86
  };
87
+
88
+ /**
89
+ * @deprecated use new `createTelemetryMiddleware`
90
+ * @param options
91
+ * @returns
92
+ */
19
93
  function createTelemetryMiddleware(options) {
20
94
  // trace
21
95
  function trace() {
22
96
  // validate apm and tracer
23
- if (!(options !== null && options !== void 0 && options.apm && typeof options.apm == 'function')) {
97
+ if (!(options?.apm && typeof options.apm == 'function')) {
24
98
  options.apm = defaultOptions.apm;
25
99
  }
26
- if (!(options !== null && options !== void 0 && options.tracer && typeof options.tracer == 'function')) {
100
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
27
101
  options.tracer = defaultOptions.tracer;
28
102
  }
29
103
  options.apm();
@@ -39,4 +113,13 @@ function createTelemetryMiddleware(options) {
39
113
  };
40
114
  }
41
115
 
42
- exports.createTelemetryMiddleware = createTelemetryMiddleware;
116
+ Object.defineProperty(exports, 'datadog', {
117
+ enumerable: true,
118
+ get: function () { return datadog__default["default"]; }
119
+ });
120
+ Object.defineProperty(exports, 'newrelic', {
121
+ enumerable: true,
122
+ get: function () { return newrelic__default["default"]; }
123
+ });
124
+ exports.createTelemetryMiddleware = createTelemetryMiddleware$1;
125
+ exports.createTelemetryMiddlewareLegacy = createTelemetryMiddleware;
@@ -1,3 +1,68 @@
1
+ import datadog from 'dd-trace';
2
+ export { default as datadog } from 'dd-trace';
3
+ import newrelic from 'newrelic';
4
+ export { default as newrelic } from 'newrelic';
5
+
6
+ const time = () => performance.now();
7
+
8
+ // record for datadog
9
+ const recordDatadog = (metric, tags) => {
10
+ datadog.init().dogstatsd.gauge(`Commercetools_Client_Response_Total`, metric, tags);
11
+ };
12
+
13
+ // record for newrelic
14
+ const recordNewrelic = metric => {
15
+ newrelic.recordMetric(`Commercetools/Client/Response/Total`, metric);
16
+ };
17
+
18
+ /**
19
+ * default newrelic APM and
20
+ * opentelemetry tracer modules
21
+ */
22
+ const defaultOptions$1 = {
23
+ /**
24
+ * if this is to be used with newrelic, then
25
+ * pass this (apm) as an option in the `createTelemetryMiddleware`
26
+ * function e.g createTelemetryMiddleware({ apm: () => require('newrelic'), ... })
27
+ */
28
+ apm: () => require('newrelic'),
29
+ tracer: () => require('../opentelemetry')
30
+ };
31
+ function createTelemetryMiddleware$1(options) {
32
+ // trace
33
+ function trace() {
34
+ // validate apm and tracer
35
+ if (!(options?.apm && typeof options.apm == 'function')) {
36
+ options.apm = defaultOptions$1.apm;
37
+ }
38
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
39
+ options.tracer = defaultOptions$1.tracer;
40
+ }
41
+ options.apm();
42
+ options.tracer();
43
+ }
44
+ trace(); // expose tracing modules
45
+ return next => async request => {
46
+ // get start (high resolution milliseconds) timestamp
47
+ const start = time();
48
+ const nextRequest = {
49
+ ...request,
50
+ ...options
51
+ };
52
+ const response = await next(nextRequest);
53
+ const response_time = time() - start;
54
+
55
+ // send `response_time` to APM platforms
56
+ if (options?.customMetrics) {
57
+ options.customMetrics.newrelic && recordNewrelic(response_time);
58
+ options.customMetrics.datadog && recordDatadog(response_time, {
59
+ env: 'dev'
60
+ });
61
+ }
62
+ return response;
63
+ };
64
+ }
65
+
1
66
  /**
2
67
  * default newrelic APM and
3
68
  * opentelemetry tracer modules
@@ -12,14 +77,20 @@ const defaultOptions = {
12
77
  apm: () => {},
13
78
  tracer: () => require('../opentelemetry')
14
79
  };
80
+
81
+ /**
82
+ * @deprecated use new `createTelemetryMiddleware`
83
+ * @param options
84
+ * @returns
85
+ */
15
86
  function createTelemetryMiddleware(options) {
16
87
  // trace
17
88
  function trace() {
18
89
  // validate apm and tracer
19
- if (!(options !== null && options !== void 0 && options.apm && typeof options.apm == 'function')) {
90
+ if (!(options?.apm && typeof options.apm == 'function')) {
20
91
  options.apm = defaultOptions.apm;
21
92
  }
22
- if (!(options !== null && options !== void 0 && options.tracer && typeof options.tracer == 'function')) {
93
+ if (!(options?.tracer && typeof options.tracer == 'function')) {
23
94
  options.tracer = defaultOptions.tracer;
24
95
  }
25
96
  options.apm();
@@ -35,4 +106,4 @@ function createTelemetryMiddleware(options) {
35
106
  };
36
107
  }
37
108
 
38
- export { createTelemetryMiddleware };
109
+ export { createTelemetryMiddleware$1 as createTelemetryMiddleware, createTelemetryMiddleware as createTelemetryMiddlewareLegacy };
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apm-legacy.d.ts","sourceRoot":"../../../src","sources":["apm-legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAKhB,2BAA2B,EAC5B,0BAAsB;AAiBvB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,OAAO,EAAE,2BAA2B,GACnC,gBAAgB,CA0BlB"}
@@ -1,2 +1,3 @@
1
1
  import type { Middleware, OTelemetryMiddlewareOptions } from "../types/types.js";
2
2
  export default function createTelemetryMiddleware(options: OTelemetryMiddlewareOptions): Middleware;
3
+ //# sourceMappingURL=apm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apm.d.ts","sourceRoot":"../../../src","sources":["apm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAIV,2BAA2B,EAC5B,0BAAsB;AAiBvB,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,OAAO,EAAE,2BAA2B,GACnC,UAAU,CAuCZ"}
@@ -1,2 +1,5 @@
1
1
  export * from "../types/types.js";
2
2
  export { default as createTelemetryMiddleware } from "./apm.js";
3
+ export { default as createTelemetryMiddlewareLegacy } from "./apm-legacy.js";
4
+ export * from "./lib/agents.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAC5D,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,wBAAoB;AACzE,gCAA6B"}
@@ -0,0 +1,4 @@
1
+ import datadog from 'dd-trace';
2
+ import newrelic from 'newrelic';
3
+ export { datadog, newrelic };
4
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"../../../../src/lib","sources":["agents.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,QAAQ,MAAM,UAAU,CAAA;AAE/B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAA"}
@@ -1,48 +1,57 @@
1
1
  export type JsonObject<T = unknown> = { [key: string]: T }
2
2
  export type MiddlewareRequest = ClientRequest
3
- export type Middleware = (next: Dispatch) => Dispatch
4
3
 
5
- export type Dispatch = (
6
- request: MiddlewareRequest,
7
- response: MiddlewareResponse
8
- ) => unknown
4
+ export type Middleware = (next: Next) => (request: MiddlewareRequest) => Promise<MiddlewareResponse>
9
5
 
10
- export type Next = (
11
- request: MiddlewareRequest,
12
- response: MiddlewareResponse
13
- ) => unknown
6
+ // export type Dispatch = (next: Next) => (request: MiddlewareRequest) => Promise<MiddlewareResponse>
7
+ export type Next = (request: MiddlewareRequest) => Promise<MiddlewareResponse>
14
8
 
15
- export type MiddlewareResponse = {
16
- resolve(response: JsonObject): void
17
- reject(error: JsonObject): void
18
- body?: JsonObject
19
- error?: HttpErrorType
20
- statusCode: number
21
- headers?: JsonObject<string>
22
- request?: JsonObject
9
+ export type MiddlewareResponse<T = unknown> = {
10
+ resolve: Function;
11
+ reject: Function;
12
+ body: T;
13
+ error?: HttpErrorType;
14
+ statusCode: number;
15
+ headers?: Record<string, any>
16
+ originalRequest?: MiddlewareRequest;
23
17
  }
24
18
 
25
19
  export interface ClientRequest {
26
20
  baseUri?: string
27
21
  uri?: string
28
- headers?: VariableMap
22
+ headers?: Record<string, any>
29
23
  method: MethodType
30
24
  uriTemplate?: string
31
25
  pathVariables?: VariableMap
32
26
  queryParams?: VariableMap
33
- body?: any,
27
+ body?: Record<string, any> | string | Uint8Array;
28
+ response?: ClientResponse
29
+ resolve?: Function;
30
+ reject?: Function;
31
+ [key: string]: any
32
+ }
33
+
34
+ export type ClientResponse<T = any> = {
35
+ body: T
36
+ code?: number
37
+ statusCode?: number
38
+ headers?: Record<string, any>
39
+ error?: HttpErrorType
40
+ retryCount?: number
34
41
  }
35
42
 
36
43
  export type HttpErrorType = {
37
- name: string
44
+ name?: string
38
45
  message: string
39
- code: number
40
- status: number
46
+ code?: number
47
+ status?: number
48
+ method: MethodType
41
49
  statusCode: number
42
- originalRequest: ClientRequest
43
- body?: JsonObject
50
+ originalRequest?: ClientRequest
51
+ body: JsonObject
44
52
  retryCount?: number
45
- headers?: JsonObject<string>
53
+ headers?: Record<string, any>
54
+ [key: string]: any
46
55
  }
47
56
 
48
57
  export type VariableMap = {
@@ -58,47 +67,75 @@ export type QueryParam =
58
67
  | boolean[]
59
68
  | undefined
60
69
 
61
- export type MethodType =
62
- | 'ACL'
63
- | 'BIND'
64
- | 'CHECKOUT'
65
- | 'CONNECT'
66
- | 'COPY'
67
- | 'DELETE'
70
+ export type MethodType =
68
71
  | 'GET'
69
72
  | 'HEAD'
70
- | 'LINK'
71
- | 'LOCK'
72
- | 'M-SEARCH'
73
- | 'MERGE'
74
- | 'MKACTIVITY'
75
- | 'MKCALENDAR'
76
- | 'MKCOL'
77
- | 'MOVE'
78
- | 'NOTIFY'
79
- | 'OPTIONS'
80
- | 'PATCH'
81
73
  | 'POST'
82
- | 'PROPFIND'
83
- | 'PROPPATCH'
84
- | 'PURGE'
85
74
  | 'PUT'
86
- | 'REBIND'
87
- | 'REPORT'
88
- | 'SEARCH'
89
- | 'SOURCE'
90
- | 'SUBSCRIBE'
75
+ | 'PATCH'
76
+ | 'DELETE'
77
+ | 'CONNECT'
78
+ | 'OPTIONS'
91
79
  | 'TRACE'
92
- | 'UNBIND'
93
- | 'UNLINK'
94
- | 'UNLOCK'
95
- | 'UNSUBSCRIBE'
80
+
81
+ export type CustomMetric = {
82
+ newrelic?: boolean;
83
+ datadog?: boolean;
84
+ }
96
85
 
97
86
  export type TelemetryMiddlewareOptions = {
98
87
  apm?: Function;
99
88
  tracer?: Function;
100
89
  userAgent?: string;
90
+ customMetrics?: CustomMetric;
101
91
  createTelemetryMiddleware: (options?: OTelemetryMiddlewareOptions) => Middleware
102
92
  }
103
93
 
104
94
  export type OTelemetryMiddlewareOptions = Omit<TelemetryMiddlewareOptions, 'createTelemetryMiddleware'>
95
+
96
+
97
+ // LEGACY TYPES
98
+ /**
99
+ * @deprecated
100
+ */
101
+ export type NextLegacy = (
102
+ request: MiddlewareRequestLegacy,
103
+ response: MiddlewareResponseLegacy
104
+ ) => unknown
105
+
106
+ /**
107
+ * @deprecated
108
+ */
109
+ export type MiddlewareResponseLegacy = {
110
+ resolve(response: JsonObject): void
111
+ reject(error: JsonObject): void
112
+ body?: JsonObject
113
+ error?: HttpErrorType
114
+ statusCode: number
115
+ headers?: JsonObject<string>
116
+ request?: JsonObject
117
+ }
118
+
119
+ /**
120
+ * @deprecated
121
+ */
122
+ export interface ClientRequestLegacy {
123
+ baseUri?: string
124
+ uri?: string
125
+ headers?: VariableMap
126
+ method: MethodType
127
+ uriTemplate?: string
128
+ pathVariables?: VariableMap
129
+ queryParams?: VariableMap
130
+ body?: any,
131
+ }
132
+
133
+ /**
134
+ * @deprecated
135
+ */
136
+ export type MiddlewareLegacy = (next: NextLegacy) => NextLegacy
137
+
138
+ /**
139
+ * @deprecated
140
+ */
141
+ export type MiddlewareRequestLegacy = ClientRequestLegacy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/ts-sdk-apm",
3
- "version": "2.0.0",
3
+ "version": "3.1.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,16 +9,18 @@
9
9
  "private": false,
10
10
  "dependencies": {
11
11
  "@opentelemetry/api": "^1.4.1",
12
- "@opentelemetry/auto-instrumentations-node": "^0.38.0",
13
- "@opentelemetry/exporter-metrics-otlp-http": "^0.41.0",
14
- "@opentelemetry/sdk-node": "^0.41.0",
15
- "uuid": "9.0.0"
12
+ "@opentelemetry/auto-instrumentations-node": "^0.55.0",
13
+ "@opentelemetry/exporter-metrics-otlp-http": "^0.57.0",
14
+ "@opentelemetry/sdk-node": "^0.57.0",
15
+ "dd-trace": "^5.31.0",
16
+ "newrelic": "^12.10.0",
17
+ "uuid": "11.0.4"
16
18
  },
17
19
  "publishConfig": {
18
20
  "access": "public"
19
21
  },
20
22
  "engines": {
21
- "node": ">=14"
23
+ "node": ">=18"
22
24
  },
23
25
  "keywords": [
24
26
  "commercetools",
@@ -51,5 +53,8 @@
51
53
  "organize_imports": "find src -type f -name '*.ts' | xargs organize-imports-cli",
52
54
  "postbuild": "yarn organize_imports",
53
55
  "post_process_generate": "yarn organize_imports"
56
+ },
57
+ "devDependencies": {
58
+ "@types/newrelic": "^9.14.6"
54
59
  }
55
60
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"commercetools-ts-sdk-apm.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}