glide_shared.opentelemetry
OpenTelemetry configuration classes shared between async and sync clients.
OpenTelemetry can only be initialized once per process. Calling OpenTelemetry.init() more than once will be ignored. If you need to change configuration, restart the process with new settings.
OpenTelemetry Configuration
OpenTelemetryConfig: Main configuration object for OpenTelemetry exporters and options.
-
traces: (optional) Configure trace exporting using OpenTelemetryTracesConfig.
-
endpoint: The collector endpoint for traces. Supported protocols: http://, https:// for HTTP/HTTPS, grpc:// for gRPC, file:// for local file export
- sample_percentage: (optional) The percentage of requests to sample (0-100). Defaults to 1. Note: Higher sampling percentages impact performance. Recommended: 1-5% in production.
-
enable_trace_context_propagation: (optional) Whether sampled GLIDE spans use the active OpenTelemetry span as their parent. Defaults to False.
-
metrics: (optional) Configure metrics exporting using OpenTelemetryMetricsConfig.
-
endpoint: The collector endpoint for metrics. Same protocol rules as above.
-
flush_interval_ms: (optional) Interval in milliseconds for flushing data. Defaults to 5000ms.
File Exporter Details
For file:// endpoints:
- Path must start with file:// (e.g., file:///tmp/otel or file:///tmp/otel/traces.json)
- If path is a directory or lacks extension, data is written to signals.json in that directory
- If path includes filename with extension, that file is used as-is
- Parent directory must exist; otherwise initialization fails with InvalidInput error
- If target file exists, new data is appended (not overwritten)
Validation Rules
- flush_interval_ms 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 when calling OpenTelemetry.init()
Trace Context Propagation
When enable_trace_context_propagation is enabled, sampling selects a GLIDE
command, batch or script span, and the application has an active OpenTelemetry span,
GLIDE creates the selected span as its child. The parent is read from the OpenTelemetry
Python API, which propagates the active span through contextvars, so nothing is
passed to GLIDE. Propagation requires the optional opentelemetry-api package and
is disabled by default. Without it, spans are created as independent trace roots.
See the "Trace Context Propagation" section of the Python README for the user-facing
description, including how sample_percentage interacts with the parent span and
where GLIDE's spans are exported.
OpenTelemetryTracesConfig
Configuration for exporting OpenTelemetry traces.
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
OpenTelemetryMetricsConfig
Configuration for exporting OpenTelemetry metrics.
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
185 186 187 188 189 190 191 192 | |
OpenTelemetryConfig
Configuration for OpenTelemetry integration.
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
OpenTelemetry
Singleton class for managing OpenTelemetry configuration and operations.
This class provides a centralized way to initialize OpenTelemetry and control sampling behavior at runtime.
Example usage::
from glide import OpenTelemetry, OpenTelemetryConfig, OpenTelemetryTracesConfig, OpenTelemetryMetricsConfig
OpenTelemetry.init(OpenTelemetryConfig(
traces=OpenTelemetryTracesConfig(
endpoint="http://localhost:4318/v1/traces",
sample_percentage=10
),
metrics=OpenTelemetryMetricsConfig(
endpoint="http://localhost:4318/v1/metrics"
),
flush_interval_ms=1000
))
Note
OpenTelemetry can only be initialized once per process. Subsequent calls to init() will be ignored. This is by design, as OpenTelemetry is a global resource that should be configured once at application startup.
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
init(config)
classmethod
Initialize OpenTelemetry with the given configuration.
This method can only be called once per process. Subsequent calls will log a warning and be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
OpenTelemetryConfig
|
The OpenTelemetry configuration specifying trace/metrics endpoints and flush intervals. |
required |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If the underlying FFI initialization fails (e.g., invalid endpoint or file path). |
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
is_initialized()
classmethod
Check whether OpenTelemetry has been initialized.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if init() has been successfully called, False otherwise. |
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
329 330 331 332 333 334 335 336 | |
is_tracing_enabled()
classmethod
Check whether trace exporting was successfully initialized.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if OpenTelemetry is initialized with traces configured. |
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
338 339 340 341 342 343 344 345 346 347 348 349 | |
get_sample_percentage()
classmethod
Get the current trace sampling percentage.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Optional[int]: The sampling percentage (0-100), or None if traces are not configured. |
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
351 352 353 354 355 356 357 358 359 360 | |
should_sample()
classmethod
Determine whether the current request should be sampled.
Uses random sampling based on the configured sample percentage.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the request should be traced, False otherwise. Always returns False if OpenTelemetry is not initialized. |
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
set_sample_percentage(percentage)
classmethod
Update the trace sampling percentage at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percentage
|
int
|
The new sampling percentage (0-100). |
required |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If traces are not initialized or percentage is out of range. |
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/opentelemetry.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |