couchbase 4.7.0 → 4.7.2

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.
Files changed (84) hide show
  1. package/CMakeLists.txt +3 -0
  2. package/deps/couchbase-cxx-cache/mozilla-ca-bundle.crt +96 -727
  3. package/deps/couchbase-cxx-cache/mozilla-ca-bundle.sha256 +1 -1
  4. package/deps/couchbase-cxx-client/CMakeLists.txt +3 -1
  5. package/deps/couchbase-cxx-client/README.md +2 -2
  6. package/deps/couchbase-cxx-client/core/error_context/base_error_context.hxx +32 -0
  7. package/deps/couchbase-cxx-client/core/error_context/key_value.cxx +1 -0
  8. package/deps/couchbase-cxx-client/core/error_context/key_value.hxx +23 -0
  9. package/deps/couchbase-cxx-client/core/error_context/key_value_error_context.hxx +35 -0
  10. package/deps/couchbase-cxx-client/core/error_context/subdocument_error_context.hxx +41 -0
  11. package/deps/couchbase-cxx-client/core/impl/binary_collection.cxx +123 -88
  12. package/deps/couchbase-cxx-client/core/impl/collection.cxx +416 -189
  13. package/deps/couchbase-cxx-client/core/impl/error.cxx +29 -4
  14. package/deps/couchbase-cxx-client/core/impl/invoke_with_node_id.hxx +44 -0
  15. package/deps/couchbase-cxx-client/core/impl/node_id.cxx +110 -0
  16. package/deps/couchbase-cxx-client/core/impl/node_id.hxx +40 -0
  17. package/deps/couchbase-cxx-client/core/io/configuration_belongs_to_session.hxx +67 -0
  18. package/deps/couchbase-cxx-client/core/io/http_session_manager.hxx +97 -57
  19. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +7 -16
  20. package/deps/couchbase-cxx-client/core/operations/document_get_all_replicas.hxx +14 -4
  21. package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -4
  22. package/deps/couchbase-cxx-client/core/operations/document_lookup_in_all_replicas.hxx +4 -0
  23. package/deps/couchbase-cxx-client/core/operations/document_query.cxx +12 -12
  24. package/deps/couchbase-cxx-client/core/operations/management/collection_create.cxx +11 -11
  25. package/deps/couchbase-cxx-client/core/operations/management/collection_drop.cxx +11 -11
  26. package/deps/couchbase-cxx-client/core/operations/management/collection_update.cxx +11 -11
  27. package/deps/couchbase-cxx-client/core/operations/management/error_utils.cxx +9 -6
  28. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +5 -4
  29. package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +7 -6
  30. package/deps/couchbase-cxx-client/core/operations/management/scope_create.cxx +12 -13
  31. package/deps/couchbase-cxx-client/core/operations/management/scope_drop.cxx +8 -9
  32. package/deps/couchbase-cxx-client/core/topology/configuration.cxx +21 -0
  33. package/deps/couchbase-cxx-client/core/topology/configuration.hxx +28 -0
  34. package/deps/couchbase-cxx-client/core/utils/contains_string.cxx +61 -0
  35. package/deps/couchbase-cxx-client/core/utils/contains_string.hxx +26 -0
  36. package/deps/couchbase-cxx-client/couchbase/collection.hxx +73 -0
  37. package/deps/couchbase-cxx-client/couchbase/error.hxx +16 -0
  38. package/deps/couchbase-cxx-client/couchbase/node_id.hxx +123 -0
  39. package/deps/couchbase-cxx-client/couchbase/node_id_for_options.hxx +61 -0
  40. package/deps/couchbase-cxx-client/couchbase/node_ids_options.hxx +62 -0
  41. package/deps/couchbase-cxx-client/couchbase/result.hxx +42 -0
  42. package/dist/analyticsexecutor.d.ts +4 -0
  43. package/dist/analyticsexecutor.js +26 -11
  44. package/dist/analyticsindexmanager.js +2 -2
  45. package/dist/binding.d.ts +12 -2
  46. package/dist/bindingutilities.js +8 -5
  47. package/dist/bucket.d.ts +9 -1
  48. package/dist/bucket.js +21 -0
  49. package/dist/cluster.d.ts +10 -1
  50. package/dist/cluster.js +25 -3
  51. package/dist/collection.d.ts +3 -3
  52. package/dist/collection.js +189 -143
  53. package/dist/diagnosticsexecutor.js +2 -2
  54. package/dist/diagnosticstypes.d.ts +36 -0
  55. package/dist/diagnosticstypes.js +22 -1
  56. package/dist/mutationstate.js +1 -1
  57. package/dist/observability.d.ts +5 -1
  58. package/dist/observability.js +11 -3
  59. package/dist/observabilityhandler.d.ts +19 -0
  60. package/dist/observabilityhandler.js +81 -14
  61. package/dist/observabilitytypes.js +19 -42
  62. package/dist/observabilityutilities.js +1 -1
  63. package/dist/oteltracer.d.ts +5 -0
  64. package/dist/oteltracer.js +7 -0
  65. package/dist/queryexecutor.d.ts +9 -0
  66. package/dist/queryexecutor.js +18 -0
  67. package/dist/queryindexmanager.js +15 -0
  68. package/dist/searchexecutor.d.ts +4 -0
  69. package/dist/searchexecutor.js +30 -15
  70. package/dist/thresholdlogging.d.ts +5 -0
  71. package/dist/thresholdlogging.js +7 -0
  72. package/dist/tracing.d.ts +6 -0
  73. package/dist/transactions.js +29 -6
  74. package/dist/version.d.ts +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/viewexecutor.d.ts +4 -0
  77. package/dist/viewexecutor.js +30 -15
  78. package/dist/waituntilreadyexecutor.d.ts +37 -0
  79. package/dist/waituntilreadyexecutor.js +156 -0
  80. package/package.json +8 -8
  81. package/scripts/prebuilds.js +13 -0
  82. package/src/binding.cpp +1 -1
  83. package/src/connection.hpp +24 -3
  84. package/src/jstocbpp_errors.hpp +6 -0
