diff --git a/observability-test/batch-transaction.ts b/observability-test/batch-transaction.ts index 13ce59c5e..50e25abc5 100644 --- a/observability-test/batch-transaction.ts +++ b/observability-test/batch-transaction.ts @@ -139,7 +139,7 @@ describe('BatchTransaction', () => { batchTransaction = new BatchTransaction(SESSION as {} as Session); batchTransaction.session = SESSION as {} as Session; batchTransaction.id = ID; - batchTransaction.observabilityOptions = {tracerProvider: provider}; + batchTransaction.observabilityOptions_ = {tracerProvider: provider}; REQUEST.callsFake((_, callback) => callback(null, RESPONSE)); }); diff --git a/observability-test/table.ts b/observability-test/table.ts index 9b20780ae..14e135e2b 100644 --- a/observability-test/table.ts +++ b/observability-test/table.ts @@ -92,7 +92,7 @@ describe('Table', () => { extend(Table, TableCached); table = new Table(DATABASE, NAME); transaction = new FakeTransaction(); - table.observabilityOptions = {tracerProvider: provider}; + table.observabilityOptions_ = {tracerProvider: provider}; }); afterEach(() => { diff --git a/src/batch-transaction.ts b/src/batch-transaction.ts index cea784b03..067539812 100644 --- a/src/batch-transaction.ts +++ b/src/batch-transaction.ts @@ -139,7 +139,7 @@ class BatchTransaction extends Snapshot { const traceConfig: traceConfig = { sql: query, - opts: this.observabilityOptions, + opts: this.observabilityOptions_, }; return startTrace( 'BatchTransaction.createQueryPartitions', @@ -182,7 +182,7 @@ class BatchTransaction extends Snapshot { */ createPartitions_(config, callback) { const traceConfig: traceConfig = { - opts: this.observabilityOptions, + opts: this.observabilityOptions_, }; return startTrace( @@ -259,7 +259,7 @@ class BatchTransaction extends Snapshot { */ createReadPartitions(options, callback) { const traceConfig: traceConfig = { - opts: this.observabilityOptions, + opts: this.observabilityOptions_, }; return startTrace( diff --git a/src/database.ts b/src/database.ts index 84053f31d..3542ffe09 100644 --- a/src/database.ts +++ b/src/database.ts @@ -337,7 +337,7 @@ class Database extends common.GrpcServiceObject { databaseDialect?: EnumKey< typeof databaseAdmin.spanner.admin.database.v1.DatabaseDialect > | null; - observabilityConfig: ObservabilityOptions | undefined; + observabilityOptions_?: ObservabilityOptions; constructor( instance: Instance, name: string, @@ -460,7 +460,7 @@ class Database extends common.GrpcServiceObject { Object.assign({}, queryOptions), Database.getEnvironmentQueryOptions() ); - this.observabilityConfig = instance.observabilityConfig; + this.observabilityOptions_ = instance.observabilityOptions_; } /** * @typedef {array} SetDatabaseMetadataResponse @@ -1070,6 +1070,7 @@ class Database extends common.GrpcServiceObject { /CREATE TABLE `*([^\s`(]+)/ )![1]; const table = this.table(tableName!); + table.observabilityOptions_ = this.observabilityOptions_; callback!(null, table, operation!, resp!); }); } diff --git a/src/index.ts b/src/index.ts index 85266c0c1..c13877694 100644 --- a/src/index.ts +++ b/src/index.ts @@ -139,7 +139,7 @@ export interface SpannerOptions extends GrpcClientOptions { sslCreds?: grpc.ChannelCredentials; routeToLeaderEnabled?: boolean; directedReadOptions?: google.spanner.v1.IDirectedReadOptions | null; - observabilityConfig?: ObservabilityOptions | undefined; + observabilityOptions?: ObservabilityOptions; } export interface RequestConfig { client: string; @@ -241,7 +241,7 @@ class Spanner extends GrpcService { resourceHeader_: {[k: string]: string}; routeToLeaderEnabled = true; directedReadOptions: google.spanner.v1.IDirectedReadOptions | null; - observabilityConfig: ObservabilityOptions | undefined; + observabilityOptions_: ObservabilityOptions | undefined; /** * Placeholder used to auto populate a column with the commit timestamp. @@ -368,7 +368,7 @@ class Spanner extends GrpcService { [CLOUD_RESOURCE_HEADER]: this.projectFormattedName_, }; this.directedReadOptions = directedReadOptions; - this.observabilityConfig = options.observabilityConfig; + this.observabilityOptions_ = options.observabilityOptions; } /** @@ -589,7 +589,7 @@ class Spanner extends GrpcService { return; } const instance = this.instance(formattedName); - instance.observabilityConfig = this.observabilityConfig; + instance.observabilityOptions_ = this.observabilityOptions_; callback!(null, instance, operation, resp); } ); diff --git a/src/instance.ts b/src/instance.ts index f64249211..443f13bd3 100644 --- a/src/instance.ts +++ b/src/instance.ts @@ -165,7 +165,7 @@ class Instance extends common.GrpcServiceObject { databases_: Map; metadata?: IInstance; resourceHeader_: {[k: string]: string}; - observabilityConfig: ObservabilityOptions | undefined; + observabilityOptions_?: ObservabilityOptions; constructor(spanner: Spanner, name: string) { const formattedName_ = Instance.formatName_(spanner.projectId, name); const methods = { @@ -241,7 +241,7 @@ class Instance extends common.GrpcServiceObject { this.resourceHeader_ = { [CLOUD_RESOURCE_HEADER]: this.formattedName_, }; - this.observabilityConfig = spanner.observabilityConfig; + this.observabilityOptions_ = spanner.observabilityOptions_; } /** @@ -928,7 +928,7 @@ class Instance extends common.GrpcServiceObject { return; } const database = this.database(name, poolOptions || poolCtor); - database.observabilityConfig = this.observabilityConfig; + database.observabilityOptions_ = this.observabilityOptions_; callback(null, database, operation, resp); } ); @@ -978,7 +978,7 @@ class Instance extends common.GrpcServiceObject { const key = name.split('/').pop() + optionsKey; if (!this.databases_.has(key!)) { const db = new Database(this, name, poolOptions, queryOptions); - db.observabilityConfig = this.observabilityConfig; + db.observabilityOptions_ = this.observabilityOptions_; this.databases_.set(key!, db); } return this.databases_.get(key!)!; diff --git a/src/instrument.ts b/src/instrument.ts index c7a4059e4..2f80dcb5d 100644 --- a/src/instrument.ts +++ b/src/instrument.ts @@ -45,12 +45,12 @@ interface SQLStatement { sql: string; } -interface observabilityOptions { +interface ObservabilityOptions { tracerProvider: TracerProvider; enableExtendedTracing?: boolean; } -export type {observabilityOptions as ObservabilityOptions}; +export type {ObservabilityOptions}; const TRACER_NAME = 'cloud.google.com/nodejs/spanner'; const TRACER_VERSION = require('../../package.json').version; @@ -76,7 +76,7 @@ interface traceConfig { sql?: string | SQLStatement; tableName?: string; dbName?: string; - opts?: observabilityOptions; + opts?: ObservabilityOptions; that?: Object; } diff --git a/src/table.ts b/src/table.ts index 87e07db89..1e5078b73 100644 --- a/src/table.ts +++ b/src/table.ts @@ -99,7 +99,7 @@ const POSTGRESQL = 'POSTGRESQL'; class Table { database: Database; name: string; - observabilityOptions?: ObservabilityOptions; + observabilityOptions_?: ObservabilityOptions; constructor(database: Database, name: string) { /** * The {@link Database} instance of this {@link Table} instance. @@ -113,6 +113,7 @@ class Table { * @type {string} */ this.name = name; + this.observabilityOptions_ = database.observabilityOptions_; } /** * Create a table. @@ -1080,7 +1081,7 @@ class Table { callback: CommitCallback ): void { const traceConfig: traceConfig = { - opts: this.observabilityOptions, + opts: this.observabilityOptions_, }; startTrace('Table.' + method, traceConfig, span => { diff --git a/src/transaction.ts b/src/transaction.ts index 1a375ff0f..60366a58b 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -286,7 +286,7 @@ export class Snapshot extends EventEmitter { queryOptions?: IQueryOptions; resourceHeader_: {[k: string]: string}; requestOptions?: Pick; - observabilityOptions?: ObservabilityOptions; + observabilityOptions_?: ObservabilityOptions; /** * The transaction ID. diff --git a/test/spanner.ts b/test/spanner.ts index b7dae3b21..5318ea510 100644 --- a/test/spanner.ts +++ b/test/spanner.ts @@ -5062,7 +5062,7 @@ describe('Spanner with mock server', () => { }); }); - it('Plumb ObservabilityConfig into Spanner, Instance and Database', () => { + it('Plumb observabilityOptions_ into Spanner, Instance and Database', () => { const exporter = new InMemorySpanExporter(); const provider = new NodeTracerProvider({ sampler: new AlwaysOnSampler(), @@ -5070,7 +5070,7 @@ describe('Spanner with mock server', () => { }); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - const observabilityConfig: typeof ObservabilityOptions = { + const observabilityOptions: typeof ObservabilityOptions = { tracerProvider: provider, enableExtendedTracing: true, }; @@ -5078,31 +5078,31 @@ describe('Spanner with mock server', () => { servicePath: 'localhost', port, sslCreds: grpc.credentials.createInsecure(), - observabilityConfig: observabilityConfig, + observabilityOptions: observabilityOptions, }); // Ensure that the same observability configuration is set on the Spanner client. - assert.deepStrictEqual(spanner.observabilityConfig, observabilityConfig); + assert.deepStrictEqual(spanner.observabilityOptions_, observabilityOptions); // Acquire a handle to the Instance through spanner.instance. const instanceByHandle = spanner.instance('instance'); assert.deepStrictEqual( - instanceByHandle.observabilityConfig, - observabilityConfig + instanceByHandle.observabilityOptions_, + observabilityOptions ); // Create the Instance by means of a constructor directly. const instanceByConstructor = new Instance(spanner, 'myInstance'); assert.deepStrictEqual( - instanceByConstructor.observabilityConfig, - observabilityConfig + instanceByConstructor.observabilityOptions_, + observabilityOptions ); // Acquire a handle to the Database through instance.database. const databaseByHandle = instanceByHandle.database('database'); assert.deepStrictEqual( - databaseByHandle.observabilityConfig, - observabilityConfig + databaseByHandle.observabilityOptions_, + observabilityOptions ); // Create the Database by means of a constructor directly. @@ -5111,8 +5111,8 @@ describe('Spanner with mock server', () => { 'myDatabase' ); assert.deepStrictEqual( - databaseByConstructor.observabilityConfig, - observabilityConfig + databaseByConstructor.observabilityOptions_, + observabilityOptions ); spanner.close();