Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: add forgotten changes
  • Loading branch information
Amir Blum committed Nov 2, 2020
commit 8faabe889c15748397066e7d785e6cb8836e3d66
1 change: 1 addition & 0 deletions plugins/node/opentelemetry-plugin-ioredis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ IORedis plugin has few options available to choose from. You can set the followi
| Options | Type | Description |
| ------- | ---- | ----------- |
| `dbStatementSerializer` | `DbStatementSerializer` | IORedis plugin will serialize db.statement using the specified function. |
| `responseHook` | `RedisResponseCustomAttributeFunction` | Function for adding custom attributes on db response |

#### Custom db.statement Serializer
The plugin serializes the whole command into a Span attribute called `db.statement`. The standard serialization format is `{cmdName} {cmdArgs.join(',')}`.
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/opentelemetry-plugin-ioredis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' -g 'should call responseHook when set in config'",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
"tdd": "npm run test -- --watch-extensions ts --watch",
Expand Down
29 changes: 26 additions & 3 deletions plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,45 @@ describe('ioredis', () => {

describe('Instrumenting with a custom responseHook', () => {

before(() => {
it(`should call responseHook when set in config`, async () => {
plugin.disable();
const config: IoredisPluginConfig = {
responseHook: (span: Span, cmdName: string, cmdArgs: Array<string | Buffer | number>, response: any) => {
console.log(cmdName);
assert.strictEqual(cmdName, 'incr');
// the command is 'incr' on a key which does not exist, thus it increase 0 by 1 and respond 1
assert.strictEqual(response, 1);
span.setAttribute('attribute key from hook', 'custom value from hook');
},
};
plugin.enable(ioredis, provider, new NoopLogger(), config);

const span = provider
.getTracer('ioredis-test')
.startSpan('test span');
await provider.getTracer('ioredis-test').withSpan(span, async () => {
await client.incr('new-key');
const endedSpans = memoryExporter.getFinishedSpans();
assert.strictEqual(endedSpans.length, 1);
assert.strictEqual(endedSpans[0].attributes['attribute key from hook'], 'custom value from hook');
});
});

it(`should call responseHook when set in config`, async () => {
it(`should call ignore responseHook which throws`, async () => {
plugin.disable();
const config: IoredisPluginConfig = {
responseHook: (span: Span, cmdName: string, cmdArgs: Array<string | Buffer | number>, response: any) => {
throw Error('error thrown in responseHook');
},
};
plugin.enable(ioredis, provider, new NoopLogger(), config);

const span = provider
.getTracer('ioredis-test')
.startSpan('test span');
await provider.getTracer('ioredis-test').withSpan(span, async () => {
await client.incr('new-key');
const endedSpans = memoryExporter.getFinishedSpans();
assert.strictEqual(endedSpans.length, 1);
});
});

Expand Down