Configure OpenTelemetry
Valkey GLIDE 2.0 introduces support for OpenTelemetry (OTel), enabling developers to gain deep insights into client-side performance and behavior in distributed systems.
Getting Started
Section titled “Getting Started”To begin collecting telemetry data with GLIDE 2.0:
- Set up an OpenTelemetry Collector to receive trace and metric data.
- Configure the GLIDE client with the endpoint to your collector.
- Alternatively, you can configure GLIDE to export telemetry data directly to a local file for development or debugging purposes, without requiring a running collector.
GLIDE does not export data directly to third-party services—instead, it sends data to your collector, which routes it to your backend (e.g., CloudWatch, Prometheus, Jaeger).
Example
Section titled “Example”from glide import OpenTelemetry, OpenTelemetryConfig, OpenTelemetryTracesConfig, OpenTelemetryMetricsConfig
OpenTelemetry.init(OpenTelemetryConfig( traces=OpenTelemetryTracesConfig( endpoint="http://localhost:4318/v1/traces", sample_percentage=10 # Optional, defaults to 1. Can also be changed at runtime via set_sample_percentage(). ), metrics=OpenTelemetryMetricsConfig( endpoint="http://localhost:4318/v1/metrics" ), flush_interval_ms=1000 # Optional, defaults to 5000))import glide.api.OpenTelemetry;
OpenTelemetry.init( OpenTelemetry.OpenTelemetryConfig.builder() .traces( OpenTelemetry.TracesConfig.builder() .endpoint("http://localhost:4318/v1/traces") .samplePercentage(10) // Optional, defaults to 1. Can also be changed at runtime via setSamplePercentage(). .build() ) .metrics( OpenTelemetry.MetricsConfig.builder() .endpoint("http://localhost:4318/v1/metrics") .build() ) .flushIntervalMs(1000L) // Optional, defaults to 5000 .build());import { OpenTelemetry, OpenTelemetryConfig, OpenTelemetryTracesConfig, OpenTelemetryMetricsConfig } from "@valkey/valkey-glide";
// Define traces configurationconst tracesConfig: OpenTelemetryTracesConfig = { endpoint: "http://localhost:4318/v1/traces", samplePercentage: 10 // Optional, defaults to 1%};
// Define metrics configurationconst metricsConfig: OpenTelemetryMetricsConfig = { endpoint: "http://localhost:4318/v1/metrics"};
// Complete OpenTelemetry configurationconst openTelemetryConfig: OpenTelemetryConfig = { traces: tracesConfig, // Optional: can omit if only metrics are needed metrics: metricsConfig, // Optional: can omit if only traces are needed flushIntervalMs: 1000 // Optional, defaults to 5000 ms};
// Initialize OpenTelemetry (can only be called once per process)OpenTelemetry.init(openTelemetryConfig);import "github.com/valkey-io/valkey-glide/go/v2"
interval := int64(1000)config := glide.OpenTelemetryConfig{ Traces: &glide.OpenTelemetryTracesConfig{ Endpoint: "http://localhost:4318/v1/traces", SamplePercentage: 10, // Optional, defaults to 1. Can also be changed at runtime via `SetSamplePercentage()` }, Metrics: &glide.OpenTelemetryMetricsConfig{ Endpoint: "http://localhost:4318/v1/metrics", }, FlushIntervalMs: &interval, // Optional, defaults to 5000}err := glide.GetOtelInstance().Init(config)if err != nil { log.Fatalf("Failed to initialize OpenTelemetry: %v", err)}Configuration Options
Section titled “Configuration Options”When initializing OpenTelemetry, you can customize behavior using the configuration object.
| Configuration | Type | Required | Default | Description |
|---|---|---|---|---|
| traces.endpoint | String | Yes (if traces enabled) | - | The trace collector endpoint URL. Supports http://, https://, grpc://, or file:// protocols. |
| traces.samplePercentage | Integer | No | 1 | Percentage (0–100) of commands to sample for tracing. For production, a low sampling rate (1–5%) is recommended to balance performance and insight. Can be changed at runtime. |
| metrics.endpoint | String | Yes (if metrics enabled) | - | The metrics collector endpoint URL. Supports http://, https://, grpc://, or file:// protocols. |
| flushIntervalMs | Integer | No | 5000 | Time in milliseconds between flushes to the collector. Must be a positive integer. |
Supported Collector Protocols
Section titled “Supported Collector Protocols”You can configure the OTel collector endpoint using one of the following protocols:
http://orhttps://- Send data via HTTP(S)grpc://- Use gRPC for efficient telemetry transmissionfile://- Write telemetry data to a local file (ideal for local dev/debugging)
File Exporter Details
Section titled “File Exporter Details”If using file:// as the endpoint:
- The path must begin with
file://. - If a directory is provided (or no file extension), data is written to
signals.jsonin that directory. - If a filename is included, it will be used as-is.
- The parent directory must already exist.
- Data is appended, not overwritten.
Validation Rules
Section titled “Validation Rules”- Flush interval must be a positive integer.
- Sample percentage must be between 0 and 100.
- File exporter paths must start with
file://and have an existing parent directory. - Invalid configuration will throw an error synchronously when calling initialization.