From fed7e38c381568e253a6c367024b23441223ee96 Mon Sep 17 00:00:00 2001 From: Noemi Date: Wed, 18 May 2022 18:10:15 +0200 Subject: [PATCH] docs(instrumentation-redis): add instrumentation options --- .../README.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/node/opentelemetry-instrumentation-redis/README.md b/plugins/node/opentelemetry-instrumentation-redis/README.md index f60d39ba48..2fe53a5693 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/README.md +++ b/plugins/node/opentelemetry-instrumentation-redis/README.md @@ -43,6 +43,37 @@ registerInstrumentations({ See [examples/redis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/redis) for a short example. +### Redis Instrumentation Options + +Redis instrumentation has a few options available to choose from. You can set the following: + +| Options | Type | Description | +| ----------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | +| `dbStatementSerializer` | `DbStatementSerializer` (function) | Redis instrumentation will serialize the command to the `db.statement` attribute using the specified function. | +| `responseHook` | `RedisResponseCustomAttributeFunction` (function) | Function for adding custom attributes on db response. Receives params: `span, moduleVersion, cmdName, cmdArgs` | +| `requireParentSpan` | `boolean` | Require parent to create redis span, default when unset is false. | + +#### Custom `db.statement` Serializer + +The instrumentation serializes the command into a Span attribute called +`db.statement`. The default serialization sets the attribute to the command +name, without the command arguments. + +It is also possible to define a custom serialization function. The function +will receive the command name and arguments and must return a string. + +Here is a simple example to serialize the command name and arguments: + +```javascript +const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis'); + +const redisInstrumentation = new RedisInstrumentation({ + dbStatementSerializer: function (cmdName, cmdArgs) { + return [cmdName, ...cmdArgs].join(" "); + }, +}); +``` + ## Useful links - For more information on OpenTelemetry, visit: