@google-cloud/spanner 7.15.0 → 7.17.0

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 (38) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +2 -0
  3. package/build/protos/google/spanner/admin/instance/v1/common.proto +7 -0
  4. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +139 -16
  5. package/build/protos/google/spanner/v1/commit_response.proto +9 -0
  6. package/build/protos/google/spanner/v1/result_set.proto +21 -0
  7. package/build/protos/google/spanner/v1/spanner.proto +61 -2
  8. package/build/protos/google/spanner/v1/transaction.proto +34 -0
  9. package/build/protos/google/spanner/v1/type.proto +43 -30
  10. package/build/protos/protos.d.ts +1724 -1112
  11. package/build/protos/protos.js +5185 -3528
  12. package/build/protos/protos.json +321 -129
  13. package/build/src/common.d.ts +8 -0
  14. package/build/src/common.js +19 -1
  15. package/build/src/database.d.ts +8 -1
  16. package/build/src/database.js +63 -56
  17. package/build/src/helper.d.ts +45 -0
  18. package/build/src/helper.js +71 -0
  19. package/build/src/index.d.ts +1 -1
  20. package/build/src/index.js +18 -11
  21. package/build/src/instance-config.d.ts +1 -0
  22. package/build/src/instance.d.ts +2 -1
  23. package/build/src/instance.js +12 -13
  24. package/build/src/instrument.d.ts +3 -0
  25. package/build/src/instrument.js +5 -1
  26. package/build/src/multiplexed-session.d.ts +136 -0
  27. package/build/src/multiplexed-session.js +197 -0
  28. package/build/src/session-factory.d.ts +101 -0
  29. package/build/src/session-factory.js +93 -0
  30. package/build/src/session-pool.d.ts +1 -39
  31. package/build/src/session-pool.js +6 -58
  32. package/build/src/session.d.ts +2 -1
  33. package/build/src/session.js +5 -6
  34. package/build/src/transaction.d.ts +1 -1
  35. package/build/src/transaction.js +8 -9
  36. package/build/src/v1/spanner_client.d.ts +44 -0
  37. package/build/src/v1/spanner_client.js +10 -0
  38. package/package.json +3 -2
@@ -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,29 +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;
327
+ if (options.multiplexed) {
328
+ reqOpts.session.multiplexed = options.multiplexed;
332
329
  }
330
+ reqOpts.session.labels = options.labels || this.labels || null;
333
331
  reqOpts.session.creatorRole =
334
332
  options.databaseRole || this.databaseRole || null;
335
- const headers = this.resourceHeader_;
333
+ const headers = this.commonHeaders_;
336
334
  if (this._getSpanner().routeToLeaderEnabled) {
337
335
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
338
336
  }
339
- this.request({
340
- client: 'SpannerClient',
341
- method: 'createSession',
342
- reqOpts,
343
- gaxOpts: options.gaxOptions,
344
- headers: headers,
345
- }, (err, resp) => {
346
- if (err) {
347
- callback(err, null, resp);
348
- return;
349
- }
350
- const session = this.session(resp.name);
351
- session.metadata = resp;
352
- 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
+ });
353
356
  });
354
357
  }
355
358
  createTable(schema, gaxOptionsOrCallback, cb) {
@@ -402,7 +405,7 @@ class Database extends common.GrpcServiceObject {
402
405
  method: 'dropDatabase',
403
406
  reqOpts,
404
407
  gaxOpts,
405
- headers: this.resourceHeader_,
408
+ headers: this.commonHeaders_,
406
409
  }, callback);
407
410
  });
408
411
  }
