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

Commit b0b7da8

Browse files
committed
chore: Add gcp resouce name span attribute
1 parent 9b0a820 commit b0b7da8

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

observability-test/observability.ts

Lines changed: 10 additions & 1 deletion
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',

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) {

0 commit comments

Comments
 (0)