@@ -67,13 +67,13 @@ class PingExecutor {
67
67
  */
68
68
  async ping(options) {
69
69
  return new Promise((resolve, reject) => {
70
- // BUG(JSCBC-993): timeout is not currently sent to the C++ client
71
- void options.timeout;
72
70
  this._cluster.conn.ping({
73
71
  report_id: options.reportId,
72
+ bucket_name: options.bucket,
74
73
  services: options.serviceTypes
75
74
  ? options.serviceTypes.map((svc) => (0, bindingutilities_1.serviceTypeToCpp)(svc))
76
75
  : undefined,
76
+ timeout: options.timeout,
77
77
  }, (cppErr, resp) => {
78
78
  const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
79
79
  if (err || !resp) {
@@ -280,3 +280,39 @@ export interface DiagnosticsOptions {
280
280
  */
281
281
  reportId?: string;
282
282
  }
283
+ /**
284
+ * Represents the desired state of a cluster.
285
+ *
286
+ * @category Diagnostics
287
+ */
288
+ export declare enum ClusterState {
289
+ /**
290
+ * Indicates that all nodes and their sockets are reachable.
291
+ */
292
+ Online = "online",
293
+ /**
294
+ * Indicates that at least one socket per service is reachable.
295
+ */
296
+ Degraded = "degraded",
297
+ /**
298
+ * Indicates that not even one socket per service is reachable.
299
+ * Invalid as a desired state for waitUntilReady.
300
+ */
301
+ Offline = "offline"
302
+ }
303
+ /**
304
+ * Options for the waitUntilReady operation on a Cluster or Bucket.
305
+ *
306
+ * @category Diagnostics
307
+ */
308
+ export interface WaitUntilReadyOptions {
309
+ /**
310
+ * The desired cluster state to wait for.
311
+ * Defaults to ClusterState.Online.
312
+ */
313
+ desiredState?: ClusterState;
314
+ /**
315
+ * The set of services to wait on.
316
+ */
317
+ serviceTypes?: ServiceType[];
318
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DiagnosticsResult = exports.DiagnosticsEndpoint = exports.PingResult = exports.PingEndpoint = exports.PingState = exports.EndpointState = void 0;
3
+ exports.ClusterState = exports.DiagnosticsResult = exports.DiagnosticsEndpoint = exports.PingResult = exports.PingEndpoint = exports.PingState = exports.EndpointState = void 0;
4
4
  /**
5
5
  * Represents the status of an an endpoint in a diagnostics report.
6
6
  *
@@ -170,3 +170,24 @@ class DiagnosticsResult {
170
170
  }
171
171
  }
172
172
  exports.DiagnosticsResult = DiagnosticsResult;
173
+ /**
174
+ * Represents the desired state of a cluster.
175
+ *
176
+ * @category Diagnostics
177
+ */
178
+ var ClusterState;
179
+ (function (ClusterState) {
180
+ /**
181
+ * Indicates that all nodes and their sockets are reachable.
182
+ */
183
+ ClusterState["Online"] = "online";
184
+ /**
185
+ * Indicates that at least one socket per service is reachable.
186
+ */
187
+ ClusterState["Degraded"] = "degraded";
188
+ /**
189
+ * Indicates that not even one socket per service is reachable.
190
+ * Invalid as a desired state for waitUntilReady.
191
+ */
192
+ ClusterState["Offline"] = "offline";
193
+ })(ClusterState || (exports.ClusterState = ClusterState = {}));
@@ -37,7 +37,7 @@ class MutationState {
37
37
  }
38
38
  else {
39
39
  const otherToken = this._data[bucketName][vbId];
40
- const otherTokenSeqNo = parseInt(otherToken.toJSON().sequence, 10);
40
+ const otherTokenSeqNo = parseInt(otherToken.toJSON().sequence_number, 10);
41
41
  if (otherTokenSeqNo < vbSeqNo) {
42
42
  this._data[bucketName][vbId] = cppToken;
43
43
  }
@@ -22,6 +22,10 @@ export declare class NoOpSpan implements RequestSpan {
22
22
  * @internal
23
23
  */
24
24
  end(): void;
25
+ /**
26
+ * @internal
27
+ */
28
+ isRecording(): boolean;
25
29
  /**
26
30
  * @internal
27
31
  */
@@ -39,7 +43,7 @@ export declare class NoOpTracer implements RequestTracer {
39
43
  /**
40
44
  * @internal
41
45
  */
42
- export declare function wrapObservableBindingCall<TReq extends CppObservableRequests, TResp extends CppObservableResponse>(fn: ObservableBindingFunc<TReq, TResp>, req: TReq, obsReqHandler: ObservableRequestHandler): Promise<[Error | null, TResp]>;
46
+ export declare function wrapObservableBindingCall<TReq extends CppObservableRequests, TResp extends CppObservableResponse>(fn: ObservableBindingFunc<TReq, TResp>, req: TReq, obsReqHandler: ObservableRequestHandler | null): Promise<[Error | null, TResp]>;
43
47
  /**
44
48
  * @internal
45
49
  */
@@ -22,6 +22,12 @@ class NoOpSpan {
22
22
  * @internal
23
23
  */
24
24
  end() { }
25
+ /**
26
+ * @internal
27
+ */
28
+ isRecording() {
29
+ return false;
30
+ }
25
31
  /**
26
32
  * @internal
27
33
  */
@@ -47,15 +53,17 @@ exports.NoOpTracer = NoOpTracer;
47
53
  */
48
54
  async function wrapObservableBindingCall(fn, req, obsReqHandler) {
49
55
  return await new Promise((resolve) => {
50
- req.wrapper_span_name = obsReqHandler.wrapperSpanName;
56
+ if (obsReqHandler) {
57
+ req.wrapper_span_name = obsReqHandler.wrapperSpanName;
58
+ }
51
59
  fn(req, (cppErr, res) => {
52
60
  let err = null;
53
61
  if (cppErr) {
54
62
  err = (0, bindingutilities_1.errorFromCpp)(cppErr);
55
- obsReqHandler.processCoreSpan(cppErr.cpp_core_span);
63
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.processCoreSpan(cppErr.cpp_core_span);
56
64
  }
57
65
  else {
58
- obsReqHandler.processCoreSpan(res.cpp_core_span);
66
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.processCoreSpan(res.cpp_core_span);
59
67
  }
60
68
  resolve([err, res]);
61
69
  });
@@ -5,6 +5,11 @@ import { ObservabilityInstruments } from './observabilitytypes';
5
5
  import { AttributeValue, CppOpAttributeName, OpType, OpAttributeName, SpanStatus, ServiceName } from './observabilitytypes';
6
6
  import { HttpOpAttributesOptions } from './observabilityutilities';
7
7
  import { RequestSpan, RequestTracer } from './tracing';
8
+ /**
9
+ * Returns true when both tracer and meter are NoOp, enabling the fast-path bypass in KV ops.
10
+ * @internal
11
+ */
12
+ export declare function isNoopObservabilityInstruments(instruments: ObservabilityInstruments): boolean;
8
13
  /**
9
14
  * @internal
10
15
  */
@@ -39,13 +44,26 @@ export declare class ObservableRequestHandler {
39
44
  */
40
45
  get clusterUUID(): string | undefined;
41
46
  /**
47
+ * Ends the request. A request is recorded once, so a call after the
48
+ * request has ended does nothing.
49
+ *
42
50
  * @internal
43
51
  */
44
52
  end(): void;
45
53
  /**
54
+ * Ends the request with an error. As with end, a call after the request
55
+ * has ended does nothing.
56
+ *
46
57
  * @internal
47
58
  */
48
59
  endWithError(error?: any): void;
60
+ /**
61
+ * Runs fn, then ends the request, so that a failure in fn is recorded as
62
+ * an error rather than as a success.
63
+ *
64
+ * @internal
65
+ */
66
+ endAfter<T>(fn: () => T): T;
49
67
  /**
50
68
  * @internal
51
69
  */
@@ -80,6 +98,7 @@ export declare class WrappedSpan implements RequestSpan {
80
98
  private readonly _tracer;
81
99
  private readonly _hasMultipleEncodingSpans;
82
100
  readonly _requestSpan: RequestSpan;
101
+ private readonly _isRecording;
83
102
  private _parentSpan;
84
103
  private _endedEncodingSpans;
85
104
  private _encodingSpan;
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WrappedSpan = exports.ObservableRequestHandler = void 0;
6
+ exports.WrappedSpan = exports.ObservableRequestHandler = exports.isNoopObservabilityInstruments = void 0;
7
+ const binding_1 = __importDefault(require("./binding"));
4
8
  const observability_1 = require("./observability");
5
9
  const observabilitytypes_1 = require("./observabilitytypes");
6
10
  const observabilityutilities_1 = require("./observabilityutilities");
7
11
  const observabilityutilities_2 = require("./observabilityutilities");
8
12
  const utilities_1 = require("./utilities");
13
+ const _DATASTRUCTURE_OPS = new Set(Object.values(observabilitytypes_1.DatastructureOp));
9
14
  /**
10
15
  * @internal
11
16
  */
12
17
  class ObservableRequestHandlerTracerImpl {
13
- constructor(opType, observabilityInstruments, parentSpan) {
14
- this._startTime = (0, observabilityutilities_1.timeInputToHiResTime)();
18
+ constructor(opType, observabilityInstruments, parentSpan, startTime) {
19
+ this._startTime = startTime !== null && startTime !== void 0 ? startTime : (0, observabilityutilities_1.timeInputToHiResTime)();
15
20
  this._opType = opType;
16
21
  this._serviceName = (0, observabilitytypes_1.serviceNameFromOpType)(opType);
17
22
  this._tracer = observabilityInstruments.tracer;
@@ -120,11 +125,23 @@ class ObservableRequestHandlerTracerImpl {
120
125
  * @internal
121
126
  */
122
127
  setRequestKeyValueAttributes(cppDocId, durability) {
123
- const opAttrs = (0, observabilityutilities_1.getAttributesForKeyValueOpType)(this._opType, cppDocId, durability);
124
- for (const [k, v] of Object.entries(opAttrs)) {
125
- this._wrappedSpan.setAttribute(k, v);
128
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.SystemName, 'couchbase');
129
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.Service, observabilitytypes_1.ServiceName.KeyValue);
130
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.OperationName, this._opType);
131
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.BucketName, cppDocId.bucket);
132
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.ScopeName, cppDocId.scope);
133
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.CollectionName, cppDocId.collection);
134
+ if (durability && durability !== binding_1.default.durability_level.none) {
135
+ if (durability === binding_1.default.durability_level.majority) {
136
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.DurabilityLevel, 'majority');
137
+ }
138
+ else if (durability === binding_1.default.durability_level.majority_and_persist_to_active) {
139
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.DurabilityLevel, 'majority_and_persist_to_active');
140
+ }
141
+ else if (durability === binding_1.default.durability_level.persist_to_majority) {
142
+ this._wrappedSpan.setAttribute(observabilitytypes_1.OpAttributeName.DurabilityLevel, 'persist_to_majority');
143
+ }
126
144
  }
127
- // TODO: meter attrs
128
145
  }
129
146
  }
130
147
  /**
@@ -223,14 +240,14 @@ class ObservableRequestHandlerNoOpMeterImpl {
223
240
  * @internal
224
241
  */
225
242
  class ObservableRequestHandlerMeterImpl {
226
- constructor(opType, observabilityInstruments) {
243
+ constructor(opType, observabilityInstruments, startTime) {
227
244
  this._attrs = {};
228
245
  this._opType = opType;
229
246
  this._serviceName = (0, observabilitytypes_1.serviceNameFromOpType)(opType);
230
247
  this._meter = observabilityInstruments.meter;
231
248
  this._getClusterLabelsFn = observabilityInstruments.clusterLabelsFn;
232
- this._startTime = (0, observabilityutilities_1.timeInputToHiResTime)();
233
- this._ignoreTopLevelOp = Object.values(observabilitytypes_1.DatastructureOp).includes(opType);
249
+ this._startTime = startTime !== null && startTime !== void 0 ? startTime : (0, observabilityutilities_1.timeInputToHiResTime)();
250
+ this._ignoreTopLevelOp = _DATASTRUCTURE_OPS.has(opType);
234
251
  }
235
252
  /**
236
253
  * @internal
@@ -315,6 +332,17 @@ class ObservableRequestHandlerMeterImpl {
315
332
  tags[observabilitytypes_1.OpAttributeName.ErrorType] = errorType;
316
333
  }
317
334
  }
335
+ const _NOOP_TRACER_IMPL = new ObservableRequestHandlerNoOpTracerImpl('', null);
336
+ const _NOOP_METER_IMPL = new ObservableRequestHandlerNoOpMeterImpl('', null);
337
+ /**
338
+ * Returns true when both tracer and meter are NoOp, enabling the fast-path bypass in KV ops.
339
+ * @internal
340
+ */
341
+ function isNoopObservabilityInstruments(instruments) {
342
+ return ((!instruments.tracer || instruments.tracer instanceof observability_1.NoOpTracer) &&
343
+ instruments.meter instanceof observability_1.NoOpMeter);
344
+ }
345
+ exports.isNoopObservabilityInstruments = isNoopObservabilityInstruments;
318
346
  /**
319
347
  * @internal
320
348
  */
@@ -322,18 +350,19 @@ class ObservableRequestHandler {
322
350
  constructor(opType, observabilityInstruments, parentSpan) {
323
351
  this._opType = opType;
324
352
  this._requestHasEnded = false;
353
+ const startTime = (0, observabilityutilities_1.timeInputToHiResTime)();
325
354
  if (!observabilityInstruments.tracer ||
326
355
  observabilityInstruments.tracer instanceof observability_1.NoOpTracer) {
327
- this._tracerImpl = new ObservableRequestHandlerNoOpTracerImpl(opType, observabilityInstruments, parentSpan);
356
+ this._tracerImpl = _NOOP_TRACER_IMPL;
328
357
  }
329
358
  else {
330
- this._tracerImpl = new ObservableRequestHandlerTracerImpl(opType, observabilityInstruments, parentSpan);
359
+ this._tracerImpl = new ObservableRequestHandlerTracerImpl(opType, observabilityInstruments, parentSpan, startTime);
331
360
  }
332
361
  if (observabilityInstruments.meter instanceof observability_1.NoOpMeter) {
333
- this._meterImpl = new ObservableRequestHandlerNoOpMeterImpl(opType, observabilityInstruments);
362
+ this._meterImpl = _NOOP_METER_IMPL;
334
363
  }
335
364
  else {
336
- this._meterImpl = new ObservableRequestHandlerMeterImpl(opType, observabilityInstruments);
365
+ this._meterImpl = new ObservableRequestHandlerMeterImpl(opType, observabilityInstruments, startTime);
337
366
  }
338
367
  }
339
368
  /**
@@ -373,21 +402,51 @@ class ObservableRequestHandler {
373
402
  return this._tracerImpl.clusterUUID;
374
403
  }
375
404
  /**
405
+ * Ends the request. A request is recorded once, so a call after the
406
+ * request has ended does nothing.
407
+ *
376
408
  * @internal
377
409
  */
378
410
  end() {
411
+ if (this._requestHasEnded) {
412
+ return;
413
+ }
379
414
  this._requestHasEnded = true;
380
415
  this._tracerImpl.end();
381
416
  this._meterImpl.processEnd(this.clusterName, this.clusterUUID);
382
417
  }
383
418
  /**
419
+ * Ends the request with an error. As with end, a call after the request
420
+ * has ended does nothing.
421
+ *
384
422
  * @internal
385
423
  */
386
424
  endWithError(error) {
425
+ if (this._requestHasEnded) {
426
+ return;
427
+ }
387
428
  this._requestHasEnded = true;
388
429
  this._tracerImpl.endWithError(error);
389
430
  this._meterImpl.processEnd(this.clusterName, this.clusterUUID, error);
390
431
  }
432
+ /**
433
+ * Runs fn, then ends the request, so that a failure in fn is recorded as
434
+ * an error rather than as a success.
435
+ *
436
+ * @internal
437
+ */
438
+ endAfter(fn) {
439
+ let result;
440
+ try {
441
+ result = fn();
442
+ }
443
+ catch (e) {
444
+ this.endWithError(e);
445
+ throw e;
446
+ }
447
+ this.end();
448
+ return result;
449
+ }
391
450
  /**
392
451
  * @internal
393
452
  */
@@ -444,6 +503,7 @@ class WrappedEncodingSpan {
444
503
  */
445
504
  class WrappedSpan {
446
505
  constructor(serviceName, opType, tracer, startTime, parentSpan) {
506
+ var _a, _b, _c;
447
507
  this._serviceName = serviceName;
448
508
  this._opType = opType;
449
509
  this._tracer = tracer;
@@ -454,6 +514,7 @@ class WrappedSpan {
454
514
  : this._parentSpan;
455
515
  this._hasMultipleEncodingSpans = this._opType == observabilitytypes_1.KeyValueOp.MutateIn;
456
516
  this._requestSpan = this._createRequestSpan(this._opType, startTime, pSpan);
517
+ this._isRecording = (_c = (_b = (_a = this._requestSpan).isRecording) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : true;
457
518
  this._endedEncodingSpans = false;
458
519
  this._startTime = startTime;
459
520
  this._endTimeWatermark = (0, observabilityutilities_1.timeInputToHiResTime)();
@@ -660,6 +721,9 @@ class WrappedSpan {
660
721
  * @internal
661
722
  */
662
723
  processCoreSpan(coreSpan) {
724
+ if (!this._isRecording) {
725
+ return;
726
+ }
663
727
  this._maybeSetAttributeFromCoreSpan(coreSpan, observabilitytypes_1.CppOpAttributeName.ClusterName);
664
728
  this._maybeSetAttributeFromCoreSpan(coreSpan, observabilitytypes_1.CppOpAttributeName.ClusterUUID);
665
729
  this._maybeSetAttributeFromCoreSpan(coreSpan, observabilitytypes_1.CppOpAttributeName.RetryCount, true);
@@ -705,6 +769,9 @@ class WrappedSpan {
705
769
  * @internal
706
770
  */
707
771
  setAttribute(key, value) {
772
+ if (!this._isRecording) {
773
+ return;
774
+ }
708
775
  if (key === observabilitytypes_1.OpAttributeName.ClusterName) {
709
776
  this._clusterName = value;
710
777
  }
@@ -263,52 +263,29 @@ var ServiceName;
263
263
  ServiceName["Transactions"] = "transactions";
264
264
  ServiceName["Views"] = "views";
265
265
  })(ServiceName || (exports.ServiceName = ServiceName = {}));
266
+ const _OP_TYPE_TO_SERVICE = new Map([
267
+ ...Object.values(KeyValueOp).map((v) => [v, ServiceName.KeyValue]),
268
+ ...Object.values(DatastructureOp).map((v) => [v, ServiceName.KeyValue]),
269
+ [StreamingOp.Analytics, ServiceName.Analytics],
270
+ [StreamingOp.Query, ServiceName.Query],
271
+ [StreamingOp.Search, ServiceName.Search],
272
+ [StreamingOp.View, ServiceName.Views],
273
+ ...Object.values(AnalyticsMgmtOp).map((v) => [v, ServiceName.Analytics]),
274
+ ...Object.values(BucketMgmtOp).map((v) => [v, ServiceName.Management]),
275
+ ...Object.values(CollectionMgmtOp).map((v) => [v, ServiceName.Management]),
276
+ ...Object.values(EventingFunctionMgmtOp).map((v) => [v, ServiceName.Eventing]),
277
+ ...Object.values(QueryIndexMgmtOp).map((v) => [v, ServiceName.Query]),
278
+ ...Object.values(SearchIndexMgmtOp).map((v) => [v, ServiceName.Search]),
279
+ ...Object.values(UserMgmtOp).map((v) => [v, ServiceName.Management]),
280
+ ...Object.values(ViewIndexMgmtOp).map((v) => [v, ServiceName.Views]),
281
+ ]);
266
282
  /**
267
283
  * @internal
268
284
  */
269
285
  function serviceNameFromOpType(opType) {
270
- if (Object.values(KeyValueOp).includes(opType)) {
271
- return ServiceName.KeyValue;
272
- }
273
- else if (Object.values(DatastructureOp).includes(opType)) {
274
- return ServiceName.KeyValue;
275
- }
276
- else if (Object.values(StreamingOp).includes(opType)) {
277
- switch (opType) {
278
- case StreamingOp.Analytics:
279
- return ServiceName.Analytics;
280
- case StreamingOp.Query:
281
- return ServiceName.Query;
282
- case StreamingOp.Search:
283
- return ServiceName.Search;
284
- case StreamingOp.View:
285
- return ServiceName.Views;
286
- }
287
- }
288
- else if (Object.values(AnalyticsMgmtOp).includes(opType)) {
289
- return ServiceName.Analytics;
290
- }
291
- else if (Object.values(BucketMgmtOp).includes(opType)) {
292
- return ServiceName.Management;
293
- }
294
- else if (Object.values(CollectionMgmtOp).includes(opType)) {
295
- return ServiceName.Management;
296
- }
297
- else if (Object.values(EventingFunctionMgmtOp).includes(opType)) {
298
- return ServiceName.Eventing;
299
- }
300
- else if (Object.values(QueryIndexMgmtOp).includes(opType)) {
301
- return ServiceName.Query;
302
- }
303
- else if (Object.values(SearchIndexMgmtOp).includes(opType)) {
304
- return ServiceName.Search;
305
- }
306
- else if (Object.values(UserMgmtOp).includes(opType)) {
307
- return ServiceName.Management;
308
- }
309
- else if (Object.values(ViewIndexMgmtOp).includes(opType)) {
310
- return ServiceName.Views;
311
- }
286
+ const svc = _OP_TYPE_TO_SERVICE.get(opType);
287
+ if (svc !== undefined)
288
+ return svc;
312
289
  throw new Error(`Unknown OpType: ${opType}`);
313
290
  }
314
291
  exports.serviceNameFromOpType = serviceNameFromOpType;
@@ -120,7 +120,7 @@ exports.timeInputToHiResTime = timeInputToHiResTime;
120
120
  function getAttributesForKeyValueOpType(opType, cppDocId, durability) {
121
121
  const attributes = {
122
122
  [observabilitytypes_1.OpAttributeName.SystemName]: 'couchbase',
123
- [observabilitytypes_1.OpAttributeName.Service]: (0, observabilitytypes_1.serviceNameFromOpType)(opType),
123
+ [observabilitytypes_1.OpAttributeName.Service]: observabilitytypes_1.ServiceName.KeyValue,
124
124
  [observabilitytypes_1.OpAttributeName.OperationName]: opType,
125
125
  [observabilitytypes_1.OpAttributeName.BucketName]: cppDocId.bucket,
126
126
  [observabilitytypes_1.OpAttributeName.ScopeName]: cppDocId.scope,
@@ -40,6 +40,11 @@ export declare class OTelWrapperSpan implements RequestSpan {
40
40
  * @param endTime - Optional timestamp for when the span ended.
41
41
  */
42
42
  end(endTime?: TimeInput): void;
43
+ /**
44
+ * Delegates to the underlying OTel span's isRecording, allowing the SDK
45
+ * to skip attribute and dispatch span work when the sampler dropped the span.
46
+ */
47
+ isRecording(): boolean;
43
48
  }
44
49
  /**
45
50
  * Wrapper class for OpenTelemetry Tracer that implements RequestTracer interface.
@@ -77,6 +77,13 @@ class OTelWrapperSpan {
77
77
  end(endTime) {
78
78
  this._otelSpan.end(endTime);
79
79
  }
80
+ /**
81
+ * Delegates to the underlying OTel span's isRecording, allowing the SDK
82
+ * to skip attribute and dispatch span work when the sampler dropped the span.
83
+ */
84
+ isRecording() {
85
+ return this._otelSpan.isRecording();
86
+ }
80
87
  }
81
88
  exports.OTelWrapperSpan = OTelWrapperSpan;
82
89
  /**
@@ -17,6 +17,15 @@ export declare class QueryExecutor {
17
17
  * @internal
18
18
  */
19
19
  get observabilityInstruments(): ObservabilityInstruments;
20
+ /**
21
+ * @internal
22
+ *
23
+ * Native callbacks swallow anything thrown out of them, so anything still
24
+ * thrown by the callback body (an 'error' emitted with no listener, or a
25
+ * throwing 'end' listener) is rethrown on a later tick, where it surfaces as
26
+ * an uncaught exception.
27
+ */
28
+ static _rethrowListenerErrors(fn: () => void): void;
20
29
  /**
21
30
  * @internal
22
31
  */
@@ -24,6 +24,24 @@ class QueryExecutor {
24
24
  get observabilityInstruments() {
25
25
  return this._cluster.observabilityInstruments;
26
26
  }
27
+ /**
28
+ * @internal
29
+ *
30
+ * Native callbacks swallow anything thrown out of them, so anything still
31
+ * thrown by the callback body (an 'error' emitted with no listener, or a
32
+ * throwing 'end' listener) is rethrown on a later tick, where it surfaces as
33
+ * an uncaught exception.
34
+ */
35
+ static _rethrowListenerErrors(fn) {
36
+ try {
37
+ fn();
38
+ }
39
+ catch (err) {
40
+ process.nextTick(() => {
41
+ throw err;
42
+ });
43
+ }
44
+ }
27
45
  /**
28
46
  * @internal
29
47
  */
@@ -212,6 +212,14 @@ class InternalQueryIndexManager {
212
212
  }, callback);
213
213
  }
214
214
  }
215
+ /**
216
+ * @internal
217
+ */
218
+ function _checkCollectionQueryIndexManagerOptions(options) {
219
+ if (options.collectionName !== undefined || options.scopeName !== undefined) {
220
+ throw new errors_1.InvalidArgumentError(new Error('collectionName and scopeName are not supported on CollectionQueryIndexManager. Use CollectionQueryIndexManager directly instead.'));
221
+ }
222
+ }
215
223
  /**
216
224
  * CollectionQueryIndexManager provides an interface for managing the
217
225
  * query indexes on the collection.
@@ -244,6 +252,7 @@ class CollectionQueryIndexManager {
244
252
  if (!options) {
245
253
  options = {};
246
254
  }
255
+ _checkCollectionQueryIndexManagerOptions(options);
247
256
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexCreate, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
248
257
  obsReqHandler.setRequestHttpAttributes();
249
258
  try {
@@ -277,6 +286,7 @@ class CollectionQueryIndexManager {
277
286
  if (!options) {
278
287
  options = {};
279
288
  }
289
+ _checkCollectionQueryIndexManagerOptions(options);
280
290
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexCreate, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
281
291
  obsReqHandler.setRequestHttpAttributes();
282
292
  try {
@@ -309,6 +319,7 @@ class CollectionQueryIndexManager {
309
319
  if (!options) {
310
320
  options = {};
311
321
  }
322
+ _checkCollectionQueryIndexManagerOptions(options);
312
323
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexDrop, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
313
324
  obsReqHandler.setRequestHttpAttributes();
314
325
  try {
@@ -339,6 +350,7 @@ class CollectionQueryIndexManager {
339
350
  if (!options) {
340
351
  options = {};
341
352
  }
353
+ _checkCollectionQueryIndexManagerOptions(options);
342
354
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexDrop, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
343
355
  obsReqHandler.setRequestHttpAttributes();
344
356
  try {
@@ -369,6 +381,7 @@ class CollectionQueryIndexManager {
369
381
  if (!options) {
370
382
  options = {};
371
383
  }
384
+ _checkCollectionQueryIndexManagerOptions(options);
372
385
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexGetAll, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
373
386
  obsReqHandler.setRequestHttpAttributes();
374
387
  try {
@@ -397,6 +410,7 @@ class CollectionQueryIndexManager {
397
410
  if (!options) {
398
411
  options = {};
399
412
  }
413
+ _checkCollectionQueryIndexManagerOptions(options);
400
414
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexBuildDeferred, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
401
415
  obsReqHandler.setRequestHttpAttributes();
402
416
  try {
@@ -427,6 +441,7 @@ class CollectionQueryIndexManager {
427
441
  if (!options) {
428
442
  options = {};
429
443
  }
444
+ _checkCollectionQueryIndexManagerOptions(options);
430
445
  const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.QueryIndexMgmtOp.QueryIndexWatchIndexes, this._manager.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
431
446
  obsReqHandler.setRequestHttpAttributes();
432
447
  try {
@@ -20,6 +20,10 @@ export declare class SearchExecutor {
20
20
  * @internal
21
21
  */
22
22
  get observabilityInstruments(): ObservabilityInstruments;
23
+ /**
24
+ * @internal
25
+ */
26
+ static _endWithError(emitter: StreamableRowPromise<SearchResult, SearchRow, SearchMetaData>, err: Error, obsReqHandler?: ObservableRequestHandler): void;
23
27
  /**
24
28
  * @internal
25
29
  */