@@ -462,7 +465,7 @@ class Database extends common.GrpcServiceObject {
462
465
  method: 'getDatabase',
463
466
  reqOpts,
464
467
  gaxOpts,
465
- headers: this.resourceHeader_,
468
+ headers: this.commonHeaders_,
466
469
  }, (err, resp) => {
467
470
  if (resp) {
468
471
  this.metadata = resp;
@@ -516,7 +519,7 @@ class Database extends common.GrpcServiceObject {
516
519
  method: 'getDatabaseDdl',
517
520
  reqOpts,
518
521
  gaxOpts,
519
- headers: this.resourceHeader_,
522
+ headers: this.commonHeaders_,
520
523
  },
521
524
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
522
525
  (err, statements, ...args) => {
@@ -537,7 +540,7 @@ class Database extends common.GrpcServiceObject {
537
540
  method: 'getIamPolicy',
538
541
  reqOpts,
539
542
  gaxOpts: options.gaxOptions,
540
- headers: this.resourceHeader_,
543
+ headers: this.commonHeaders_,
541
544
  }, (err, resp) => {
542
545
  callback(err, resp);
543
546
  });
@@ -570,7 +573,7 @@ class Database extends common.GrpcServiceObject {
570
573
  method: 'listSessions',
571
574
  reqOpts,
572
575
  gaxOpts,
573
- headers: this.resourceHeader_,
576
+ headers: this.commonHeaders_,
574
577
  }, (err, sessions, nextPageRequest, ...args) => {
575
578
  if (err) {
576
579
  (0, instrument_1.setSpanError)(span, err);
@@ -653,7 +656,7 @@ class Database extends common.GrpcServiceObject {
653
656
  method: 'listSessionsStream',
654
657
  reqOpts,
655
658
  gaxOpts,
656
- headers: this.resourceHeader_,
659
+ headers: this.commonHeaders_,
657
660
  });
658
661
  }
659
662
  getSnapshot(optionsOrCallback, cb) {
@@ -663,6 +666,18 @@ class Database extends common.GrpcServiceObject {
663
666
  const options = typeof optionsOrCallback === 'object'
664
667
  ? optionsOrCallback
665
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
+ }
666
681
  return (0, instrument_1.startTrace)('Database.getSnapshot', this._traceConfig, span => {
667
682
  this.pool_.getSession((err, session) => {
668
683
  if (err) {
@@ -722,12 +737,6 @@ class Database extends common.GrpcServiceObject {
722
737
  transaction._observabilityOptions = this._observabilityOptions;
723
738
  this._releaseOnEnd(session, transaction, span);
724
739
  }
725
- else if ((0, session_pool_1.isSessionNotFoundError)(err)) {
726
- span.addEvent('No session available', {
727
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
728
- });
729
- (0, instrument_1.setSpanError)(span, err);
730
- }
731
740
  else {
732
741
  (0, instrument_1.setSpanError)(span, err);
733
742
  }
@@ -772,7 +781,7 @@ class Database extends common.GrpcServiceObject {
772
781
  method: 'listDatabaseRoles',
773
782
  reqOpts,
774
783
  gaxOpts,
775
- headers: this.resourceHeader_,
784
+ headers: this.commonHeaders_,
776
785
  }, (err, roles, nextPageRequest, ...args) => {
777
786
  const nextQuery = nextPageRequest
778
787
  ? extend({}, gaxOpts, nextPageRequest)
@@ -831,11 +840,7 @@ class Database extends common.GrpcServiceObject {
831
840
  pool.getSession((err, session_) => {
832
841
  const span = (0, instrument_1.getActiveOrNoopSpan)();
833
842
  if (err) {
834
- if ((0, session_pool_1.isSessionNotFoundError)(err)) {
835
- span.addEvent('No session available', {
836
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
837
- });
838
- }
843
+ (0, instrument_1.setSpanError)(span, err);
839
844
  destroyStream(err);
840
845
  return;
841
846
  }
@@ -874,7 +879,7 @@ class Database extends common.GrpcServiceObject {
874
879
  method: 'restoreDatabase',
875
880
  reqOpts,
876
881
  gaxOpts,
877
- headers: this.resourceHeader_,
882
+ headers: this.commonHeaders_,
878
883
  }, (err, operation, resp) => {
879
884
  if (err) {
880
885
  callback(err, null, null, resp);
@@ -1313,10 +1318,12 @@ class Database extends common.GrpcServiceObject {
1313
1318
  }
1314
1319
  }
1315
1320
  catch (e) {
1316
- if (!(0, session_pool_1.isSessionNotFoundError)(e)) {
1321
+ if ((0, session_pool_1.isSessionNotFoundError)(e)) {
1317
1322
  span.addEvent('No session available', {
1318
1323
  'session.id': sessionId,
1319
1324
  });
1325
+ }
1326
+ else {
1320
1327
  span.end();
1321
1328
  throw e;
1322
1329
  }
@@ -1406,7 +1413,7 @@ class Database extends common.GrpcServiceObject {
1406
1413
  method: 'batchWrite',
1407
1414
  reqOpts,
1408
1415
  gaxOpts,
1409
- headers: this.resourceHeader_,
1416
+ headers: this.commonHeaders_,
1410
1417
  });
1411
1418
  dataStream
1412
1419
  .once('data', () => (dataReceived = true))
@@ -1522,7 +1529,7 @@ class Database extends common.GrpcServiceObject {
1522
1529
  method: 'setIamPolicy',
1523
1530
  reqOpts,
1524
1531
  gaxOpts: gaxOpts,
1525
- headers: this.resourceHeader_,
1532
+ headers: this.commonHeaders_,
1526
1533
  }, (err, resp) => {
1527
1534
  callback(err, resp);
1528
1535
  });
@@ -1549,7 +1556,7 @@ class Database extends common.GrpcServiceObject {
1549
1556
  method: 'updateDatabaseDdl',
1550
1557
  reqOpts,
1551
1558
  gaxOpts,
1552
- headers: this.resourceHeader_,
1559
+ headers: this.commonHeaders_,
1553
1560
  }, callback);
1554
1561
  }
1555
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,12 +198,11 @@ 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
+ (0, instrument_1.ensureContextPropagation)();
205
206
  }
206
207
  /**
207
208
  * Gets the InstanceAdminClient object.
@@ -291,7 +292,7 @@ class Spanner extends service_1.GrpcService {
291
292
  method: 'createInstance',
292
293
  reqOpts,
293
294
  gaxOpts: config.gaxOptions,
294
- headers: this.resourceHeader_,
295
+ headers: this.commonHeaders_,
295
296
  }, (err, operation, resp) => {
296
297
  if (err) {
297
298
  callback(err, null, null, resp);
@@ -329,7 +330,7 @@ class Spanner extends service_1.GrpcService {
329
330
  method: 'listInstances',
330
331
  reqOpts,
331
332
  gaxOpts,
332
- headers: this.resourceHeader_,
333
+ headers: this.commonHeaders_,
333
334
  }, (err, instances, nextPageRequest, ...args) => {
334
335
  let instanceInstances = null;
335
336
  if (instances) {
@@ -403,7 +404,7 @@ class Spanner extends service_1.GrpcService {
403
404
  method: 'listInstancesStream',
404
405
  reqOpts,
405
406
  gaxOpts,
406
- headers: this.resourceHeader_,
407
+ headers: this.commonHeaders_,
407
408
  });
408
409
  }
409
410
  createInstanceConfig(name, config, callback) {
@@ -443,7 +444,7 @@ class Spanner extends service_1.GrpcService {
443
444
  method: 'createInstanceConfig',
444
445
  reqOpts,
445
446
  gaxOpts: config.gaxOptions,
446
- headers: this.resourceHeader_,
447
+ headers: this.commonHeaders_,
447
448
  }, (err, operation, resp) => {
448
449
  if (err) {
449
450
  callback(err, null, null, resp);
@@ -478,7 +479,7 @@ class Spanner extends service_1.GrpcService {
478
479
  method: 'listInstanceConfigs',
479
480
  reqOpts,
480
481
  gaxOpts,
481
- headers: this.resourceHeader_,
482
+ headers: this.commonHeaders_,
482
483
  }, (err, instanceConfigs, nextPageRequest, ...args) => {
483
484
  const nextQuery = nextPageRequest
484
485
  ? extend({}, options, nextPageRequest)
@@ -542,7 +543,7 @@ class Spanner extends service_1.GrpcService {
542
543
  method: 'listInstanceConfigsStream',
543
544
  reqOpts,
544
545
  gaxOpts,
545
- headers: this.resourceHeader_,
546
+ headers: this.commonHeaders_,
546
547
  });
547
548
  }
548
549
  getInstanceConfig(name, optionsOrCallback, cb) {
@@ -559,7 +560,7 @@ class Spanner extends service_1.GrpcService {
559
560
  method: 'getInstanceConfig',
560
561
  reqOpts,
561
562
  gaxOpts,
562
- headers: this.resourceHeader_,
563
+ headers: this.commonHeaders_,
563
564
  }, (err, instanceConfig) => {
564
565
  callback(err, instanceConfig);
565
566
  });
@@ -589,7 +590,7 @@ class Spanner extends service_1.GrpcService {
589
590
  method: 'listInstanceConfigOperations',
590
591
  reqOpts,
591
592
  gaxOpts,
592
- headers: this.resourceHeader_,
593
+ headers: this.commonHeaders_,
593
594
  }, (err, operations, nextPageRequest, ...args) => {
594
595
  const nextQuery = nextPageRequest
595
596
  ? extend({}, options, nextPageRequest)
@@ -685,6 +686,12 @@ class Spanner extends service_1.GrpcService {
685
686
  this.projectIdReplaced_ = true;
686
687
  }
687
688
  config.headers[common_1.CLOUD_RESOURCE_HEADER] = (0, projectify_1.replaceProjectIdToken)(config.headers[common_1.CLOUD_RESOURCE_HEADER], projectId);
689
+ // Do context propagation
690
+ api_1.propagation.inject(api_1.context.active(), config.headers, {
691
+ set: (carrier, key, value) => {
692
+ carrier[key] = value; // Set the span context (trace and span ID)
693
+ },
694
+ });
688
695
  const requestFn = gaxClient[config.method].bind(gaxClient, reqOpts,
689
696
  // Add headers to `gaxOpts`
690
697
  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 };
@@ -43,7 +44,9 @@ interface traceConfig {
43
44
  declare const SPAN_NAMESPACE_PREFIX = "CloudSpanner";
44
45
  export { SPAN_NAMESPACE_PREFIX, traceConfig };
45
46
  declare function ensureInitialContextManagerSet(): void;
47
+ declare function ensureContextPropagation(): void;
46
48
  export { ensureInitialContextManagerSet };
49
+ export { ensureContextPropagation };
47
50
  /**
48
51
  * startTrace begins an active span in the current active context
49
52
  * and passes it back to the set callback function. Each span will