Skip to content

Commit

Permalink
all: suffix observabilityOptions with "_" to signal private membership
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Sep 30, 2024
1 parent 1f21470 commit 09450a1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion observability-test/batch-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

Expand Down
2 changes: 1 addition & 1 deletion observability-test/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/batch-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class BatchTransaction extends Snapshot {

const traceConfig: traceConfig = {
sql: query,
opts: this.observabilityOptions,
opts: this.observabilityOptions_,
};
return startTrace(
'BatchTransaction.createQueryPartitions',
Expand Down Expand Up @@ -182,7 +182,7 @@ class BatchTransaction extends Snapshot {
*/
createPartitions_(config, callback) {
const traceConfig: traceConfig = {
opts: this.observabilityOptions,
opts: this.observabilityOptions_,
};

return startTrace(
Expand Down Expand Up @@ -259,7 +259,7 @@ class BatchTransaction extends Snapshot {
*/
createReadPartitions(options, callback) {
const traceConfig: traceConfig = {
opts: this.observabilityOptions,
opts: this.observabilityOptions_,
};

return startTrace(
Expand Down
5 changes: 3 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -368,7 +368,7 @@ class Spanner extends GrpcService {
[CLOUD_RESOURCE_HEADER]: this.projectFormattedName_,
};
this.directedReadOptions = directedReadOptions;
this.observabilityConfig = options.observabilityConfig;
this.observabilityOptions_ = options.observabilityOptions;
}

/**
Expand Down Expand Up @@ -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);
}
);
Expand Down
8 changes: 4 additions & 4 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Instance extends common.GrpcServiceObject {
databases_: Map<string, Database>;
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 = {
Expand Down Expand Up @@ -241,7 +241,7 @@ class Instance extends common.GrpcServiceObject {
this.resourceHeader_ = {
[CLOUD_RESOURCE_HEADER]: this.formattedName_,
};
this.observabilityConfig = spanner.observabilityConfig;
this.observabilityOptions_ = spanner.observabilityOptions_;
}

/**
Expand Down Expand Up @@ -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);
}
);
Expand Down Expand Up @@ -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!)!;
Expand Down
6 changes: 3 additions & 3 deletions src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -76,7 +76,7 @@ interface traceConfig {
sql?: string | SQLStatement;
tableName?: string;
dbName?: string;
opts?: observabilityOptions;
opts?: ObservabilityOptions;
that?: Object;
}

Expand Down
5 changes: 3 additions & 2 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -113,6 +113,7 @@ class Table {
* @type {string}
*/
this.name = name;
this.observabilityOptions_ = database.observabilityOptions_;
}
/**
* Create a table.
Expand Down Expand Up @@ -1080,7 +1081,7 @@ class Table {
callback: CommitCallback
): void {
const traceConfig: traceConfig = {
opts: this.observabilityOptions,
opts: this.observabilityOptions_,
};

startTrace('Table.' + method, traceConfig, span => {
Expand Down
2 changes: 1 addition & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class Snapshot extends EventEmitter {
queryOptions?: IQueryOptions;
resourceHeader_: {[k: string]: string};
requestOptions?: Pick<IRequestOptions, 'transactionTag'>;
observabilityOptions?: ObservabilityOptions;
observabilityOptions_?: ObservabilityOptions;

/**
* The transaction ID.
Expand Down
24 changes: 12 additions & 12 deletions test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5062,47 +5062,47 @@ 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(),
exporter: exporter,
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

const observabilityConfig: typeof ObservabilityOptions = {
const observabilityOptions: typeof ObservabilityOptions = {
tracerProvider: provider,
enableExtendedTracing: true,
};
const spanner = new Spanner({
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.
Expand All @@ -5111,8 +5111,8 @@ describe('Spanner with mock server', () => {
'myDatabase'
);
assert.deepStrictEqual(
databaseByConstructor.observabilityConfig,
observabilityConfig
databaseByConstructor.observabilityOptions_,
observabilityOptions
);

spanner.close();
Expand Down

0 comments on commit 09450a1

Please sign in to comment.