Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

@opentelemetry/instrumentation-redis-4

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-redis-4

OpenTelemetry instrumentation for `redis` v4 database client for Redis


Version published
Maintainers
3
Created

What is @opentelemetry/instrumentation-redis-4?

@opentelemetry/instrumentation-redis-4 is an OpenTelemetry instrumentation package for Redis version 4.x. It allows you to automatically collect and report telemetry data from your Redis operations, which can be used for monitoring, tracing, and performance analysis.

What are @opentelemetry/instrumentation-redis-4's main functionalities?

Automatic Tracing

This feature allows you to automatically trace Redis operations. The code sample demonstrates how to set up the OpenTelemetry NodeTracerProvider and register the Redis instrumentation. Once set up, Redis operations like `set` and `get` will be automatically traced.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis-4');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new RedisInstrumentation(),
  ],
});

const redis = require('redis');
const client = redis.createClient();

client.on('error', (err) => console.error('Redis Client Error', err));
client.connect();

client.set('key', 'value');
client.get('key', (err, reply) => {
  console.log(reply); // 'value'
});

Custom Span Attributes

This feature allows you to add custom attributes to spans. The code sample demonstrates how to set up a response hook that adds the length of the Redis response as a custom attribute to the span.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis-4');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new RedisInstrumentation({
      responseHook: (span, response) => {
        span.setAttribute('redis.response_length', response.length);
      },
    }),
  ],
});

const redis = require('redis');
const client = redis.createClient();

client.on('error', (err) => console.error('Redis Client Error', err));
client.connect();

client.set('key', 'value');
client.get('key', (err, reply) => {
  console.log(reply); // 'value'
});

Other packages similar to @opentelemetry/instrumentation-redis-4

FAQs

Package last updated on 05 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts