Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
245d7ee
feat(instrumentation-ioredis): add moduleVersionAttributeName config …
Apr 7, 2021
576233f
Merge remote-tracking branch 'upstream/main' into ioredis-module-vers…
Apr 18, 2021
12ba869
chore(ioredis): type of moduleVersion
Apr 18, 2021
da2eb31
Merge remote-tracking branch 'upstream/main' into ioredis-module-vers…
Apr 25, 2021
ce35c7a
feat(instrumentation-ioredis): convert module version capturing to hook
Apr 25, 2021
077973e
style(instrumentation-ioredis): moduleVersion optional type
Apr 25, 2021
3d06618
fix(instrumentation-ioredis): no assert.match in node 10
Apr 25, 2021
e7db198
docs(instrumentation-ioredis): add request hook signuature to README
Apr 26, 2021
5fbfa93
docs(instrumentation-ioredis): lighter hook params documentation
Apr 26, 2021
0435644
docs(instrumentation-ioredis): add request hook example
Apr 26, 2021
ea1d7b9
docs(instrumentation-ioredis): improve request hook example
Apr 26, 2021
acd1789
Update plugins/node/opentelemetry-instrumentation-ioredis/src/types.ts
blumamir Apr 26, 2021
1dde769
Merge remote-tracking branch 'upstream/main' into ioredis-module-vers…
Apr 26, 2021
14ca036
docs(instrumentation-ioredis): double to single quotes
Apr 26, 2021
4d0a1be
fix(instrumentation-ioredis): update changed interface name everywhere
Apr 26, 2021
a509313
Merge remote-tracking branch 'upstream/main' into ioredis-module-vers…
Apr 26, 2021
2924b56
docs(instrumentation-ioredis): revert change of badge
Apr 26, 2021
b89242e
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
Apr 26, 2021
ec1e3d1
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
Apr 27, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ IORedis instrumentation has few options available to choose from. You can set th
| `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 |
| `moduleVersionAttributeName` | `string` | If passed, a span attribute will be added to all spans with key of the provided "moduleVersionAttributeName" and value of the module version. |

#### Custom db.statement Serializer
The instrumentation serializes the whole command into a Span attribute called `db.statement`. The standard serialization format is `{cmdName} {cmdArgs.join(',')}`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export class IORedisInstrumentation extends InstrumentationBase<
new InstrumentationNodeModuleDefinition<typeof ioredisTypes>(
'ioredis',
this.supportedVersions,
moduleExports => {
(moduleExports, moduleVersion?: string | undefined) => {
diag.debug('Applying patch for ioredis');
if (isWrapped(moduleExports.prototype.sendCommand)) {
this._unwrap(moduleExports.prototype, 'sendCommand');
}
this._wrap(
moduleExports.prototype,
'sendCommand',
this._patchSendCommand()
this._patchSendCommand(moduleVersion)
);
if (isWrapped(moduleExports.prototype.connect)) {
this._unwrap(moduleExports.prototype, 'connect');
Expand All @@ -81,9 +81,14 @@ export class IORedisInstrumentation extends InstrumentationBase<
/**
* Patch send command internal to trace requests
*/
private _patchSendCommand() {
private _patchSendCommand(moduleVersion?: string | undefined) {
return (original: Function) => {
return traceSendCommand(this.tracer, original, this._config);
return traceSendCommand(
this.tracer,
original,
this._config,
moduleVersion
);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ export interface IORedisInstrumentationConfig extends InstrumentationConfig {

/** Require parent to create ioredis span, default when unset is true */
requireParentSpan?: boolean;

/**
* If passed, a span attribute will be added to all spans with key of the provided "moduleVersionAttributeName"
* and value of the module version.
*/
moduleVersionAttributeName?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const defaultDbStatementSerializer: DbStatementSerializer = (
export const traceSendCommand = (
tracer: Tracer,
original: Function,
config?: IORedisInstrumentationConfig
config?: IORedisInstrumentationConfig,
moduleVersion?: string | undefined
) => {
const dbStatementSerializer =
config?.dbStatementSerializer || defaultDbStatementSerializer;
Expand All @@ -110,6 +111,10 @@ export const traceSendCommand = (
},
});

if (config?.moduleVersionAttributeName && moduleVersion) {
span.setAttribute(config?.moduleVersionAttributeName, moduleVersion);
}

const { host, port } = this.options;

span.setAttributes({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ describe('ioredis', () => {
});

describe('Instrumenting query operations', () => {
before(() => {
instrumentation.disable();
instrumentation = new IORedisInstrumentation();
instrumentation.setTracerProvider(provider);
require('ioredis');
});

IOREDIS_CALLBACK_OPERATIONS.forEach(command => {
it(`should create a child span for cb style ${command.description}`, done => {
const attributes = {
Expand Down Expand Up @@ -762,6 +769,28 @@ describe('ioredis', () => {
});
});

it('moduleVersionAttributeName should capture ioredis version', async () => {
const VERSION_ATTR = 'instrumentedmodule.version';
instrumentation.disable();
const config: IORedisInstrumentationConfig = {
moduleVersionAttributeName: VERSION_ATTR,
};
instrumentation = new IORedisInstrumentation(config);
instrumentation.setTracerProvider(provider);
require('ioredis');

const span = provider.getTracer('ioredis-test').startSpan('test span');
await context.with(setSpan(context.active(), span), async () => {
await client.set(testKeyName, 'data');
const endedSpans = memoryExporter.getFinishedSpans();
assert.strictEqual(endedSpans.length, 1);
assert.match(
endedSpans[0].attributes[VERSION_ATTR] as string,
/\d{1,4}\.\d{1,4}\.\d{1,5}.*/
);
});
});

describe('Instrumenting with a custom responseHook', () => {
it('should call responseHook when set in config', async () => {
instrumentation.disable();
Expand Down