@google-cloud/spanner 7.16.0 → 7.17.1

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.
@@ -25,6 +25,7 @@ const through = require("through2");
25
25
  const google_gax_1 = require("google-gax");
26
26
  const backup_1 = require("./backup");
27
27
  const batch_transaction_1 = require("./batch-transaction");
28
+ const session_factory_1 = require("./session-factory");
28
29
  const session_1 = require("./session");
29
30
  const session_pool_1 = require("./session-pool");
30
31
  const table_1 = require("./table");
@@ -55,6 +56,7 @@ const instrument_1 = require("./instrument");
55
56
  */
56
57
  class Database extends common.GrpcServiceObject {
57
58
  constructor(instance, name, poolOptions, queryOptions) {
59
+ var _a;
58
60
  const methods = {
59
61
  /**
60
62
  * Create a database.
@@ -140,17 +142,9 @@ class Database extends common.GrpcServiceObject {
140
142
  }
141
143
  },
142
144
  });
143
- this.pool_ =
144
- typeof poolOptions === 'function'
145
- ? new poolOptions(this, null)
146
- : new session_pool_1.SessionPool(this, poolOptions);
147
- const sessionPoolInstance = this.pool_;
148
- if (sessionPoolInstance) {
149
- sessionPoolInstance._observabilityOptions =
150
- instance._observabilityOptions;
151
- }
152
145
  if (typeof poolOptions === 'object') {
153
146
  this.databaseRole = poolOptions.databaseRole || null;
147
+ this.labels = poolOptions.labels || null;
154
148
  }
155
149
  this.formattedName_ = formattedName_;
156
150
  this.instance = instance;
@@ -159,15 +153,18 @@ class Database extends common.GrpcServiceObject {
159
153
  opts: this._observabilityOptions,
160
154
  dbName: this.formattedName_,
161
155
  };
162
- this.resourceHeader_ = {
163
- [common_1.CLOUD_RESOURCE_HEADER]: this.formattedName_,
164
- };
165
156
  this.request = instance.request;
166
157
  this._observabilityOptions = instance._observabilityOptions;
158
+ this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
167
159
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
160
  this.requestStream = instance.requestStream;
169
- this.pool_.on('error', this.emit.bind(this, 'error'));
170
- this.pool_.open();
161
+ this.sessionFactory_ = new session_factory_1.SessionFactory(this, name, poolOptions);
162
+ this.pool_ = this.sessionFactory_.getPool();
163
+ const sessionPoolInstance = this.pool_;
164
+ if (sessionPoolInstance) {
165
+ sessionPoolInstance._observabilityOptions =
166
+ instance._observabilityOptions;
167
+ }
171
168
  this.queryOptions_ = Object.assign(Object.assign({}, queryOptions), Database.getEnvironmentQueryOptions());
172
169
  }
173
170
  setMetadata(metadata, optionsOrCallback, cb) {
@@ -186,7 +183,7 @@ class Database extends common.GrpcServiceObject {
186
183
  method: 'updateDatabase',
187
184
  reqOpts,
188
185
  gaxOpts,
189
- headers: this.resourceHeader_,
186
+ headers: this.commonHeaders_,
190
187
  }, callback);
191
188
  }
192
189
  static getEnvironmentQueryOptions() {
@@ -212,7 +209,7 @@ class Database extends common.GrpcServiceObject {
212
209
  sessionTemplate: { labels: labels, creatorRole: databaseRole },
213
210
  sessionCount: count,
214
211
  };
215
- const headers = this.resourceHeader_;
212
+ const headers = this.commonHeaders_;
216
213
  if (this._getSpanner().routeToLeaderEnabled) {
217
214
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
218
215
  }
@@ -327,32 +324,35 @@ class Database extends common.GrpcServiceObject {
327
324
  database: this.formattedName_,
328
325
  };
329
326
  reqOpts.session = {};
330
- if (options.labels) {
331
- reqOpts.session.labels = options.labels;
332
- }
333
327
  if (options.multiplexed) {
334
328
  reqOpts.session.multiplexed = options.multiplexed;
335
329
  }
330
+ reqOpts.session.labels = options.labels || this.labels || null;
336
331
  reqOpts.session.creatorRole =
337
332
  options.databaseRole || this.databaseRole || null;
338
- const headers = this.resourceHeader_;
333
+ const headers = this.commonHeaders_;
339
334
  if (this._getSpanner().routeToLeaderEnabled) {
340
335
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
341
336
  }
342
- this.request({
343
- client: 'SpannerClient',
344
- method: 'createSession',
345
- reqOpts,
346
- gaxOpts: options.gaxOptions,
347
- headers: headers,
348
- }, (err, resp) => {
349
- if (err) {
350
- callback(err, null, resp);
351
- return;
352
- }
353
- const session = this.session(resp.name);
354
- session.metadata = resp;
355
- callback(null, session, resp);
337
+ (0, instrument_1.startTrace)('Database.createSession', this._traceConfig, span => {
338
+ this.request({
339
+ client: 'SpannerClient',
340
+ method: 'createSession',
341
+ reqOpts,
342
+ gaxOpts: options.gaxOptions,
343
+ headers: headers,
344
+ }, (err, resp) => {
345
+ if (err) {
346
+ (0, instrument_1.setSpanError)(span, err);
347
+ span.end();
348
+ callback(err, null, resp);
349
+ return;
350
+ }
351
+ const session = this.session(resp.name);
352
+ session.metadata = resp;
353
+ span.end();
354
+ callback(null, session, resp);
355
+ });
356
356
  });
357
357
  }
358
358
  createTable(schema, gaxOptionsOrCallback, cb) {
@@ -405,7 +405,7 @@ class Database extends common.GrpcServiceObject {
405
405
  method: 'dropDatabase',
406
406
  reqOpts,
407
407
  gaxOpts,
408
- headers: this.resourceHeader_,
408
+ headers: this.commonHeaders_,
409
409
  }, callback);
410
410
  });
411
411
  }
@@ -465,7 +465,7 @@ class Database extends common.GrpcServiceObject {
465
465
  method: 'getDatabase',
466
466
  reqOpts,
467
467
  gaxOpts,
468
- headers: this.resourceHeader_,
468
+ headers: this.commonHeaders_,
469
469
  }, (err, resp) => {
470
470
  if (resp) {
471
471
  this.metadata = resp;
@@ -519,7 +519,7 @@ class Database extends common.GrpcServiceObject {
519
519
  method: 'getDatabaseDdl',
520
520
  reqOpts,
521
521
  gaxOpts,
522
- headers: this.resourceHeader_,
522
+ headers: this.commonHeaders_,
523
523
  },
524
524
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
525
525
  (err, statements, ...args) => {
@@ -540,7 +540,7 @@ class Database extends common.GrpcServiceObject {
540
540
  method: 'getIamPolicy',
541
541
  reqOpts,
542
542
  gaxOpts: options.gaxOptions,
543
- headers: this.resourceHeader_,
543
+ headers: this.commonHeaders_,
544
544
  }, (err, resp) => {
545
545
  callback(err, resp);
546
546
  });
@@ -573,7 +573,7 @@ class Database extends common.GrpcServiceObject {
573
573
  method: 'listSessions',
574
574
  reqOpts,
575
575
  gaxOpts,
576
- headers: this.resourceHeader_,
576
+ headers: this.commonHeaders_,
577
577
  }, (err, sessions, nextPageRequest, ...args) => {
578
578
  if (err) {
579
579
  (0, instrument_1.setSpanError)(span, err);
@@ -656,7 +656,7 @@ class Database extends common.GrpcServiceObject {
656
656
  method: 'listSessionsStream',
657
657
  reqOpts,
658
658
  gaxOpts,
659
- headers: this.resourceHeader_,
659
+ headers: this.commonHeaders_,
660
660
  });
661
661
  }
662
662
  getSnapshot(optionsOrCallback, cb) {
@@ -666,6 +666,18 @@ class Database extends common.GrpcServiceObject {
666
666
  const options = typeof optionsOrCallback === 'object'
667
667
  ? optionsOrCallback
668
668
  : {};
669
+ if (('maxStaleness' in options &&
670
+ options.maxStaleness !== null &&
671
+ options.maxStaleness !== undefined) ||
672
+ ('minReadTimestamp' in options &&
673
+ options.minReadTimestamp !== null &&
674
+ options.minReadTimestamp !== undefined)) {
675
+ const error = Object.assign(new Error('maxStaleness / minReadTimestamp is not supported for multi-use read-only transactions.'), {
676
+ code: 3, // invalid argument
677
+ });
678
+ callback(error);
679
+ return;
680
+ }
669
681
  return (0, instrument_1.startTrace)('Database.getSnapshot', this._traceConfig, span => {
670
682
  this.pool_.getSession((err, session) => {
671
683
  if (err) {
@@ -725,12 +737,6 @@ class Database extends common.GrpcServiceObject {
725
737
  transaction._observabilityOptions = this._observabilityOptions;
726
738
  this._releaseOnEnd(session, transaction, span);
727
739
  }
728
- else if ((0, session_pool_1.isSessionNotFoundError)(err)) {
729
- span.addEvent('No session available', {
730
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
731
- });
732
- (0, instrument_1.setSpanError)(span, err);
733
- }
734
740
  else {
735
741
  (0, instrument_1.setSpanError)(span, err);
736
742
  }
@@ -775,7 +781,7 @@ class Database extends common.GrpcServiceObject {
775
781
  method: 'listDatabaseRoles',
776
782
  reqOpts,
777
783
  gaxOpts,
778
- headers: this.resourceHeader_,
784
+ headers: this.commonHeaders_,
779
785
  }, (err, roles, nextPageRequest, ...args) => {
780
786
  const nextQuery = nextPageRequest
781
787
  ? extend({}, gaxOpts, nextPageRequest)
@@ -834,11 +840,7 @@ class Database extends common.GrpcServiceObject {
834
840
  pool.getSession((err, session_) => {
835
841
  const span = (0, instrument_1.getActiveOrNoopSpan)();
836
842
  if (err) {
837
- if ((0, session_pool_1.isSessionNotFoundError)(err)) {
838
- span.addEvent('No session available', {
839
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
840
- });
841
- }
843
+ (0, instrument_1.setSpanError)(span, err);
842
844
  destroyStream(err);
843
845
  return;
844
846
  }
@@ -877,7 +879,7 @@ class Database extends common.GrpcServiceObject {
877
879
  method: 'restoreDatabase',
878
880
  reqOpts,
879
881
  gaxOpts,
880
- headers: this.resourceHeader_,
882
+ headers: this.commonHeaders_,
881
883
  }, (err, operation, resp) => {
882
884
  if (err) {
883
885
  callback(err, null, null, resp);
@@ -1316,10 +1318,12 @@ class Database extends common.GrpcServiceObject {
1316
1318
  }
1317
1319
  }
1318
1320
  catch (e) {
1319
- if (!(0, session_pool_1.isSessionNotFoundError)(e)) {
1321
+ if ((0, session_pool_1.isSessionNotFoundError)(e)) {
1320
1322
  span.addEvent('No session available', {
1321
1323
  'session.id': sessionId,
1322
1324
  });
1325
+ }
1326
+ else {
1323
1327
  span.end();
1324
1328
  throw e;
1325
1329
  }
@@ -1409,7 +1413,7 @@ class Database extends common.GrpcServiceObject {
1409
1413
  method: 'batchWrite',
1410
1414
  reqOpts,
1411
1415
  gaxOpts,
1412
- headers: this.resourceHeader_,
1416
+ headers: this.commonHeaders_,
1413
1417
  });
1414
1418
  dataStream
1415
1419
  .once('data', () => (dataReceived = true))
@@ -1525,7 +1529,7 @@ class Database extends common.GrpcServiceObject {
1525
1529
  method: 'setIamPolicy',
1526
1530
  reqOpts,
1527
1531
  gaxOpts: gaxOpts,
1528
- headers: this.resourceHeader_,
1532
+ headers: this.commonHeaders_,
1529
1533
  }, (err, resp) => {
1530
1534
  callback(err, resp);
1531
1535
  });
@@ -1552,7 +1556,7 @@ class Database extends common.GrpcServiceObject {
1552
1556
  method: 'updateDatabaseDdl',
1553
1557
  reqOpts,
1554
1558
  gaxOpts,
1555
- headers: this.resourceHeader_,
1559
+ headers: this.commonHeaders_,
1556
1560
  }, callback);
1557
1561
  }
1558
1562
  /**
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright 2024 Google LLC
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { grpc } from 'google-gax';
16
+ /**
17
+ * Checks whether the given error is a 'Database not found' error.
18
+ * @param {Error} error The error to check.
19
+ * @return {boolean} True if the error is a 'Database not found' error, and otherwise false.
20
+ */
21
+ export declare function isDatabaseNotFoundError(error: grpc.ServiceError | undefined): boolean;
22
+ /**
23
+ * Checks whether the given error is an 'Instance not found' error.
24
+ * @param {Error} error The error to check.
25
+ * @return {boolean} True if the error is an 'Instance not found' error, and otherwise false.
26
+ */
27
+ export declare function isInstanceNotFoundError(error: grpc.ServiceError | undefined): boolean;
28
+ /**
29
+ * Checks whether the given error is a 'Could not load the default credentials' error.
30
+ * @param {Error} error The error to check.
31
+ * @return {boolean} True if the error is a 'Could not load the default credentials' error, and otherwise false.
32
+ */
33
+ export declare function isDefaultCredentialsNotSetError(error: grpc.ServiceError | undefined): boolean;
34
+ /**
35
+ * Checks whether the given error is an 'Unable to detect a Project Id in the current environment' error.
36
+ * @param {Error} error The error to check.
37
+ * @return {boolean} True if the error is an 'Unable to detect a Project Id in the current environment' error, and otherwise false.
38
+ */
39
+ export declare function isProjectIdNotSetInEnvironmentError(error: grpc.ServiceError | undefined): boolean;
40
+ /**
41
+ * Checks whether the given error is a 'Create session permission' error.
42
+ * @param {Error} error The error to check.
43
+ * @return {boolean} True if the error is a 'Create session permission' error, and otherwise false.
44
+ */
45
+ export declare function isCreateSessionPermissionError(error: grpc.ServiceError | undefined): boolean;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2024 Google LLC
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.isDatabaseNotFoundError = isDatabaseNotFoundError;
18
+ exports.isInstanceNotFoundError = isInstanceNotFoundError;
19
+ exports.isDefaultCredentialsNotSetError = isDefaultCredentialsNotSetError;
20
+ exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentError;
21
+ exports.isCreateSessionPermissionError = isCreateSessionPermissionError;
22
+ const google_gax_1 = require("google-gax");
23
+ /**
24
+ * Checks whether the given error is a 'Database not found' error.
25
+ * @param {Error} error The error to check.
26
+ * @return {boolean} True if the error is a 'Database not found' error, and otherwise false.
27
+ */
28
+ function isDatabaseNotFoundError(error) {
29
+ return (error !== undefined &&
30
+ error.code === google_gax_1.grpc.status.NOT_FOUND &&
31
+ error.message.includes('Database not found'));
32
+ }
33
+ /**
34
+ * Checks whether the given error is an 'Instance not found' error.
35
+ * @param {Error} error The error to check.
36
+ * @return {boolean} True if the error is an 'Instance not found' error, and otherwise false.
37
+ */
38
+ function isInstanceNotFoundError(error) {
39
+ return (error !== undefined &&
40
+ error.code === google_gax_1.grpc.status.NOT_FOUND &&
41
+ error.message.includes('Instance not found'));
42
+ }
43
+ /**
44
+ * Checks whether the given error is a 'Could not load the default credentials' error.
45
+ * @param {Error} error The error to check.
46
+ * @return {boolean} True if the error is a 'Could not load the default credentials' error, and otherwise false.
47
+ */
48
+ function isDefaultCredentialsNotSetError(error) {
49
+ return (error !== undefined &&
50
+ error.message.includes('Could not load the default credentials'));
51
+ }
52
+ /**
53
+ * Checks whether the given error is an 'Unable to detect a Project Id in the current environment' error.
54
+ * @param {Error} error The error to check.
55
+ * @return {boolean} True if the error is an 'Unable to detect a Project Id in the current environment' error, and otherwise false.
56
+ */
57
+ function isProjectIdNotSetInEnvironmentError(error) {
58
+ return (error !== undefined &&
59
+ error.message.includes('Unable to detect a Project Id in the current environment'));
60
+ }
61
+ /**
62
+ * Checks whether the given error is a 'Create session permission' error.
63
+ * @param {Error} error The error to check.
64
+ * @return {boolean} True if the error is a 'Create session permission' error, and otherwise false.
65
+ */
66
+ function isCreateSessionPermissionError(error) {
67
+ return (error !== undefined &&
68
+ error.code === google_gax_1.grpc.status.PERMISSION_DENIED &&
69
+ error.message.includes('spanner.sessions.create'));
70
+ }
71
+ //# sourceMappingURL=helper.js.map
@@ -163,7 +163,7 @@ declare class Spanner extends GrpcService {
163
163
  instanceConfigs_: Map<string, InstanceConfig>;
164
164
  projectIdReplaced_: boolean;
165
165
  projectFormattedName_: string;
166
- resourceHeader_: {
166
+ commonHeaders_: {
167
167
  [k: string]: string;
168
168
  };
169
169
  routeToLeaderEnabled: boolean;
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "Numeric", { enumerable: true, get: function () {
33
33
  Object.defineProperty(exports, "PGNumeric", { enumerable: true, get: function () { return codec_1.PGNumeric; } });
34
34
  Object.defineProperty(exports, "SpannerDate", { enumerable: true, get: function () { return codec_1.SpannerDate; } });
35
35
  Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return codec_1.Struct; } });
36
+ const api_1 = require("@opentelemetry/api");
36
37
  const backup_1 = require("./backup");
37
38
  Object.defineProperty(exports, "Backup", { enumerable: true, get: function () { return backup_1.Backup; } });
38
39
  const database_1 = require("./database");
@@ -131,6 +132,7 @@ class Spanner extends service_1.GrpcService {
131
132
  return undefined;
132
133
  }
133
134
  constructor(options) {
135
+ var _a;
134
136
  const scopes = [];
135
137
  const clientClasses = [
136
138
  v1.DatabaseAdminClient,
@@ -196,11 +198,9 @@ class Spanner extends service_1.GrpcService {
196
198
  this.instanceConfigs_ = new Map();
197
199
  this.projectIdReplaced_ = false;
198
200
  this.projectFormattedName_ = 'projects/' + this.projectId;
199
- this.resourceHeader_ = {
200
- [common_1.CLOUD_RESOURCE_HEADER]: this.projectFormattedName_,
201
- };
202
201
  this.directedReadOptions = directedReadOptions;
203
202
  this._observabilityOptions = options.observabilityOptions;
203
+ this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
204
204
  (0, instrument_1.ensureInitialContextManagerSet)();
205
205
  }
206
206
  /**
@@ -291,7 +291,7 @@ class Spanner extends service_1.GrpcService {
291
291
  method: 'createInstance',
292
292
  reqOpts,
293
293
  gaxOpts: config.gaxOptions,
294
- headers: this.resourceHeader_,
294
+ headers: this.commonHeaders_,
295
295
  }, (err, operation, resp) => {
296
296
  if (err) {
297
297
  callback(err, null, null, resp);
@@ -329,7 +329,7 @@ class Spanner extends service_1.GrpcService {
329
329
  method: 'listInstances',
330
330
  reqOpts,
331
331
  gaxOpts,
332
- headers: this.resourceHeader_,
332
+ headers: this.commonHeaders_,
333
333
  }, (err, instances, nextPageRequest, ...args) => {
334
334
  let instanceInstances = null;
335
335
  if (instances) {
@@ -403,7 +403,7 @@ class Spanner extends service_1.GrpcService {
403
403
  method: 'listInstancesStream',
404
404
  reqOpts,
405
405
  gaxOpts,
406
- headers: this.resourceHeader_,
406
+ headers: this.commonHeaders_,
407
407
  });
408
408
  }
409
409
  createInstanceConfig(name, config, callback) {
@@ -443,7 +443,7 @@ class Spanner extends service_1.GrpcService {
443
443
  method: 'createInstanceConfig',
444
444
  reqOpts,
445
445
  gaxOpts: config.gaxOptions,
446
- headers: this.resourceHeader_,
446
+ headers: this.commonHeaders_,
447
447
  }, (err, operation, resp) => {
448
448
  if (err) {
449
449
  callback(err, null, null, resp);
@@ -478,7 +478,7 @@ class Spanner extends service_1.GrpcService {
478
478
  method: 'listInstanceConfigs',
479
479
  reqOpts,
480
480
  gaxOpts,
481
- headers: this.resourceHeader_,
481
+ headers: this.commonHeaders_,
482
482
  }, (err, instanceConfigs, nextPageRequest, ...args) => {
483
483
  const nextQuery = nextPageRequest
484
484
  ? extend({}, options, nextPageRequest)
@@ -542,7 +542,7 @@ class Spanner extends service_1.GrpcService {
542
542
  method: 'listInstanceConfigsStream',
543
543
  reqOpts,
544
544
  gaxOpts,
545
- headers: this.resourceHeader_,
545
+ headers: this.commonHeaders_,
546
546
  });
547
547
  }
548
548
  getInstanceConfig(name, optionsOrCallback, cb) {
@@ -559,7 +559,7 @@ class Spanner extends service_1.GrpcService {
559
559
  method: 'getInstanceConfig',
560
560
  reqOpts,
561
561
  gaxOpts,
562
- headers: this.resourceHeader_,
562
+ headers: this.commonHeaders_,
563
563
  }, (err, instanceConfig) => {
564
564
  callback(err, instanceConfig);
565
565
  });
@@ -589,7 +589,7 @@ class Spanner extends service_1.GrpcService {
589
589
  method: 'listInstanceConfigOperations',
590
590
  reqOpts,
591
591
  gaxOpts,
592
- headers: this.resourceHeader_,
592
+ headers: this.commonHeaders_,
593
593
  }, (err, operations, nextPageRequest, ...args) => {
594
594
  const nextQuery = nextPageRequest
595
595
  ? extend({}, options, nextPageRequest)
@@ -685,6 +685,12 @@ class Spanner extends service_1.GrpcService {
685
685
  this.projectIdReplaced_ = true;
686
686
  }
687
687
  config.headers[common_1.CLOUD_RESOURCE_HEADER] = (0, projectify_1.replaceProjectIdToken)(config.headers[common_1.CLOUD_RESOURCE_HEADER], projectId);
688
+ // Do context propagation
689
+ api_1.propagation.inject(api_1.context.active(), config.headers, {
690
+ set: (carrier, key, value) => {
691
+ carrier[key] = value; // Set the span context (trace and span ID)
692
+ },
693
+ });
688
694
  const requestFn = gaxClient[config.method].bind(gaxClient, reqOpts,
689
695
  // Add headers to `gaxOpts`
690
696
  extend(true, {}, config.gaxOpts, {
@@ -67,6 +67,7 @@ interface DeleteInstanceConfigRequest {
67
67
  * ```
68
68
  */
69
69
  declare class InstanceConfig extends common.GrpcServiceObject {
70
+ static [x: string]: any;
70
71
  formattedName_: string;
71
72
  request: InstanceConfigRequest;
72
73
  metadata?: IInstanceConfig;
@@ -93,12 +93,13 @@ interface InstanceRequest {
93
93
  * ```
94
94
  */
95
95
  declare class Instance extends common.GrpcServiceObject {
96
+ static [x: string]: any;
96
97
  formattedName_: string;
97
98
  request: InstanceRequest;
98
99
  requestStream: (config: RequestConfig) => Duplex;
99
100
  databases_: Map<string, Database>;
100
101
  metadata?: IInstance;
101
- resourceHeader_: {
102
+ commonHeaders_: {
102
103
  [k: string]: string;
103
104
  };
104
105
  _observabilityOptions?: ObservabilityOptions;
@@ -47,6 +47,7 @@ const protos_1 = require("../protos/protos");
47
47
  */
48
48
  class Instance extends common.GrpcServiceObject {
49
49
  constructor(spanner, name) {
50
+ var _a;
50
51
  const formattedName_ = Instance.formatName_(spanner.projectId, name);
51
52
  const methods = {
52
53
  /**
@@ -114,10 +115,8 @@ class Instance extends common.GrpcServiceObject {
114
115
  this.request = spanner.request.bind(spanner);
115
116
  this.requestStream = spanner.requestStream.bind(spanner);
116
117
  this.databases_ = new Map();
117
- this.resourceHeader_ = {
118
- [common_1.CLOUD_RESOURCE_HEADER]: this.formattedName_,
119
- };
120
118
  this._observabilityOptions = spanner._observabilityOptions;
119
+ this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
121
120
  }
122
121
  /**
123
122
  * Get a reference to a Backup object.
@@ -214,7 +213,7 @@ class Instance extends common.GrpcServiceObject {
214
213
  method: 'listBackups',
215
214
  reqOpts,
216
215
  gaxOpts,
217
- headers: this.resourceHeader_,
216
+ headers: this.commonHeaders_,
218
217
  }, (err, backups, nextPageRequest, ...args) => {
219
218
  let backupInstances = null;
220
219
  if (backups) {
@@ -290,7 +289,7 @@ class Instance extends common.GrpcServiceObject {
290
289
  method: 'listBackupsStream',
291
290
  reqOpts,
292
291
  gaxOpts,
293
- headers: this.resourceHeader_,
292
+ headers: this.commonHeaders_,
294
293
  });
295
294
  }
296
295
  /**
@@ -355,7 +354,7 @@ class Instance extends common.GrpcServiceObject {
355
354
  method: 'listBackupOperations',
356
355
  reqOpts,
357
356
  gaxOpts,
358
- headers: this.resourceHeader_,
357
+ headers: this.commonHeaders_,
359
358
  }, (err, operations, nextPageRequest, ...args) => {
360
359
  const nextQuery = nextPageRequest
361
360
  ? extend({}, options, nextPageRequest)
@@ -426,7 +425,7 @@ class Instance extends common.GrpcServiceObject {
426
425
  method: 'listDatabaseOperations',
427
426
  reqOpts,
428
427
  gaxOpts,
429
- headers: this.resourceHeader_,
428
+ headers: this.commonHeaders_,
430
429
  }, (err, operations, nextPageRequest, ...args) => {
431
430
  const nextQuery = nextPageRequest
432
431
  ? extend({}, options, nextPageRequest)
@@ -465,7 +464,7 @@ class Instance extends common.GrpcServiceObject {
465
464
  method: 'createDatabase',
466
465
  reqOpts,
467
466
  gaxOpts: options.gaxOptions,
468
- headers: this.resourceHeader_,
467
+ headers: this.commonHeaders_,
469
468
  }, (err, operation, resp) => {
470
469
  if (err) {
471
470
  callback(err, null, null, resp);
@@ -537,7 +536,7 @@ class Instance extends common.GrpcServiceObject {
537
536
  method: 'deleteInstance',
538
537
  reqOpts,
539
538
  gaxOpts,
540
- headers: this.resourceHeader_,
539
+ headers: this.commonHeaders_,
541
540
  }, (err, resp) => {
542
541
  if (!err) {
543
542
  this.parent.instances_.delete(this.id);
@@ -624,7 +623,7 @@ class Instance extends common.GrpcServiceObject {
624
623
  method: 'listDatabases',
625
624
  reqOpts,
626
625
  gaxOpts,
627
- headers: this.resourceHeader_,
626
+ headers: this.commonHeaders_,
628
627
  }, (err, rowDatabases, nextPageRequest, ...args) => {
629
628
  let databases = null;
630
629
  if (rowDatabases) {
@@ -701,7 +700,7 @@ class Instance extends common.GrpcServiceObject {
701
700
  method: 'listDatabasesStream',
702
701
  reqOpts,
703
702
  gaxOpts,
704
- headers: this.resourceHeader_,
703
+ headers: this.commonHeaders_,
705
704
  });
706
705
  }
707
706
  getMetadata(optionsOrCallback, cb) {
@@ -720,7 +719,7 @@ class Instance extends common.GrpcServiceObject {
720
719
  method: 'getInstance',
721
720
  reqOpts,
722
721
  gaxOpts: options.gaxOptions,
723
- headers: this.resourceHeader_,
722
+ headers: this.commonHeaders_,
724
723
  }, (err, resp) => {
725
724
  if (resp) {
726
725
  this.metadata = resp;
@@ -744,7 +743,7 @@ class Instance extends common.GrpcServiceObject {
744
743
  method: 'updateInstance',
745
744
  reqOpts,
746
745
  gaxOpts,
747
- headers: this.resourceHeader_,
746
+ headers: this.commonHeaders_,
748
747
  }, callback);
749
748
  }
750
749
  /**
@@ -20,6 +20,7 @@ interface SQLStatement {
20
20
  interface ObservabilityOptions {
21
21
  tracerProvider: TracerProvider;
22
22
  enableExtendedTracing?: boolean;
23
+ enableEndToEndTracing?: boolean;
23
24
  }
24
25
  export type { ObservabilityOptions };
25
26
  export type { Span };