@valkey/valkey-glide 1.3.5-rc11 → 1.3.5-rc13
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.
- package/README.md +5 -11
- package/build-ts/BaseClient.d.ts +4 -9
- package/build-ts/BaseClient.js +251 -229
- package/build-ts/Batch.d.ts +5 -5
- package/build-ts/Batch.js +219 -220
- package/build-ts/Commands.d.ts +1 -2
- package/build-ts/Commands.js +4 -5
- package/build-ts/GlideClient.d.ts +1 -3
- package/build-ts/GlideClient.js +53 -54
- package/build-ts/GlideClusterClient.d.ts +1 -4
- package/build-ts/GlideClusterClient.js +52 -54
- package/build-ts/Logger.js +3 -3
- package/build-ts/OpenTelemetry.d.ts +87 -0
- package/build-ts/OpenTelemetry.js +117 -0
- package/build-ts/ProtobufMessage.d.ts +12 -81
- package/build-ts/ProtobufMessage.js +42 -177
- package/build-ts/index.d.ts +2 -2
- package/build-ts/index.js +2 -25
- package/build-ts/native.d.ts +66 -0
- package/build-ts/native.js +6 -0
- package/build-ts/server-modules/GlideFt.d.ts +1 -4
- package/build-ts/server-modules/GlideFt.js +10 -11
- package/build-ts/server-modules/GlideFtOptions.d.ts +1 -2
- package/build-ts/server-modules/GlideJson.d.ts +1 -3
- package/build-ts/server-modules/GlideJson.js +2 -2
- package/package.json +7 -7
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GlideClusterClient = exports.GlideClusterClientConfiguration = void 0;
|
|
7
|
-
const
|
|
7
|
+
const _1 = require(".");
|
|
8
8
|
const ProtobufMessage_1 = require("../build-ts/ProtobufMessage");
|
|
9
|
-
const BaseClient_1 = require("./BaseClient");
|
|
10
|
-
const Commands_1 = require("./Commands");
|
|
11
9
|
/* eslint-disable-next-line @typescript-eslint/no-namespace */
|
|
12
10
|
var GlideClusterClientConfiguration;
|
|
13
11
|
(function (GlideClusterClientConfiguration) {
|
|
@@ -48,7 +46,7 @@ function convertClusterGlideRecord(res, isRoutedToSingleNodeByDefault, route) {
|
|
|
48
46
|
(Boolean(route) && route !== "allPrimaries" && route !== "allNodes");
|
|
49
47
|
return isSingleNodeResponse
|
|
50
48
|
? res
|
|
51
|
-
: (0,
|
|
49
|
+
: (0, _1.convertGlideRecordToRecord)(res);
|
|
52
50
|
}
|
|
53
51
|
/**
|
|
54
52
|
* Client used for connection to cluster servers.
|
|
@@ -56,7 +54,7 @@ function convertClusterGlideRecord(res, isRoutedToSingleNodeByDefault, route) {
|
|
|
56
54
|
*
|
|
57
55
|
* @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#cluster | Valkey Glide Wiki}.
|
|
58
56
|
*/
|
|
59
|
-
class GlideClusterClient extends
|
|
57
|
+
class GlideClusterClient extends _1.BaseClient {
|
|
60
58
|
/**
|
|
61
59
|
* @internal
|
|
62
60
|
*/
|
|
@@ -175,7 +173,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
175
173
|
(resolveAns) => {
|
|
176
174
|
try {
|
|
177
175
|
resolve([
|
|
178
|
-
new
|
|
176
|
+
new _1.ClusterScanCursor(resolveAns[0].toString()),
|
|
179
177
|
resolveAns[1],
|
|
180
178
|
]);
|
|
181
179
|
}
|
|
@@ -277,7 +275,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
277
275
|
* ```
|
|
278
276
|
*/
|
|
279
277
|
async customCommand(args, options) {
|
|
280
|
-
const command = (0,
|
|
278
|
+
const command = (0, _1.createCustomCommand)(args);
|
|
281
279
|
return super.createWritePromise(command, options);
|
|
282
280
|
}
|
|
283
281
|
/**
|
|
@@ -374,7 +372,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
374
372
|
* ```
|
|
375
373
|
*/
|
|
376
374
|
async ping(options) {
|
|
377
|
-
return this.createWritePromise((0,
|
|
375
|
+
return this.createWritePromise((0, _1.createPing)(options?.message), options);
|
|
378
376
|
}
|
|
379
377
|
/**
|
|
380
378
|
* Gets information and statistics about the server.
|
|
@@ -401,7 +399,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
401
399
|
* ```
|
|
402
400
|
*/
|
|
403
401
|
async info(options) {
|
|
404
|
-
return this.createWritePromise((0,
|
|
402
|
+
return this.createWritePromise((0, _1.createInfo)(options?.sections), { decoder: _1.Decoder.String, ...options }).then((res) => convertClusterGlideRecord(res, false, options?.route));
|
|
405
403
|
}
|
|
406
404
|
/**
|
|
407
405
|
* Gets the name of the connection to which the request is routed.
|
|
@@ -431,7 +429,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
431
429
|
* ```
|
|
432
430
|
*/
|
|
433
431
|
async clientGetName(options) {
|
|
434
|
-
return this.createWritePromise((0,
|
|
432
|
+
return this.createWritePromise((0, _1.createClientGetName)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
435
433
|
}
|
|
436
434
|
/**
|
|
437
435
|
* Rewrites the configuration file with the current configuration.
|
|
@@ -451,8 +449,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
451
449
|
* ```
|
|
452
450
|
*/
|
|
453
451
|
async configRewrite(options) {
|
|
454
|
-
return this.createWritePromise((0,
|
|
455
|
-
decoder:
|
|
452
|
+
return this.createWritePromise((0, _1.createConfigRewrite)(), {
|
|
453
|
+
decoder: _1.Decoder.String,
|
|
456
454
|
...options,
|
|
457
455
|
});
|
|
458
456
|
}
|
|
@@ -474,8 +472,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
474
472
|
* ```
|
|
475
473
|
*/
|
|
476
474
|
async configResetStat(options) {
|
|
477
|
-
return this.createWritePromise((0,
|
|
478
|
-
decoder:
|
|
475
|
+
return this.createWritePromise((0, _1.createConfigResetStat)(), {
|
|
476
|
+
decoder: _1.Decoder.String,
|
|
479
477
|
...options,
|
|
480
478
|
});
|
|
481
479
|
}
|
|
@@ -497,7 +495,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
497
495
|
* ```
|
|
498
496
|
*/
|
|
499
497
|
async clientId(options) {
|
|
500
|
-
return this.createWritePromise((0,
|
|
498
|
+
return this.createWritePromise((0, _1.createClientId)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
501
499
|
}
|
|
502
500
|
/**
|
|
503
501
|
* Reads the configuration parameters of the running server.
|
|
@@ -528,7 +526,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
528
526
|
* ```
|
|
529
527
|
*/
|
|
530
528
|
async configGet(parameters, options) {
|
|
531
|
-
return this.createWritePromise((0,
|
|
529
|
+
return this.createWritePromise((0, _1.createConfigGet)(parameters), options).then((res) => (0, _1.convertGlideRecordToRecord)(res));
|
|
532
530
|
}
|
|
533
531
|
/**
|
|
534
532
|
* Sets configuration parameters to the specified values.
|
|
@@ -550,8 +548,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
550
548
|
* ```
|
|
551
549
|
*/
|
|
552
550
|
async configSet(parameters, options) {
|
|
553
|
-
return this.createWritePromise((0,
|
|
554
|
-
decoder:
|
|
551
|
+
return this.createWritePromise((0, _1.createConfigSet)(parameters), {
|
|
552
|
+
decoder: _1.Decoder.String,
|
|
555
553
|
...options,
|
|
556
554
|
});
|
|
557
555
|
}
|
|
@@ -581,7 +579,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
581
579
|
* ```
|
|
582
580
|
*/
|
|
583
581
|
async echo(message, options) {
|
|
584
|
-
return this.createWritePromise((0,
|
|
582
|
+
return this.createWritePromise((0, _1.createEcho)(message), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
585
583
|
}
|
|
586
584
|
/**
|
|
587
585
|
* Returns the server time.
|
|
@@ -614,7 +612,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
614
612
|
* ```
|
|
615
613
|
*/
|
|
616
614
|
async time(options) {
|
|
617
|
-
return this.createWritePromise((0,
|
|
615
|
+
return this.createWritePromise((0, _1.createTime)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
618
616
|
}
|
|
619
617
|
/**
|
|
620
618
|
* Copies the value stored at the `source` to the `destination` key. When `replace` is `true`,
|
|
@@ -638,7 +636,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
638
636
|
* ```
|
|
639
637
|
*/
|
|
640
638
|
async copy(source, destination, options) {
|
|
641
|
-
return this.createWritePromise((0,
|
|
639
|
+
return this.createWritePromise((0, _1.createCopy)(source, destination, options));
|
|
642
640
|
}
|
|
643
641
|
/**
|
|
644
642
|
* Displays a piece of generative computer art and the server version.
|
|
@@ -657,7 +655,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
657
655
|
* ```
|
|
658
656
|
*/
|
|
659
657
|
async lolwut(options) {
|
|
660
|
-
return this.createWritePromise((0,
|
|
658
|
+
return this.createWritePromise((0, _1.createLolwut)(options), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
661
659
|
}
|
|
662
660
|
/**
|
|
663
661
|
* Invokes a previously loaded function.
|
|
@@ -679,7 +677,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
679
677
|
* ```
|
|
680
678
|
*/
|
|
681
679
|
async fcallWithRoute(func, args, options) {
|
|
682
|
-
return this.createWritePromise((0,
|
|
680
|
+
return this.createWritePromise((0, _1.createFCall)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
683
681
|
}
|
|
684
682
|
/**
|
|
685
683
|
* Invokes a previously loaded read-only function.
|
|
@@ -702,7 +700,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
702
700
|
* ```
|
|
703
701
|
*/
|
|
704
702
|
async fcallReadonlyWithRoute(func, args, options) {
|
|
705
|
-
return this.createWritePromise((0,
|
|
703
|
+
return this.createWritePromise((0, _1.createFCallReadOnly)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
706
704
|
}
|
|
707
705
|
/**
|
|
708
706
|
* Deletes a library and all its functions.
|
|
@@ -722,8 +720,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
722
720
|
* ```
|
|
723
721
|
*/
|
|
724
722
|
async functionDelete(libraryCode, options) {
|
|
725
|
-
return this.createWritePromise((0,
|
|
726
|
-
decoder:
|
|
723
|
+
return this.createWritePromise((0, _1.createFunctionDelete)(libraryCode), {
|
|
724
|
+
decoder: _1.Decoder.String,
|
|
727
725
|
...options,
|
|
728
726
|
});
|
|
729
727
|
}
|
|
@@ -749,7 +747,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
749
747
|
* ```
|
|
750
748
|
*/
|
|
751
749
|
async functionLoad(libraryCode, options) {
|
|
752
|
-
return this.createWritePromise((0,
|
|
750
|
+
return this.createWritePromise((0, _1.createFunctionLoad)(libraryCode, options?.replace), options);
|
|
753
751
|
}
|
|
754
752
|
/**
|
|
755
753
|
* Deletes all function libraries.
|
|
@@ -769,8 +767,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
769
767
|
* ```
|
|
770
768
|
*/
|
|
771
769
|
async functionFlush(options) {
|
|
772
|
-
return this.createWritePromise((0,
|
|
773
|
-
decoder:
|
|
770
|
+
return this.createWritePromise((0, _1.createFunctionFlush)(options?.mode), {
|
|
771
|
+
decoder: _1.Decoder.String,
|
|
774
772
|
...options,
|
|
775
773
|
});
|
|
776
774
|
}
|
|
@@ -805,13 +803,13 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
805
803
|
* ```
|
|
806
804
|
*/
|
|
807
805
|
async functionList(options) {
|
|
808
|
-
return this.createWritePromise((0,
|
|
806
|
+
return this.createWritePromise((0, _1.createFunctionList)(options), options).then((res) => res.length == 0
|
|
809
807
|
? res // no libs
|
|
810
808
|
: (Array.isArray(res[0])
|
|
811
809
|
? // single node response
|
|
812
|
-
res.map(
|
|
810
|
+
res.map(_1.convertGlideRecordToRecord)
|
|
813
811
|
: // multi node response
|
|
814
|
-
(0,
|
|
812
|
+
(0, _1.convertGlideRecordToRecord)(res)));
|
|
815
813
|
}
|
|
816
814
|
/**
|
|
817
815
|
* Returns information about the function that's currently running and information about the
|
|
@@ -863,7 +861,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
863
861
|
* ```
|
|
864
862
|
*/
|
|
865
863
|
async functionStats(options) {
|
|
866
|
-
return this.createWritePromise((0,
|
|
864
|
+
return this.createWritePromise((0, _1.createFunctionStats)(), options).then((res) => (0, _1.convertGlideRecordToRecord)(res));
|
|
867
865
|
}
|
|
868
866
|
/**
|
|
869
867
|
* Kills a function that is currently executing.
|
|
@@ -881,8 +879,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
881
879
|
* ```
|
|
882
880
|
*/
|
|
883
881
|
async functionKill(options) {
|
|
884
|
-
return this.createWritePromise((0,
|
|
885
|
-
decoder:
|
|
882
|
+
return this.createWritePromise((0, _1.createFunctionKill)(), {
|
|
883
|
+
decoder: _1.Decoder.String,
|
|
886
884
|
...options,
|
|
887
885
|
});
|
|
888
886
|
}
|
|
@@ -902,7 +900,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
902
900
|
* ```
|
|
903
901
|
*/
|
|
904
902
|
async functionDump(options) {
|
|
905
|
-
return this.createWritePromise((0,
|
|
903
|
+
return this.createWritePromise((0, _1.createFunctionDump)(), { decoder: _1.Decoder.Bytes, ...options }).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
906
904
|
}
|
|
907
905
|
/**
|
|
908
906
|
* Restores libraries from the serialized payload returned by {@link functionDump}.
|
|
@@ -923,7 +921,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
923
921
|
* ```
|
|
924
922
|
*/
|
|
925
923
|
async functionRestore(payload, options) {
|
|
926
|
-
return this.createWritePromise((0,
|
|
924
|
+
return this.createWritePromise((0, _1.createFunctionRestore)(payload, options?.policy), { decoder: _1.Decoder.String, ...options });
|
|
927
925
|
}
|
|
928
926
|
/**
|
|
929
927
|
* Deletes all the keys of all the existing databases. This command never fails.
|
|
@@ -944,8 +942,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
944
942
|
* ```
|
|
945
943
|
*/
|
|
946
944
|
async flushall(options) {
|
|
947
|
-
return this.createWritePromise((0,
|
|
948
|
-
decoder:
|
|
945
|
+
return this.createWritePromise((0, _1.createFlushAll)(options?.mode), {
|
|
946
|
+
decoder: _1.Decoder.String,
|
|
949
947
|
...options,
|
|
950
948
|
});
|
|
951
949
|
}
|
|
@@ -968,8 +966,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
968
966
|
* ```
|
|
969
967
|
*/
|
|
970
968
|
async flushdb(options) {
|
|
971
|
-
return this.createWritePromise((0,
|
|
972
|
-
decoder:
|
|
969
|
+
return this.createWritePromise((0, _1.createFlushDB)(options?.mode), {
|
|
970
|
+
decoder: _1.Decoder.String,
|
|
973
971
|
...options,
|
|
974
972
|
});
|
|
975
973
|
}
|
|
@@ -991,7 +989,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
991
989
|
* ```
|
|
992
990
|
*/
|
|
993
991
|
async dbsize(options) {
|
|
994
|
-
return this.createWritePromise((0,
|
|
992
|
+
return this.createWritePromise((0, _1.createDBSize)(), options);
|
|
995
993
|
}
|
|
996
994
|
/** Publish a message on pubsub channel.
|
|
997
995
|
* This command aggregates PUBLISH and SPUBLISH commands functionalities.
|
|
@@ -1020,7 +1018,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1020
1018
|
* ```
|
|
1021
1019
|
*/
|
|
1022
1020
|
async publish(message, channel, sharded = false) {
|
|
1023
|
-
return this.createWritePromise((0,
|
|
1021
|
+
return this.createWritePromise((0, _1.createPublish)(message, channel, sharded));
|
|
1024
1022
|
}
|
|
1025
1023
|
/**
|
|
1026
1024
|
* Lists the currently active shard channels.
|
|
@@ -1045,7 +1043,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1045
1043
|
* ```
|
|
1046
1044
|
*/
|
|
1047
1045
|
async pubsubShardChannels(options) {
|
|
1048
|
-
return this.createWritePromise((0,
|
|
1046
|
+
return this.createWritePromise((0, _1.createPubsubShardChannels)(options?.pattern), options);
|
|
1049
1047
|
}
|
|
1050
1048
|
/**
|
|
1051
1049
|
* Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified shard channels.
|
|
@@ -1068,7 +1066,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1068
1066
|
* ```
|
|
1069
1067
|
*/
|
|
1070
1068
|
async pubsubShardNumSub(channels, options) {
|
|
1071
|
-
return this.createWritePromise((0,
|
|
1069
|
+
return this.createWritePromise((0, _1.createPubSubShardNumSub)(channels), options).then((res) => res.map((r) => {
|
|
1072
1070
|
return { channel: r.key, numSub: r.value };
|
|
1073
1071
|
}));
|
|
1074
1072
|
}
|
|
@@ -1090,7 +1088,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1090
1088
|
* ```
|
|
1091
1089
|
*/
|
|
1092
1090
|
async lastsave(options) {
|
|
1093
|
-
return this.createWritePromise((0,
|
|
1091
|
+
return this.createWritePromise((0, _1.createLastSave)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
1094
1092
|
}
|
|
1095
1093
|
/**
|
|
1096
1094
|
* Returns a random existing key name.
|
|
@@ -1109,7 +1107,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1109
1107
|
* ```
|
|
1110
1108
|
*/
|
|
1111
1109
|
async randomKey(options) {
|
|
1112
|
-
return this.createWritePromise((0,
|
|
1110
|
+
return this.createWritePromise((0, _1.createRandomKey)(), options);
|
|
1113
1111
|
}
|
|
1114
1112
|
/**
|
|
1115
1113
|
* Flushes all the previously watched keys for a transaction. Executing a transaction will
|
|
@@ -1131,8 +1129,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1131
1129
|
* ```
|
|
1132
1130
|
*/
|
|
1133
1131
|
async unwatch(options) {
|
|
1134
|
-
return this.createWritePromise((0,
|
|
1135
|
-
decoder:
|
|
1132
|
+
return this.createWritePromise((0, _1.createUnWatch)(), {
|
|
1133
|
+
decoder: _1.Decoder.String,
|
|
1136
1134
|
...options,
|
|
1137
1135
|
});
|
|
1138
1136
|
}
|
|
@@ -1202,7 +1200,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1202
1200
|
* ```
|
|
1203
1201
|
*/
|
|
1204
1202
|
async scriptExists(sha1s, options) {
|
|
1205
|
-
return this.createWritePromise((0,
|
|
1203
|
+
return this.createWritePromise((0, _1.createScriptExists)(sha1s), options);
|
|
1206
1204
|
}
|
|
1207
1205
|
/**
|
|
1208
1206
|
* Flushes the Lua scripts cache.
|
|
@@ -1221,8 +1219,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1221
1219
|
* ```
|
|
1222
1220
|
*/
|
|
1223
1221
|
async scriptFlush(options) {
|
|
1224
|
-
return this.createWritePromise((0,
|
|
1225
|
-
decoder:
|
|
1222
|
+
return this.createWritePromise((0, _1.createScriptFlush)(options?.mode), {
|
|
1223
|
+
decoder: _1.Decoder.String,
|
|
1226
1224
|
...options,
|
|
1227
1225
|
});
|
|
1228
1226
|
}
|
|
@@ -1242,8 +1240,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
|
1242
1240
|
* ```
|
|
1243
1241
|
*/
|
|
1244
1242
|
async scriptKill(options) {
|
|
1245
|
-
return this.createWritePromise((0,
|
|
1246
|
-
decoder:
|
|
1243
|
+
return this.createWritePromise((0, _1.createScriptKill)(), {
|
|
1244
|
+
decoder: _1.Decoder.String,
|
|
1247
1245
|
...options,
|
|
1248
1246
|
});
|
|
1249
1247
|
}
|
package/build-ts/Logger.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Logger = void 0;
|
|
7
|
-
const
|
|
7
|
+
const _1 = require(".");
|
|
8
8
|
const LEVEL = new Map([
|
|
9
9
|
["error", 0 /* Level.Error */],
|
|
10
10
|
["warn", 1 /* Level.Warn */],
|
|
@@ -24,7 +24,7 @@ const LEVEL = new Map([
|
|
|
24
24
|
*/
|
|
25
25
|
class Logger {
|
|
26
26
|
constructor(level, fileName) {
|
|
27
|
-
Logger.logger_level = (0,
|
|
27
|
+
Logger.logger_level = (0, _1.InitInternalLogger)(LEVEL.get(level), fileName);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Logs the provided message if the provided log level is lower then the logger level.
|
|
@@ -44,7 +44,7 @@ class Logger {
|
|
|
44
44
|
const level = LEVEL.get(logLevel) || 0;
|
|
45
45
|
if (!(level <= Logger.logger_level))
|
|
46
46
|
return;
|
|
47
|
-
(0,
|
|
47
|
+
(0, _1.log)(level, logIdentifier, message);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ OpenTelemetry can only be initialized once per process. Calling `OpenTelemetry.init()` more than once will be ignored.
|
|
5
|
+
* If you need to change configuration, restart the process with new settings.
|
|
6
|
+
*
|
|
7
|
+
* ### OpenTelemetry
|
|
8
|
+
*
|
|
9
|
+
* - **openTelemetryConfig**: Use this object to configure OpenTelemetry exporters and options.
|
|
10
|
+
* - **traces**: (optional) Configure trace exporting.
|
|
11
|
+
* - **endpoint**: The collector endpoint for traces. Supported protocols:
|
|
12
|
+
* - `http://` or `https://` for HTTP/HTTPS
|
|
13
|
+
* - `grpc://` for gRPC
|
|
14
|
+
* - `file://` for local file export (see below)
|
|
15
|
+
* - **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.
|
|
16
|
+
* Note: There is a tradeoff between sampling percentage and performance. Higher sampling percentages will provide more detailed telemetry data but will impact performance.
|
|
17
|
+
* It is recommended to keep this number low (1-5%) in production environments unless you have specific needs for higher sampling rates.
|
|
18
|
+
* - **metrics**: (optional) Configure metrics exporting.
|
|
19
|
+
* - **endpoint**: The collector endpoint for metrics. Same protocol rules as above.
|
|
20
|
+
* - **flushIntervalMs**: (optional) Interval in milliseconds for flushing data to the collector. Must be a positive integer. Defaults to 5000ms if not specified.
|
|
21
|
+
*
|
|
22
|
+
* #### File Exporter Details
|
|
23
|
+
* - For `file://` endpoints:
|
|
24
|
+
* - The path must start with `file://` (e.g., `file:///tmp/otel` or `file:///tmp/otel/traces.json`).
|
|
25
|
+
* - If the path is a directory or lacks a file extension, data is written to `signals.json` in that directory.
|
|
26
|
+
* - If the path includes a filename with an extension, that file is used as-is.
|
|
27
|
+
* - The parent directory must already exist; otherwise, initialization will fail with an InvalidInput error.
|
|
28
|
+
* - If the target file exists, new data is appended (not overwritten).
|
|
29
|
+
*
|
|
30
|
+
* #### Validation Rules
|
|
31
|
+
* - `flushIntervalMs` must be a positive integer.
|
|
32
|
+
* - `samplePercentage` must be between 0 and 100.
|
|
33
|
+
* - File exporter paths must start with `file://` and have an existing parent directory.
|
|
34
|
+
* - Invalid configuration will throw an error synchronously when calling `OpenTelemetry.init()`.
|
|
35
|
+
*/
|
|
36
|
+
import { OpenTelemetryConfig } from ".";
|
|
37
|
+
export declare class OpenTelemetry {
|
|
38
|
+
private static _instance;
|
|
39
|
+
private static openTelemetryConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Example usage:
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { OpenTelemetry } from "@valkey/glide";
|
|
44
|
+
*
|
|
45
|
+
* OpenTelemetry.init({
|
|
46
|
+
* traces: {
|
|
47
|
+
* endpoint: "http://localhost:4318/v1/traces",
|
|
48
|
+
* samplePercentage: 10, // Optional, defaults to 1. Can also be changed at runtime via setSamplePercentage().
|
|
49
|
+
* },
|
|
50
|
+
* metrics: {
|
|
51
|
+
* endpoint: "http://localhost:4318/v1/metrics",
|
|
52
|
+
* },
|
|
53
|
+
* flushIntervalMs: 5000, // Optional, defaults to 5000
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* Initialize the OpenTelemetry instance
|
|
58
|
+
* @param openTelemetryConfig - The OpenTelemetry configuration
|
|
59
|
+
*/
|
|
60
|
+
static init(openTelemetryConfig: OpenTelemetryConfig): void;
|
|
61
|
+
private static internalInit;
|
|
62
|
+
/**
|
|
63
|
+
* Check if the OpenTelemetry instance is initialized
|
|
64
|
+
* @returns True if the OpenTelemetry instance is initialized, false otherwise
|
|
65
|
+
*/
|
|
66
|
+
static isInitialized(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Get the sample percentage for traces
|
|
69
|
+
* @returns The sample percentage for traces only if OpenTelemetry is initialized and the traces config is set, otherwise undefined.
|
|
70
|
+
*/
|
|
71
|
+
static getSamplePercentage(): number | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Determines if the current request should be sampled for OpenTelemetry tracing.
|
|
74
|
+
* Uses the configured sample percentage to randomly decide whether to create a span for this request.
|
|
75
|
+
* @returns true if the request should be sampled, false otherwise
|
|
76
|
+
*/
|
|
77
|
+
static shouldSample(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Set the percentage of requests to be sampled and traced. Must be a value between 0 and 100.
|
|
80
|
+
* This setting only affects traces, not metrics.
|
|
81
|
+
* @param percentage - The sample percentage 0-100
|
|
82
|
+
* @throws Error if OpenTelemetry is not initialized or traces config is not set
|
|
83
|
+
* @remarks
|
|
84
|
+
* This method can be called at runtime to change the sampling percentage without reinitializing OpenTelemetry.
|
|
85
|
+
*/
|
|
86
|
+
static setSamplePercentage(percentage: number): void;
|
|
87
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ OpenTelemetry can only be initialized once per process. Calling `OpenTelemetry.init()` more than once will be ignored.
|
|
6
|
+
* If you need to change configuration, restart the process with new settings.
|
|
7
|
+
*
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.OpenTelemetry = void 0;
|
|
39
|
+
const _1 = require(".");
|
|
40
|
+
class OpenTelemetry {
|
|
41
|
+
/**
|
|
42
|
+
* Example usage:
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { OpenTelemetry } from "@valkey/glide";
|
|
45
|
+
*
|
|
46
|
+
* OpenTelemetry.init({
|
|
47
|
+
* traces: {
|
|
48
|
+
* endpoint: "http://localhost:4318/v1/traces",
|
|
49
|
+
* samplePercentage: 10, // Optional, defaults to 1. Can also be changed at runtime via setSamplePercentage().
|
|
50
|
+
* },
|
|
51
|
+
* metrics: {
|
|
52
|
+
* endpoint: "http://localhost:4318/v1/metrics",
|
|
53
|
+
* },
|
|
54
|
+
* flushIntervalMs: 5000, // Optional, defaults to 5000
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* Initialize the OpenTelemetry instance
|
|
59
|
+
* @param openTelemetryConfig - The OpenTelemetry configuration
|
|
60
|
+
*/
|
|
61
|
+
static init(openTelemetryConfig) {
|
|
62
|
+
if (!this._instance) {
|
|
63
|
+
this.internalInit(openTelemetryConfig);
|
|
64
|
+
_1.Logger.log("info", "GlideOpenTelemetry", "OpenTelemetry initialized with config: " +
|
|
65
|
+
JSON.stringify(openTelemetryConfig));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
_1.Logger.log("warn", "GlideOpenTelemetry", "OpenTelemetry already initialized");
|
|
69
|
+
}
|
|
70
|
+
static internalInit(openTelemetryConfig) {
|
|
71
|
+
this.openTelemetryConfig = openTelemetryConfig;
|
|
72
|
+
(0, _1.InitOpenTelemetry)(openTelemetryConfig);
|
|
73
|
+
this._instance = new OpenTelemetry();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if the OpenTelemetry instance is initialized
|
|
77
|
+
* @returns True if the OpenTelemetry instance is initialized, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
static isInitialized() {
|
|
80
|
+
return this._instance != null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the sample percentage for traces
|
|
84
|
+
* @returns The sample percentage for traces only if OpenTelemetry is initialized and the traces config is set, otherwise undefined.
|
|
85
|
+
*/
|
|
86
|
+
static getSamplePercentage() {
|
|
87
|
+
return this.openTelemetryConfig?.traces?.samplePercentage;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Determines if the current request should be sampled for OpenTelemetry tracing.
|
|
91
|
+
* Uses the configured sample percentage to randomly decide whether to create a span for this request.
|
|
92
|
+
* @returns true if the request should be sampled, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
static shouldSample() {
|
|
95
|
+
const percentage = this.getSamplePercentage();
|
|
96
|
+
return (this.isInitialized() &&
|
|
97
|
+
percentage !== undefined &&
|
|
98
|
+
Math.random() * 100 < percentage);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set the percentage of requests to be sampled and traced. Must be a value between 0 and 100.
|
|
102
|
+
* This setting only affects traces, not metrics.
|
|
103
|
+
* @param percentage - The sample percentage 0-100
|
|
104
|
+
* @throws Error if OpenTelemetry is not initialized or traces config is not set
|
|
105
|
+
* @remarks
|
|
106
|
+
* This method can be called at runtime to change the sampling percentage without reinitializing OpenTelemetry.
|
|
107
|
+
*/
|
|
108
|
+
static setSamplePercentage(percentage) {
|
|
109
|
+
if (!this.openTelemetryConfig || !this.openTelemetryConfig.traces) {
|
|
110
|
+
throw new _1.ConfigurationError("OpenTelemetry config traces not initialized");
|
|
111
|
+
}
|
|
112
|
+
this.openTelemetryConfig.traces.samplePercentage = percentage;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.OpenTelemetry = OpenTelemetry;
|
|
116
|
+
OpenTelemetry._instance = null;
|
|
117
|
+
OpenTelemetry.openTelemetryConfig = null;
|