@valkey/valkey-glide 1.3.5-rc9 → 2.0.0-rc7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
+ */
4
+ import { OpenTelemetryConfig } from ".";
5
+ /**
6
+ * ⚠️ OpenTelemetry can only be initialized once per process. Calling `OpenTelemetry.init()` more than once will be ignored.
7
+ * If you need to change configuration, restart the process with new settings.
8
+ * ### OpenTelemetry
9
+ *
10
+ * - **openTelemetryConfig**: Use this object to configure OpenTelemetry exporters and options.
11
+ * - **traces**: (optional) Configure trace exporting.
12
+ * - **endpoint**: The collector endpoint for traces. Supported protocols:
13
+ * - `http://` or `https://` for HTTP/HTTPS
14
+ * - `grpc://` for gRPC
15
+ * - `file://` for local file export (see below)
16
+ * - **samplePercentage**: (optional) The percentage of requests to sample and create a span for, used to measure command duration. Must be between 0 and 100. Defaults to 1 if not specified.
17
+ * Note: There is a tradeoff between sampling percentage and performance. Higher sampling percentages will provide more detailed telemetry data but will impact performance.
18
+ * It is recommended to keep this number low (1-5%) in production environments unless you have specific needs for higher sampling rates.
19
+ * - **metrics**: (optional) Configure metrics exporting.
20
+ * - **endpoint**: The collector endpoint for metrics. Same protocol rules as above.
21
+ * - **flushIntervalMs**: (optional) Interval in milliseconds for flushing data to the collector. Must be a positive integer. Defaults to 5000ms if not specified.
22
+ *
23
+ * #### File Exporter Details
24
+ * - For `file://` endpoints:
25
+ * - The path must start with `file://` (e.g., `file:///tmp/otel` or `file:///tmp/otel/traces.json`).
26
+ * - If the path is a directory or lacks a file extension, data is written to `signals.json` in that directory.
27
+ * - If the path includes a filename with an extension, that file is used as-is.
28
+ * - The parent directory must already exist; otherwise, initialization will fail with an InvalidInput error.
29
+ * - If the target file exists, new data is appended (not overwritten).
30
+ *
31
+ * #### Validation Rules
32
+ * - `flushIntervalMs` must be a positive integer.
33
+ * - `samplePercentage` must be between 0 and 100.
34
+ * - File exporter paths must start with `file://` and have an existing parent directory.
35
+ * - Invalid configuration will throw an error synchronously when calling `OpenTelemetry.init()`.
36
+ */
37
+ export declare class OpenTelemetry {
38
+ private static _instance;
39
+ private static openTelemetryConfig;
40
+ /**
41
+ * Singleton class for managing OpenTelemetry configuration and operations.
42
+ * This class provides a centralized way to initialize OpenTelemetry and control
43
+ * sampling behavior at runtime.
44
+ *
45
+ * Example usage:
46
+ * ```typescript
47
+ * import { OpenTelemetry, OpenTelemetryConfig, OpenTelemetryTracesConfig, OpenTelemetryMetricsConfig } from "@valkey/valkey-glide";
48
+ *
49
+ * let tracesConfig: OpenTelemetryTracesConfig = {
50
+ * endpoint: "http://localhost:4318/v1/traces",
51
+ * samplePercentage: 10, // Optional, defaults to 1. Can also be changed at runtime via setSamplePercentage().
52
+ * };
53
+ * let metricsConfig: OpenTelemetryMetricsConfig = {
54
+ * endpoint: "http://localhost:4318/v1/metrics",
55
+ * };
56
+
57
+ * let config : OpenTelemetryConfig = {
58
+ * traces: tracesConfig,
59
+ * metrics: metricsConfig,
60
+ * flushIntervalMs: 1000, // Optional, defaults to 5000
61
+ * };
62
+ * OpenTelemetry.init(config);
63
+ *
64
+ * ```
65
+ *
66
+ * @remarks
67
+ * OpenTelemetry can only be initialized once per process. Subsequent calls to
68
+ * init() will be ignored. This is by design, as OpenTelemetry is a global
69
+ * resource that should be configured once at application startup.
70
+ *
71
+ * Initialize the OpenTelemetry instance
72
+ * @param openTelemetryConfig - The OpenTelemetry configuration
73
+ */
74
+ static init(openTelemetryConfig: OpenTelemetryConfig): void;
75
+ private static internalInit;
76
+ /**
77
+ * Check if the OpenTelemetry instance is initialized
78
+ * @returns True if the OpenTelemetry instance is initialized, false otherwise
79
+ */
80
+ static isInitialized(): boolean;
81
+ /**
82
+ * Get the sample percentage for traces
83
+ * @returns The sample percentage for traces only if OpenTelemetry is initialized and the traces config is set, otherwise undefined.
84
+ */
85
+ static getSamplePercentage(): number | undefined;
86
+ /**
87
+ * Determines if the current request should be sampled for OpenTelemetry tracing.
88
+ * Uses the configured sample percentage to randomly decide whether to create a span for this request.
89
+ * @returns true if the request should be sampled, false otherwise
90
+ */
91
+ static shouldSample(): boolean;
92
+ /**
93
+ * Set the percentage of requests to be sampled and traced. Must be a value between 0 and 100.
94
+ * This setting only affects traces, not metrics.
95
+ * @param percentage - The sample percentage 0-100
96
+ * @throws Error if OpenTelemetry is not initialized or traces config is not set
97
+ * @remarks
98
+ * This method can be called at runtime to change the sampling percentage without reinitializing OpenTelemetry.
99
+ */
100
+ static setSamplePercentage(percentage: number): void;
101
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OpenTelemetry = void 0;
7
+ const _1 = require(".");
8
+ /**
9
+ * ⚠️ OpenTelemetry can only be initialized once per process. Calling `OpenTelemetry.init()` more than once will be ignored.
10
+ * If you need to change configuration, restart the process with new settings.
11
+ * ### OpenTelemetry
12
+ *
13
+ * - **openTelemetryConfig**: Use this object to configure OpenTelemetry exporters and options.
14
+ * - **traces**: (optional) Configure trace exporting.
15
+ * - **endpoint**: The collector endpoint for traces. Supported protocols:
16
+ * - `http://` or `https://` for HTTP/HTTPS
17
+ * - `grpc://` for gRPC
18
+ * - `file://` for local file export (see below)
19
+ * - **samplePercentage**: (optional) The percentage of requests to sample and create a span for, used to measure command duration. Must be between 0 and 100. Defaults to 1 if not specified.
20
+ * Note: There is a tradeoff between sampling percentage and performance. Higher sampling percentages will provide more detailed telemetry data but will impact performance.
21
+ * It is recommended to keep this number low (1-5%) in production environments unless you have specific needs for higher sampling rates.
22
+ * - **metrics**: (optional) Configure metrics exporting.
23
+ * - **endpoint**: The collector endpoint for metrics. Same protocol rules as above.
24
+ * - **flushIntervalMs**: (optional) Interval in milliseconds for flushing data to the collector. Must be a positive integer. Defaults to 5000ms if not specified.
25
+ *
26
+ * #### File Exporter Details
27
+ * - For `file://` endpoints:
28
+ * - The path must start with `file://` (e.g., `file:///tmp/otel` or `file:///tmp/otel/traces.json`).
29
+ * - If the path is a directory or lacks a file extension, data is written to `signals.json` in that directory.
30
+ * - If the path includes a filename with an extension, that file is used as-is.
31
+ * - The parent directory must already exist; otherwise, initialization will fail with an InvalidInput error.
32
+ * - If the target file exists, new data is appended (not overwritten).
33
+ *
34
+ * #### Validation Rules
35
+ * - `flushIntervalMs` must be a positive integer.
36
+ * - `samplePercentage` must be between 0 and 100.
37
+ * - File exporter paths must start with `file://` and have an existing parent directory.
38
+ * - Invalid configuration will throw an error synchronously when calling `OpenTelemetry.init()`.
39
+ */
40
+ class OpenTelemetry {
41
+ static _instance = null;
42
+ static openTelemetryConfig = null;
43
+ /**
44
+ * Singleton class for managing OpenTelemetry configuration and operations.
45
+ * This class provides a centralized way to initialize OpenTelemetry and control
46
+ * sampling behavior at runtime.
47
+ *
48
+ * Example usage:
49
+ * ```typescript
50
+ * import { OpenTelemetry, OpenTelemetryConfig, OpenTelemetryTracesConfig, OpenTelemetryMetricsConfig } from "@valkey/valkey-glide";
51
+ *
52
+ * let tracesConfig: OpenTelemetryTracesConfig = {
53
+ * endpoint: "http://localhost:4318/v1/traces",
54
+ * samplePercentage: 10, // Optional, defaults to 1. Can also be changed at runtime via setSamplePercentage().
55
+ * };
56
+ * let metricsConfig: OpenTelemetryMetricsConfig = {
57
+ * endpoint: "http://localhost:4318/v1/metrics",
58
+ * };
59
+
60
+ * let config : OpenTelemetryConfig = {
61
+ * traces: tracesConfig,
62
+ * metrics: metricsConfig,
63
+ * flushIntervalMs: 1000, // Optional, defaults to 5000
64
+ * };
65
+ * OpenTelemetry.init(config);
66
+ *
67
+ * ```
68
+ *
69
+ * @remarks
70
+ * OpenTelemetry can only be initialized once per process. Subsequent calls to
71
+ * init() will be ignored. This is by design, as OpenTelemetry is a global
72
+ * resource that should be configured once at application startup.
73
+ *
74
+ * Initialize the OpenTelemetry instance
75
+ * @param openTelemetryConfig - The OpenTelemetry configuration
76
+ */
77
+ static init(openTelemetryConfig) {
78
+ if (!this._instance) {
79
+ this.internalInit(openTelemetryConfig);
80
+ _1.Logger.log("info", "GlideOpenTelemetry", "OpenTelemetry initialized with config: " +
81
+ JSON.stringify(openTelemetryConfig));
82
+ return;
83
+ }
84
+ _1.Logger.log("warn", "GlideOpenTelemetry", "OpenTelemetry already initialized - ignoring new configuration");
85
+ }
86
+ static internalInit(openTelemetryConfig) {
87
+ this.openTelemetryConfig = openTelemetryConfig;
88
+ (0, _1.InitOpenTelemetry)(openTelemetryConfig);
89
+ this._instance = new OpenTelemetry();
90
+ }
91
+ /**
92
+ * Check if the OpenTelemetry instance is initialized
93
+ * @returns True if the OpenTelemetry instance is initialized, false otherwise
94
+ */
95
+ static isInitialized() {
96
+ return this._instance != null;
97
+ }
98
+ /**
99
+ * Get the sample percentage for traces
100
+ * @returns The sample percentage for traces only if OpenTelemetry is initialized and the traces config is set, otherwise undefined.
101
+ */
102
+ static getSamplePercentage() {
103
+ return this.openTelemetryConfig?.traces?.samplePercentage;
104
+ }
105
+ /**
106
+ * Determines if the current request should be sampled for OpenTelemetry tracing.
107
+ * Uses the configured sample percentage to randomly decide whether to create a span for this request.
108
+ * @returns true if the request should be sampled, false otherwise
109
+ */
110
+ static shouldSample() {
111
+ const percentage = this.getSamplePercentage();
112
+ return (this.isInitialized() &&
113
+ percentage !== undefined &&
114
+ Math.random() * 100 < percentage);
115
+ }
116
+ /**
117
+ * Set the percentage of requests to be sampled and traced. Must be a value between 0 and 100.
118
+ * This setting only affects traces, not metrics.
119
+ * @param percentage - The sample percentage 0-100
120
+ * @throws Error if OpenTelemetry is not initialized or traces config is not set
121
+ * @remarks
122
+ * This method can be called at runtime to change the sampling percentage without reinitializing OpenTelemetry.
123
+ */
124
+ static setSamplePercentage(percentage) {
125
+ if (!this.openTelemetryConfig || !this.openTelemetryConfig.traces) {
126
+ throw new _1.ConfigurationError("OpenTelemetry config traces not initialized");
127
+ }
128
+ if (percentage < 0 || percentage > 100) {
129
+ throw new _1.ConfigurationError("Sample percentage must be between 0 and 100");
130
+ }
131
+ this.openTelemetryConfig.traces.samplePercentage = percentage;
132
+ }
133
+ }
134
+ exports.OpenTelemetry = OpenTelemetry;
@@ -1353,6 +1353,9 @@ export namespace command_request {
1353
1353
 
1354
1354
  /** CommandRequest route */
1355
1355
  route?: (command_request.IRoutes|null);
1356
+
1357
+ /** CommandRequest rootSpanPtr */
1358
+ rootSpanPtr?: (number|Long|null);
1356
1359
  }
1357
1360
 
1358
1361
  /** Represents a CommandRequest. */
@@ -1388,9 +1391,15 @@ export namespace command_request {
1388
1391
  /** CommandRequest route. */
1389
1392
  public route?: (command_request.IRoutes|null);
1390
1393
 
1394
+ /** CommandRequest rootSpanPtr. */
1395
+ public rootSpanPtr?: (number|Long|null);
1396
+
1391
1397
  /** CommandRequest command. */
1392
1398
  public command?: ("singleCommand"|"batch"|"scriptInvocation"|"scriptInvocationPointers"|"clusterScan"|"updateConnectionPassword");
1393
1399
 
1400
+ /** CommandRequest _rootSpanPtr. */
1401
+ public _rootSpanPtr?: "rootSpanPtr";
1402
+
1394
1403
  /**
1395
1404
  * Creates a new CommandRequest instance using the specified properties.
1396
1405
  * @param [properties] Properties to set
@@ -1894,84 +1903,6 @@ export namespace connection_request {
1894
1903
  public static getTypeUrl(typeUrlPrefix?: string): string;
1895
1904
  }
1896
1905
 
1897
- /** Properties of an OpenTelemetryConfig. */
1898
- interface IOpenTelemetryConfig {
1899
-
1900
- /** OpenTelemetryConfig collectorEndPoint */
1901
- collectorEndPoint?: (string|null);
1902
-
1903
- /** OpenTelemetryConfig spanFlushInterval */
1904
- spanFlushInterval?: (number|Long|null);
1905
- }
1906
-
1907
- /** Represents an OpenTelemetryConfig. */
1908
- class OpenTelemetryConfig implements IOpenTelemetryConfig {
1909
-
1910
- /**
1911
- * Constructs a new OpenTelemetryConfig.
1912
- * @param [properties] Properties to set
1913
- */
1914
- constructor(properties?: connection_request.IOpenTelemetryConfig);
1915
-
1916
- /** OpenTelemetryConfig collectorEndPoint. */
1917
- public collectorEndPoint: string;
1918
-
1919
- /** OpenTelemetryConfig spanFlushInterval. */
1920
- public spanFlushInterval?: (number|Long|null);
1921
-
1922
- /** OpenTelemetryConfig _spanFlushInterval. */
1923
- public _spanFlushInterval?: "spanFlushInterval";
1924
-
1925
- /**
1926
- * Creates a new OpenTelemetryConfig instance using the specified properties.
1927
- * @param [properties] Properties to set
1928
- * @returns OpenTelemetryConfig instance
1929
- */
1930
- public static create(properties?: connection_request.IOpenTelemetryConfig): connection_request.OpenTelemetryConfig;
1931
-
1932
- /**
1933
- * Encodes the specified OpenTelemetryConfig message. Does not implicitly {@link connection_request.OpenTelemetryConfig.verify|verify} messages.
1934
- * @param message OpenTelemetryConfig message or plain object to encode
1935
- * @param [writer] Writer to encode to
1936
- * @returns Writer
1937
- */
1938
- public static encode(message: connection_request.IOpenTelemetryConfig, writer?: $protobuf.Writer): $protobuf.Writer;
1939
-
1940
- /**
1941
- * Encodes the specified OpenTelemetryConfig message, length delimited. Does not implicitly {@link connection_request.OpenTelemetryConfig.verify|verify} messages.
1942
- * @param message OpenTelemetryConfig message or plain object to encode
1943
- * @param [writer] Writer to encode to
1944
- * @returns Writer
1945
- */
1946
- public static encodeDelimited(message: connection_request.IOpenTelemetryConfig, writer?: $protobuf.Writer): $protobuf.Writer;
1947
-
1948
- /**
1949
- * Decodes an OpenTelemetryConfig message from the specified reader or buffer.
1950
- * @param reader Reader or buffer to decode from
1951
- * @param [length] Message length if known beforehand
1952
- * @returns OpenTelemetryConfig
1953
- * @throws {Error} If the payload is not a reader or valid buffer
1954
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
1955
- */
1956
- public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): connection_request.OpenTelemetryConfig;
1957
-
1958
- /**
1959
- * Decodes an OpenTelemetryConfig message from the specified reader or buffer, length delimited.
1960
- * @param reader Reader or buffer to decode from
1961
- * @returns OpenTelemetryConfig
1962
- * @throws {Error} If the payload is not a reader or valid buffer
1963
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
1964
- */
1965
- public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): connection_request.OpenTelemetryConfig;
1966
-
1967
- /**
1968
- * Gets the default type url for OpenTelemetryConfig
1969
- * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1970
- * @returns The default type url
1971
- */
1972
- public static getTypeUrl(typeUrlPrefix?: string): string;
1973
- }
1974
-
1975
1906
  /** Properties of a ConnectionRequest. */
1976
1907
  interface IConnectionRequest {
1977
1908
 
@@ -2023,8 +1954,8 @@ export namespace connection_request {
2023
1954
  /** ConnectionRequest connectionTimeout */
2024
1955
  connectionTimeout?: (number|null);
2025
1956
 
2026
- /** ConnectionRequest opentelemetryConfig */
2027
- opentelemetryConfig?: (connection_request.IOpenTelemetryConfig|null);
1957
+ /** ConnectionRequest lazyConnect */
1958
+ lazyConnect?: (boolean|null);
2028
1959
  }
2029
1960
 
2030
1961
  /** Represents a ConnectionRequest. */
@@ -2084,8 +2015,8 @@ export namespace connection_request {
2084
2015
  /** ConnectionRequest connectionTimeout. */
2085
2016
  public connectionTimeout: number;
2086
2017
 
2087
- /** ConnectionRequest opentelemetryConfig. */
2088
- public opentelemetryConfig?: (connection_request.IOpenTelemetryConfig|null);
2018
+ /** ConnectionRequest lazyConnect. */
2019
+ public lazyConnect: boolean;
2089
2020
 
2090
2021
  /** ConnectionRequest periodicChecks. */
2091
2022
  public periodicChecks?: ("periodicChecksManualInterval"|"periodicChecksDisabled");
@@ -2337,6 +2268,9 @@ export namespace response {
2337
2268
 
2338
2269
  /** Response isPush */
2339
2270
  isPush?: (boolean|null);
2271
+
2272
+ /** Response rootSpanPtr */
2273
+ rootSpanPtr?: (number|Long|null);
2340
2274
  }
2341
2275
 
2342
2276
  /** Represents a Response. */
@@ -2366,9 +2300,15 @@ export namespace response {
2366
2300
  /** Response isPush. */
2367
2301
  public isPush: boolean;
2368
2302
 
2303
+ /** Response rootSpanPtr. */
2304
+ public rootSpanPtr?: (number|Long|null);
2305
+
2369
2306
  /** Response value. */
2370
2307
  public value?: ("respPointer"|"constantResponse"|"requestError"|"closingError");
2371
2308
 
2309
+ /** Response _rootSpanPtr. */
2310
+ public _rootSpanPtr?: "rootSpanPtr";
2311
+
2372
2312
  /**
2373
2313
  * Creates a new Response instance using the specified properties.
2374
2314
  * @param [properties] Properties to set