Socket
Socket
Sign inDemoInstall

@opentelemetry/instrumentation-ioredis

Package Overview
Dependencies
Maintainers
4
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-ioredis - npm Package Compare versions

Comparing version 0.13.1 to 0.14.0

1

build/src/ioredis.d.ts

@@ -5,3 +5,2 @@ import type * as ioredisTypes from 'ioredis';

export declare class IORedisInstrumentation extends InstrumentationBase<typeof ioredisTypes> {
protected _config: IORedisInstrumentationConfig;
static readonly DB_SYSTEM = "redis";

@@ -8,0 +7,0 @@ readonly supportedVersions: string[];

11

build/src/ioredis.js

@@ -19,9 +19,12 @@ "use strict";

exports.IORedisInstrumentation = void 0;
const api_1 = require("@opentelemetry/api");
const instrumentation_1 = require("@opentelemetry/instrumentation");
const utils_1 = require("./utils");
const version_1 = require("./version");
const DEFAULT_CONFIG = {
requireParentSpan: true,
};
class IORedisInstrumentation extends instrumentation_1.InstrumentationBase {
constructor(_config = {}) {
super('@opentelemetry/instrumentation-ioredis', version_1.VERSION, _config);
this._config = _config;
super('@opentelemetry/instrumentation-ioredis', version_1.VERSION, Object.assign({}, DEFAULT_CONFIG, _config));
this.supportedVersions = ['>1 <5'];

@@ -32,3 +35,3 @@ }

new instrumentation_1.InstrumentationNodeModuleDefinition('ioredis', this.supportedVersions, moduleExports => {
this._logger.debug('Applying patch for ioredis');
api_1.diag.debug('Applying patch for ioredis');
if (instrumentation_1.isWrapped(moduleExports.prototype.sendCommand)) {

@@ -46,3 +49,3 @@ this._unwrap(moduleExports.prototype, 'sendCommand');

return;
this._logger.debug('Removing patch for ioredis');
api_1.diag.debug('Removing patch for ioredis');
this._unwrap(moduleExports.prototype, 'sendCommand');

@@ -49,0 +52,0 @@ this._unwrap(moduleExports.prototype, 'connect');

/// <reference types="node" />
import type * as ioredisTypes from 'ioredis';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { Span } from '@opentelemetry/api';
export interface IORedisCommand {

@@ -21,2 +22,14 @@ reject: (err: Error) => void;

/**
* Function that can be used to add custom attributes to span on response from redis server
* @param span - The span created for the redis command, on which attributes can be set
* @param cmdName - The name of the command (eg. set, get, mset)
* @param cmdArgs - Array of arguments passed to the command
* @param response - The response object which is returned to the user who called this command.
* Can be used to set custom attributes on the span.
* The type of the response varies depending on the specific command.
*/
export interface RedisResponseCustomAttributeFunction {
(span: Span, cmdName: IORedisCommand['name'], cmdArgs: IORedisCommand['args'], response: unknown): void;
}
/**
* Options available for the IORedis Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-ioredis#ioredis-instrumentation-options))

@@ -27,3 +40,7 @@ */

dbStatementSerializer?: DbStatementSerializer;
/** Function for adding custom attributes on db response */
responseHook?: RedisResponseCustomAttributeFunction;
/** Require parent to create ioredis span, default when unset is true */
requireParentSpan?: boolean;
}
//# sourceMappingURL=types.d.ts.map

@@ -22,2 +22,3 @@ "use strict";

const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const instrumentation_1 = require("@opentelemetry/instrumentation");
const endSpan = (span, err) => {

@@ -27,3 +28,3 @@ if (err) {

span.setStatus({
code: api_1.StatusCode.ERROR,
code: api_1.SpanStatusCode.ERROR,
message: err.message,

@@ -69,4 +70,4 @@ });

}
// Do not trace if there is not parent span
if (api_1.getSpan(api_1.context.active()) === undefined) {
const hasNoParentSpan = api_1.getSpan(api_1.context.active()) === undefined;
if ((config === null || config === void 0 ? void 0 : config.requireParentSpan) === true && hasNoParentSpan) {
return original.apply(this, arguments);

@@ -92,2 +93,7 @@ }

cmd.resolve = function (result) {
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 => {
if (e) {
api_1.diag.error('ioredis response hook failed', e);
}
}, true);
endSpan(span, null);

@@ -94,0 +100,0 @@ origResolve(result);

@@ -1,2 +0,2 @@

export declare const VERSION = "0.13.1";
export declare const VERSION = "0.14.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.13.1';
exports.VERSION = '0.14.0';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/instrumentation-ioredis",
"version": "0.13.1",
"version": "0.14.0",
"description": "OpenTelemetry ioredis automatic instrumentation package.",

@@ -47,6 +47,6 @@ "main": "build/src/index.js",

"devDependencies": {
"@opentelemetry/context-async-hooks": "0.15.0",
"@opentelemetry/node": "0.15.0",
"@opentelemetry/test-utils": "^0.13.1",
"@opentelemetry/tracing": "0.15.0",
"@opentelemetry/context-async-hooks": "0.18.0",
"@opentelemetry/node": "0.18.0",
"@opentelemetry/test-utils": "^0.14.0",
"@opentelemetry/tracing": "0.18.0",
"@types/ioredis": "4.17.3",

@@ -70,7 +70,7 @@ "@types/mocha": "7.0.2",

"dependencies": {
"@opentelemetry/api": "^0.15.0",
"@opentelemetry/instrumentation": "^0.15.0",
"@opentelemetry/semantic-conventions": "^0.15.0"
"@opentelemetry/api": "^0.18.0",
"@opentelemetry/instrumentation": "^0.18.0",
"@opentelemetry/semantic-conventions": "^0.18.0"
},
"gitHead": "fa0700bae22c5e3d6f007b4353ed18f1f53a6c69"
"gitHead": "7a87f4105ff432380132d81f56a33e3f5c4e8fb1"
}

@@ -25,3 +25,3 @@ # OpenTelemetry ioredis Instrumentation for Node.js

To load a specific instrumentation (**ioredis** in this case), specify it in the Node Tracer's configuration
To load a specific instrumentation (**ioredis** in this case), specify it in the registerInstrumentations's configuration

@@ -31,16 +31,22 @@ ```javascript

const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new NodeTracerProvider({
// be sure to disable old plugin
plugins: {
ioredis: { enabled: false, path: '@opentelemetry/plugin-ioredis' }
},
});
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
const ioredisInstrumentation = new IORedisInstrumentation({
// see under for available configuration
});
registerInstrumentations({
instrumentations: [
new IORedisInstrumentation({
// see under for available configuration
}),
{
// be sure to disable old plugin but only if it was installed
plugins: {
ioredis: { enabled: false, path: '@opentelemetry/plugin-ioredis' }
},
}
],
tracerProvider: provider,
})
```

@@ -55,2 +61,4 @@

| `dbStatementSerializer` | `DbStatementSerializer` | IORedis instrumentation will serialize db.statement using the specified function. |
| `responseHook` | `RedisResponseCustomAttributeFunction` | Function for adding custom attributes on db response |
| `requireParentSpan` | `boolean` | Require parent to create ioredis span, default when unset is true |

@@ -57,0 +65,0 @@ #### Custom db.statement Serializer

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc