Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions observability-test/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ const {SpanStatusCode, TracerProvider} = require('@opentelemetry/api');
// eslint-disable-next-line n/no-extraneous-require
const {SimpleSpanProcessor} = require('@opentelemetry/sdk-trace-base');
const {
TRACER_NAME,
TRACER_VERSION,
SPAN_NAMESPACE_PREFIX,
getActiveOrNoopSpan,
setSpanError,
setSpanErrorAndException,
startTrace,
} = require('../src/instrument');
const {
ATTR_OTEL_SCOPE_NAME,
ATTR_OTEL_SCOPE_VERSION,
SEMATTRS_DB_NAME,
SEMATTRS_DB_SQL_TABLE,
SEMATTRS_DB_STATEMENT,
Expand Down Expand Up @@ -129,6 +133,18 @@ describe('startTrace', () => {
it('with semantic attributes', () => {
const opts = {tableName: 'table', dbName: 'db'};
startTrace('aSpan', opts, span => {
assert.equal(
span.attributes[ATTR_OTEL_SCOPE_NAME],
TRACER_NAME,
'Missing OTEL_SCOPE_NAME attribute'
);

assert.equal(
span.attributes[ATTR_OTEL_SCOPE_VERSION],
TRACER_VERSION,
'Missing OTEL_SCOPE_VERSION attribute'
);

assert.equal(
span.attributes[SEMATTRS_DB_SYSTEM],
'spanner',
Expand Down
6 changes: 6 additions & 0 deletions src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

import {
ATTR_OTEL_SCOPE_NAME,
ATTR_OTEL_SCOPE_VERSION,
SEMATTRS_DB_NAME,
SEMATTRS_DB_STATEMENT,
SEMATTRS_DB_SYSTEM,
Expand Down Expand Up @@ -53,6 +55,8 @@ export type {observabilityOptions as ObservabilityOptions};
const TRACER_NAME = 'cloud.google.com/nodejs/spanner';
const TRACER_VERSION = '7.14.0'; // Manually hard coded, TODO: remove

export {TRACER_NAME, TRACER_VERSION}; // Only exported for testing.

/**
* getTracer fetches the tracer from the provided tracerProvider.
* @param {TracerProvider} [tracerProvider] optional custom tracer provider
Expand Down Expand Up @@ -102,6 +106,8 @@ export function startTrace<T>(
{kind: SpanKind.CLIENT},
span => {
span.setAttribute(SEMATTRS_DB_SYSTEM, 'spanner');
span.setAttribute(ATTR_OTEL_SCOPE_NAME, TRACER_NAME);
span.setAttribute(ATTR_OTEL_SCOPE_VERSION, TRACER_VERSION);

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