Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 100c54b

Browse files
committed
Merge branch 'main' into databaserole_sessionlabels
2 parents cde4fa6 + 1058683 commit 100c54b

6 files changed

Lines changed: 21 additions & 10 deletions

File tree

observability-test/observability.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ describe('startTrace', () => {
126126
});
127127

128128
it('with semantic attributes', () => {
129-
const opts = {tableName: 'table', dbName: 'db'};
129+
const opts = {
130+
tableName: 'table',
131+
dbName: 'projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID',
132+
};
130133
startTrace('aSpan', opts, span => {
131134
assert.equal(
132135
span.attributes[ATTR_OTEL_SCOPE_NAME],
@@ -158,6 +161,12 @@ describe('startTrace', () => {
158161
'Missing gcp.client.repo attribute',
159162
);
160163

164+
assert.equal(
165+
span.attributes['gcp.resource.name'],
166+
'//spanner.googleapis.com/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID',
167+
'Missing gcp.resource.name attribute',
168+
);
169+
161170
assert.equal(
162171
span.attributes[SEMATTRS_DB_SQL_TABLE],
163172
'table',
@@ -166,7 +175,7 @@ describe('startTrace', () => {
166175

167176
assert.equal(
168177
span.attributes[SEMATTRS_DB_NAME],
169-
'db',
178+
'projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID',
170179
'Missing DB_NAME attribute',
171180
);
172181
});

samples/observability-traces.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function main(
3737
} = require('@opentelemetry/sdk-trace-base');
3838
const {Spanner} = require('@google-cloud/spanner');
3939

40-
const traceExporter = new TraceExporter();
40+
const traceExporter = new TraceExporter({projectId: projectId});
4141

4242
// Create a provider with a custom sampler
4343
const provider = new NodeTracerProvider({
@@ -81,7 +81,7 @@ async function main(
8181
spanner.close();
8282
}
8383

84-
provider.forceFlush();
84+
await provider.forceFlush();
8585

8686
// This sleep gives ample time for the trace
8787
// spans to be exported to Google Cloud Trace.

src/database.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,8 @@ class Database extends common.GrpcServiceObject {
473473
this.instance = instance;
474474

475475
const poolOpts = typeof poolOptions === 'object' ? poolOptions : null;
476-
this.databaseRole =
477-
databaseRole || (poolOpts && poolOpts.databaseRole) || null;
478-
this.labels =
479-
this._getSpanner().sessionLabels || (poolOpts && poolOpts.labels) || null;
476+
this.databaseRole = databaseRole || poolOpts?.databaseRole || null;
477+
this.labels = this._getSpanner().sessionLabels || poolOpts?.labels || null;
480478

481479
this._observabilityOptions = instance._observabilityOptions;
482480
this._traceConfig = {

src/instrument.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export function startTrace<T>(
150150
span.setAttribute('db.sql.table', config.tableName);
151151
}
152152
if (config.dbName) {
153+
span.setAttribute(
154+
'gcp.resource.name',
155+
`//spanner.googleapis.com/${config.dbName}`,
156+
);
153157
span.setAttribute('db.name', config.dbName);
154158
}
155159
if (config.requestTag) {

src/v1/instance_admin_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Google LLC
1+
// Copyright 2026 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

test/gapic_instance_admin_v1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Google LLC
1+
// Copyright 2026 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)