Skip to content

Commit

Permalink
feat: add gcp client attributes for Opentelemetry traces
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Jan 10, 2025
1 parent 8d89b9a commit 3577804
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions observability-test/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ describe('startTrace', () => {
'Missing OTEL_SCOPE_VERSION attribute'
);

assert.equal(
span.attributes['gcp.client.service'],
'Spanner',
'Missing gcp.client.service attribute'
);

assert.equal(
span.attributes['gcp.client.version'],
TRACER_VERSION,
'Missing gcp.client.version attribute'
);

assert.equal(
span.attributes['gcp.client.repo'],
'googleapis/nodejs-spanner',
'Missing gcp.client.repo attribute'
);

assert.equal(
span.attributes[SEMATTRS_DB_SYSTEM],
'spanner',
Expand Down
3 changes: 3 additions & 0 deletions src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export function startTrace<T>(
span.setAttribute(SEMATTRS_DB_SYSTEM, 'spanner');
span.setAttribute(ATTR_OTEL_SCOPE_NAME, TRACER_NAME);
span.setAttribute(ATTR_OTEL_SCOPE_VERSION, TRACER_VERSION);
span.setAttribute('gcp.client.service', 'Spanner');
span.setAttribute('gcp.client.version', TRACER_VERSION);
span.setAttribute('gcp.client.repo', 'googleapis/nodejs-spanner');

if (config.tableName) {
span.setAttribute(SEMATTRS_DB_SQL_TABLE, config.tableName);
Expand Down

0 comments on commit 3577804

Please sign in to comment.