@opentelemetry/instrumentation-ioredis 0.23.0 → 0.27.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 +35 -0
- package/README.md +6 -4
- package/build/src/index.js.map +1 -0
- package/build/src/instrumentation.d.ts +2 -0
- package/build/src/instrumentation.js +93 -2
- package/build/src/instrumentation.js.map +1 -0
- package/build/src/types.js.map +1 -0
- package/build/src/utils.d.ts +6 -5
- package/build/src/utils.js +3 -92
- package/build/src/utils.js.map +1 -0
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -0
- package/package.json +20 -15
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.27.0](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.26.0...instrumentation-ioredis-v0.27.0) (2021-11-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* use latest instrumentation base ([#769](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/769)) ([7aff23e](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/7aff23ebebbe209fa3b78c2e7f513c9cd2231be4))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* devDependencies
|
|
15
|
+
* @opentelemetry/contrib-test-utils bumped from ^0.27.0 to ^0.28.0
|
|
16
|
+
|
|
17
|
+
## [0.26.0](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.25.0...instrumentation-ioredis-v0.26.0) (2021-10-22)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* support API and SDK 1.0 ([#706](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/706)) ([096b694](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/096b694bbc3079f0ab4ee0462869b10eb8185202))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* Add support for setConfig in ioredis instrumentation ([#689](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/689)) ([314c890](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/314c89050a2db231047914f2052eda689b49333c))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Dependencies
|
|
32
|
+
|
|
33
|
+
* The following workspace dependencies were updated
|
|
34
|
+
* devDependencies
|
|
35
|
+
* @opentelemetry/contrib-test-utils bumped from ^0.25.0 to ^0.27.0
|
package/README.md
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
This module provides automatic instrumentation for [`ioredis`](https://github.com/luin/ioredis).
|
|
9
9
|
|
|
10
10
|
For automatic instrumentation see the
|
|
11
|
-
[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package.
|
|
11
|
+
[@opentelemetry/sdk-trace-node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package.
|
|
12
|
+
|
|
13
|
+
Compatible with OpenTelemetry JS API and SDK `1.0+`.
|
|
12
14
|
|
|
13
15
|
## Installation
|
|
14
16
|
|
|
@@ -25,11 +27,11 @@ npm install --save @opentelemetry/instrumentation-ioredis
|
|
|
25
27
|
To load a specific instrumentation (**ioredis** in this case), specify it in the registerInstrumentations's configuration
|
|
26
28
|
|
|
27
29
|
```javascript
|
|
28
|
-
const { NodeTracerProvider } = require(
|
|
30
|
+
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
|
|
29
31
|
const {
|
|
30
32
|
IORedisInstrumentation,
|
|
31
|
-
} = require(
|
|
32
|
-
const { registerInstrumentations } = require(
|
|
33
|
+
} = require('@opentelemetry/instrumentation-ioredis');
|
|
34
|
+
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
|
|
33
35
|
|
|
34
36
|
const provider = new NodeTracerProvider();
|
|
35
37
|
provider.register();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,oDAAkC"}
|
|
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.IORedisInstrumentation = void 0;
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
20
|
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
21
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
22
|
+
const instrumentation_2 = require("@opentelemetry/instrumentation");
|
|
21
23
|
const utils_1 = require("./utils");
|
|
22
24
|
const version_1 = require("./version");
|
|
23
25
|
const DEFAULT_CONFIG = {
|
|
@@ -26,6 +28,95 @@ const DEFAULT_CONFIG = {
|
|
|
26
28
|
class IORedisInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
27
29
|
constructor(_config = {}) {
|
|
28
30
|
super('@opentelemetry/instrumentation-ioredis', version_1.VERSION, Object.assign({}, DEFAULT_CONFIG, _config));
|
|
31
|
+
this.traceSendCommand = (original, moduleVersion) => {
|
|
32
|
+
const instrumentation = this;
|
|
33
|
+
return function (cmd) {
|
|
34
|
+
if (arguments.length < 1 || typeof cmd !== 'object') {
|
|
35
|
+
return original.apply(this, arguments);
|
|
36
|
+
}
|
|
37
|
+
const config = instrumentation.getConfig();
|
|
38
|
+
const dbStatementSerializer = (config === null || config === void 0 ? void 0 : config.dbStatementSerializer) || utils_1.defaultDbStatementSerializer;
|
|
39
|
+
const hasNoParentSpan = api_1.trace.getSpan(api_1.context.active()) === undefined;
|
|
40
|
+
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) {
|
|
41
|
+
return original.apply(this, arguments);
|
|
42
|
+
}
|
|
43
|
+
const span = instrumentation.tracer.startSpan(cmd.name, {
|
|
44
|
+
kind: api_1.SpanKind.CLIENT,
|
|
45
|
+
attributes: {
|
|
46
|
+
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: IORedisInstrumentation.DB_SYSTEM,
|
|
47
|
+
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: dbStatementSerializer(cmd.name, cmd.args),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (config === null || config === void 0 ? void 0 : config.requestHook) {
|
|
51
|
+
instrumentation_2.safeExecuteInTheMiddle(() => config === null || config === void 0 ? void 0 : config.requestHook(span, {
|
|
52
|
+
moduleVersion,
|
|
53
|
+
cmdName: cmd.name,
|
|
54
|
+
cmdArgs: cmd.args,
|
|
55
|
+
}), e => {
|
|
56
|
+
if (e) {
|
|
57
|
+
api_1.diag.error('ioredis instrumentation: request hook failed', e);
|
|
58
|
+
}
|
|
59
|
+
}, true);
|
|
60
|
+
}
|
|
61
|
+
const { host, port } = this.options;
|
|
62
|
+
span.setAttributes({
|
|
63
|
+
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host,
|
|
64
|
+
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port,
|
|
65
|
+
[semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: `redis://${host}:${port}`,
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
const result = original.apply(this, arguments);
|
|
69
|
+
const origResolve = cmd.resolve;
|
|
70
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
71
|
+
cmd.resolve = function (result) {
|
|
72
|
+
instrumentation_2.safeExecuteInTheMiddle(() => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.responseHook) === null || _a === void 0 ? void 0 : _a.call(config, span, cmd.name, cmd.args, result); }, e => {
|
|
73
|
+
if (e) {
|
|
74
|
+
api_1.diag.error('ioredis instrumentation: response hook failed', e);
|
|
75
|
+
}
|
|
76
|
+
}, true);
|
|
77
|
+
utils_1.endSpan(span, null);
|
|
78
|
+
origResolve(result);
|
|
79
|
+
};
|
|
80
|
+
const origReject = cmd.reject;
|
|
81
|
+
cmd.reject = function (err) {
|
|
82
|
+
utils_1.endSpan(span, err);
|
|
83
|
+
origReject(err);
|
|
84
|
+
};
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
utils_1.endSpan(span, error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
this.traceConnection = (original) => {
|
|
94
|
+
const instrumentation = this;
|
|
95
|
+
return function () {
|
|
96
|
+
const span = instrumentation.tracer.startSpan('connect', {
|
|
97
|
+
kind: api_1.SpanKind.CLIENT,
|
|
98
|
+
attributes: {
|
|
99
|
+
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: IORedisInstrumentation.DB_SYSTEM,
|
|
100
|
+
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: 'connect',
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const { host, port } = this.options;
|
|
104
|
+
span.setAttributes({
|
|
105
|
+
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host,
|
|
106
|
+
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port,
|
|
107
|
+
[semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: `redis://${host}:${port}`,
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
const client = original.apply(this, arguments);
|
|
111
|
+
utils_1.endSpan(span, null);
|
|
112
|
+
return client;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
utils_1.endSpan(span, error);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
29
120
|
}
|
|
30
121
|
init() {
|
|
31
122
|
return [
|
|
@@ -54,12 +145,12 @@ class IORedisInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
54
145
|
*/
|
|
55
146
|
_patchSendCommand(moduleVersion) {
|
|
56
147
|
return (original) => {
|
|
57
|
-
return
|
|
148
|
+
return this.traceSendCommand(original, moduleVersion);
|
|
58
149
|
};
|
|
59
150
|
}
|
|
60
151
|
_patchConnection() {
|
|
61
152
|
return (original) => {
|
|
62
|
-
return
|
|
153
|
+
return this.traceConnection(original);
|
|
63
154
|
};
|
|
64
155
|
}
|
|
65
156
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAAoE;AAEpE,oEAIwC;AAExC,8EAAyE;AACzE,oEAAwE;AACxE,mCAAgE;AAChE,uCAAoC;AAEpC,MAAM,cAAc,GAAiC;IACnD,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,MAAa,sBAAuB,SAAQ,qCAE3C;IAGC,YAAY,UAAwC,EAAE;QACpD,KAAK,CACH,wCAAwC,EACxC,iBAAO,EACP,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,CAC3C,CAAC;QAqDI,qBAAgB,GAAG,CAAC,QAAkB,EAAE,aAAsB,EAAE,EAAE;YACxE,MAAM,eAAe,GAAG,IAAI,CAAC;YAC7B,OAAO,UAAoC,GAAoB;gBAC7D,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;oBACnD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;iBACxC;gBACD,MAAM,MAAM,GACV,eAAe,CAAC,SAAS,EAAkC,CAAC;gBAC9D,MAAM,qBAAqB,GACzB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,qBAAqB,KAAI,oCAA4B,CAAC;gBAEhE,MAAM,eAAe,GAAG,WAAK,CAAC,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import {
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="mocha" />
|
|
3
|
+
import { Span } from '@opentelemetry/api';
|
|
4
|
+
import { DbStatementSerializer } from './types';
|
|
5
|
+
export declare const endSpan: (span: Span, err: NodeJS.ErrnoException | null | undefined) => void;
|
|
6
|
+
export declare const defaultDbStatementSerializer: DbStatementSerializer;
|
|
6
7
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/src/utils.js
CHANGED
|
@@ -15,11 +15,8 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.defaultDbStatementSerializer = exports.endSpan = void 0;
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
|
-
const _1 = require("./");
|
|
21
|
-
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
22
|
-
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
23
20
|
const endSpan = (span, err) => {
|
|
24
21
|
if (err) {
|
|
25
22
|
span.recordException(err);
|
|
@@ -30,95 +27,9 @@ const endSpan = (span, err) => {
|
|
|
30
27
|
}
|
|
31
28
|
span.end();
|
|
32
29
|
};
|
|
33
|
-
|
|
34
|
-
return function () {
|
|
35
|
-
const span = tracer.startSpan('connect', {
|
|
36
|
-
kind: api_1.SpanKind.CLIENT,
|
|
37
|
-
attributes: {
|
|
38
|
-
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: _1.IORedisInstrumentation.DB_SYSTEM,
|
|
39
|
-
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: 'connect',
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
const { host, port } = this.options;
|
|
43
|
-
span.setAttributes({
|
|
44
|
-
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host,
|
|
45
|
-
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port,
|
|
46
|
-
[semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: `redis://${host}:${port}`,
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
const client = original.apply(this, arguments);
|
|
50
|
-
endSpan(span, null);
|
|
51
|
-
return client;
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
endSpan(span, error);
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
exports.traceConnection = traceConnection;
|
|
30
|
+
exports.endSpan = endSpan;
|
|
60
31
|
const defaultDbStatementSerializer = (cmdName, cmdArgs) => Array.isArray(cmdArgs) && cmdArgs.length
|
|
61
32
|
? `${cmdName} ${cmdArgs.join(' ')}`
|
|
62
33
|
: cmdName;
|
|
63
|
-
|
|
64
|
-
const dbStatementSerializer = (config === null || config === void 0 ? void 0 : config.dbStatementSerializer) || defaultDbStatementSerializer;
|
|
65
|
-
return function (cmd) {
|
|
66
|
-
if (arguments.length < 1 || typeof cmd !== 'object') {
|
|
67
|
-
return original.apply(this, arguments);
|
|
68
|
-
}
|
|
69
|
-
const hasNoParentSpan = api_1.trace.getSpan(api_1.context.active()) === undefined;
|
|
70
|
-
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) {
|
|
71
|
-
return original.apply(this, arguments);
|
|
72
|
-
}
|
|
73
|
-
const span = tracer.startSpan(cmd.name, {
|
|
74
|
-
kind: api_1.SpanKind.CLIENT,
|
|
75
|
-
attributes: {
|
|
76
|
-
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: _1.IORedisInstrumentation.DB_SYSTEM,
|
|
77
|
-
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: dbStatementSerializer(cmd.name, cmd.args),
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
if (config === null || config === void 0 ? void 0 : config.requestHook) {
|
|
81
|
-
instrumentation_1.safeExecuteInTheMiddle(() => config === null || config === void 0 ? void 0 : config.requestHook(span, {
|
|
82
|
-
moduleVersion,
|
|
83
|
-
cmdName: cmd.name,
|
|
84
|
-
cmdArgs: cmd.args,
|
|
85
|
-
}), e => {
|
|
86
|
-
if (e) {
|
|
87
|
-
api_1.diag.error('ioredis instrumentation: request hook failed', e);
|
|
88
|
-
}
|
|
89
|
-
}, true);
|
|
90
|
-
}
|
|
91
|
-
const { host, port } = this.options;
|
|
92
|
-
span.setAttributes({
|
|
93
|
-
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: host,
|
|
94
|
-
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: port,
|
|
95
|
-
[semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: `redis://${host}:${port}`,
|
|
96
|
-
});
|
|
97
|
-
try {
|
|
98
|
-
const result = original.apply(this, arguments);
|
|
99
|
-
const origResolve = cmd.resolve;
|
|
100
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
101
|
-
cmd.resolve = function (result) {
|
|
102
|
-
instrumentation_1.safeExecuteInTheMiddle(() => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.responseHook) === null || _a === void 0 ? void 0 : _a.call(config, span, cmd.name, cmd.args, result); }, e => {
|
|
103
|
-
if (e) {
|
|
104
|
-
api_1.diag.error('ioredis instrumentation: response hook failed', e);
|
|
105
|
-
}
|
|
106
|
-
}, true);
|
|
107
|
-
endSpan(span, null);
|
|
108
|
-
origResolve(result);
|
|
109
|
-
};
|
|
110
|
-
const origReject = cmd.reject;
|
|
111
|
-
cmd.reject = function (err) {
|
|
112
|
-
endSpan(span, err);
|
|
113
|
-
origReject(err);
|
|
114
|
-
};
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
endSpan(span, error);
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
exports.traceSendCommand = traceSendCommand;
|
|
34
|
+
exports.defaultDbStatementSerializer = defaultDbStatementSerializer;
|
|
124
35
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0D;AAGnD,MAAM,OAAO,GAAG,CACrB,IAAU,EACV,GAA6C,EAC7C,EAAE;IACF,IAAI,GAAG,EAAE;QACP,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,oBAAc,CAAC,KAAK;YAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC,CAAC;KACJ;IACD,IAAI,CAAC,GAAG,EAAE,CAAC;AACb,CAAC,CAAC;AAZW,QAAA,OAAO,WAYlB;AAEK,MAAM,4BAA4B,GAA0B,CACjE,OAAO,EACP,OAAO,EACP,EAAE,CACF,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM;IACtC,CAAC,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;IACnC,CAAC,CAAC,OAAO,CAAC;AAND,QAAA,4BAA4B,gCAM3B"}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.27.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/instrumentation-ioredis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "OpenTelemetry ioredis automatic instrumentation package.",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"types": "build/src/index.d.ts",
|
|
@@ -9,11 +9,14 @@
|
|
|
9
9
|
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
|
|
10
10
|
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
|
|
11
11
|
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
|
|
12
|
+
"test-all-versions": "tav",
|
|
13
|
+
"test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions",
|
|
12
14
|
"tdd": "npm run test -- --watch-extensions ts --watch",
|
|
13
15
|
"clean": "rimraf build/*",
|
|
14
16
|
"lint": "eslint . --ext .ts",
|
|
15
17
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
16
|
-
"precompile": "tsc --version",
|
|
18
|
+
"precompile": "tsc --version && lerna run version --scope @opentelemetry/instrumentation-ioredis --include-filtered-dependencies",
|
|
19
|
+
"prewatch": "npm run precompile",
|
|
17
20
|
"version:update": "node ../../../scripts/version-update.js",
|
|
18
21
|
"compile": "npm run version:update && tsc -p .",
|
|
19
22
|
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
|
|
@@ -35,6 +38,7 @@
|
|
|
35
38
|
},
|
|
36
39
|
"files": [
|
|
37
40
|
"build/src/**/*.js",
|
|
41
|
+
"build/src/**/*.js.map",
|
|
38
42
|
"build/src/**/*.d.ts",
|
|
39
43
|
"doc",
|
|
40
44
|
"LICENSE",
|
|
@@ -44,30 +48,31 @@
|
|
|
44
48
|
"access": "public"
|
|
45
49
|
},
|
|
46
50
|
"peerDependencies": {
|
|
47
|
-
"@opentelemetry/api": "^1.0.
|
|
51
|
+
"@opentelemetry/api": "^1.0.2"
|
|
48
52
|
},
|
|
49
53
|
"devDependencies": {
|
|
50
|
-
"@opentelemetry/api": "1.0.
|
|
51
|
-
"@opentelemetry/context-async-hooks": "0.
|
|
52
|
-
"@opentelemetry/
|
|
53
|
-
"@opentelemetry/
|
|
54
|
-
"@opentelemetry/
|
|
54
|
+
"@opentelemetry/api": "1.0.2",
|
|
55
|
+
"@opentelemetry/context-async-hooks": "1.0.1",
|
|
56
|
+
"@opentelemetry/contrib-test-utils": "^0.28.0",
|
|
57
|
+
"@opentelemetry/sdk-trace-base": "1.0.1",
|
|
58
|
+
"@opentelemetry/sdk-trace-node": "1.0.1",
|
|
55
59
|
"@types/mocha": "7.0.2",
|
|
56
|
-
"@types/node": "14.17.
|
|
57
|
-
"codecov": "3.8.
|
|
60
|
+
"@types/node": "14.17.9",
|
|
61
|
+
"codecov": "3.8.3",
|
|
58
62
|
"cross-env": "7.0.3",
|
|
59
63
|
"gts": "3.1.0",
|
|
60
|
-
"ioredis": "4.27.
|
|
64
|
+
"ioredis": "4.27.7",
|
|
61
65
|
"mocha": "7.2.0",
|
|
62
66
|
"nyc": "15.1.0",
|
|
63
67
|
"rimraf": "3.0.2",
|
|
68
|
+
"test-all-versions": "5.0.1",
|
|
64
69
|
"ts-mocha": "8.0.0",
|
|
65
70
|
"typescript": "4.3.5"
|
|
66
71
|
},
|
|
67
72
|
"dependencies": {
|
|
68
|
-
"@opentelemetry/instrumentation": "^0.
|
|
69
|
-
"@opentelemetry/semantic-conventions": "^0.
|
|
70
|
-
"@types/ioredis": "4.26.
|
|
73
|
+
"@opentelemetry/instrumentation": "^0.27.0",
|
|
74
|
+
"@opentelemetry/semantic-conventions": "^1.0.0",
|
|
75
|
+
"@types/ioredis": "4.26.6"
|
|
71
76
|
},
|
|
72
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "45f84dcd2fe01db242fd0efed293db685b9fd9f3"
|
|
73
78
|
}
|