Skip to content

Commit

Permalink
docs(instrumentation-redis): add instrumentation options (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
unflxw authored May 24, 2022
1 parent 116caab commit 4b36b75
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions plugins/node/opentelemetry-instrumentation-redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://opentelemetry.io/>
Expand Down

0 comments on commit 4b36b75

Please sign in to comment.