diff --git a/README.md b/README.md index 7f2e16e75..170d7dc6e 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Please use a tracer named "nodejs-spanner". `SPANNER_NODEJS_ANNOTATE_PII_SQL=1`, this is because SQL statements can be sensitive personally-identifiable-information (PII).** -To test out trace examination, you can use the Zipkin tracing service like this. +To test out trace examination, you can use Google Cloud Trace like this. ```javascript function exportSpans(instanceId, databaseId, projectId) { @@ -121,9 +121,8 @@ function exportSpans(instanceId, databaseId, projectId) { }) ); - const {ZipkinExporter} = require('@opentelemetry/exporter-zipkin'); - const options = {serviceName: 'nodejs-spanner'}; - const exporter = new ZipkinExporter(options); + const {TraceExporter} = require('@google-cloud/opentelemetry-cloud-trace-exporter'); + const exporter = new TraceExporter({}); const sdk = new NodeSDK({ resource: resource, diff --git a/samples/observability-traces.js b/samples/observability-traces.js index 5329b6693..058e8ec1f 100644 --- a/samples/observability-traces.js +++ b/samples/observability-traces.js @@ -42,9 +42,11 @@ function exportSpans(instanceId, databaseId, projectId) { }) ); - const {ZipkinExporter} = require('@opentelemetry/exporter-zipkin'); const options = {serviceName: 'nodejs-spanner'}; - const exporter = new ZipkinExporter(options); + const { + TraceExporter, + } = require('@google-cloud/opentelemetry-cloud-trace-exporter'); + const exporter = new TraceExporter({}); const sdk = new NodeSDK({ resource: resource, @@ -55,11 +57,10 @@ function exportSpans(instanceId, databaseId, projectId) { }); sdk.start(); - const {OTTracePropagator} = require('@opentelemetry/propagator-ot-trace'); const provider = new NodeTracerProvider({resource: resource}); provider.addSpanProcessor(new BatchSpanProcessor(exporter)); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); - provider.register({propagator: new OTTracePropagator()}); + provider.register(); // OpenTelemetry MUST be imported much earlier than the cloud-spanner package. const tracer = trace.getTracer('nodejs-spanner'); @@ -120,7 +121,6 @@ function exportSpans(instanceId, databaseId, projectId) { span.end(); spanner.close(); setTimeout(() => { - exporter.forceFlush(); console.log('finished delete and creation of the database'); }, 8000); }); diff --git a/samples/package.json b/samples/package.json index 4cd8ea809..cc6dd3dcf 100644 --- a/samples/package.json +++ b/samples/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@google-cloud/kms": "^4.0.0", - "@google-cloud/opentelemetry-cloud-trace-exporter": "^2.2.0", + "@google-cloud/opentelemetry-cloud-trace-exporter": "^2.3.0", "@google-cloud/precise-date": "^4.0.0", "@google-cloud/spanner": "^7.9.1", "@opentelemetry/api": "^1.9.0", diff --git a/src/session.ts b/src/session.ts index d8877121f..9d39386b9 100644 --- a/src/session.ts +++ b/src/session.ts @@ -236,7 +236,7 @@ export class Session extends common.GrpcServiceObject { optionsOrCallback: CreateSessionOptions | CreateSessionCallback, callback: CreateSessionCallback ) => { - const span = startTrace('cloud.google.com/nodejs/Session.create'); + const span = startTrace('Session.create'); const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; callback = @@ -379,7 +379,7 @@ export class Session extends common.GrpcServiceObject { optionsOrCallback?: CallOptions | GetSessionMetadataCallback, cb?: GetSessionMetadataCallback ): void | Promise { - const span = startTrace('cloud.google.com/nodejs/Session.getMetadata'); + const span = startTrace('Session.getMetadata'); const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; const callback = @@ -441,7 +441,7 @@ export class Session extends common.GrpcServiceObject { optionsOrCallback?: CallOptions | KeepAliveCallback, cb?: KeepAliveCallback ): void | Promise { - const span = startTrace('cloud.google.com/nodejs/Session.keepAlive'); + const span = startTrace('Session.keepAlive'); const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; const callback = diff --git a/src/v1/instrument.ts b/src/v1/instrument.ts index 27bcec6fa..2a535d3c7 100644 --- a/src/v1/instrument.ts +++ b/src/v1/instrument.ts @@ -39,7 +39,7 @@ registerInstrumentations({ instrumentations: [new GrpcInstrumentation(), new HttpInstrumentation()], }); -var optedInPII = process.env.SPANNER_NODEJS_ANNOTATE_PII_SQL === '1'; +const optedInPII = process.env.SPANNER_NODEJS_ANNOTATE_PII_SQL === '1'; interface SQLStatement { sql: string; @@ -49,7 +49,10 @@ interface SQLStatement { // scope change in which trying to use tracer.startActiveSpan // would change the meaning of this, and also introduction of callbacks // would radically change all the code structures making it more invasive. -export function startTrace(spanNameSuffix: string, sql?: string | SQLStatement): Span { +export function startTrace( + spanNameSuffix: string, + sql?: string | SQLStatement +): Span { const span = tracer.startSpan( 'cloud.google.com/nodejs/spanner/' + spanNameSuffix ); @@ -105,10 +108,7 @@ function callbackify(originalMethod: typeof CallbackMethod) { const cb = Array.prototype.pop.call(arguments); - console.log('cb.name', cb.name); - const span = startTrace( - 'cloud.google.com/nodejs/Spanner.' + cb.name + '.callbackify' - ); + const span = startTrace('Spanner.' + cb.name); originalMethod.apply(this, arguments).then( // tslint:disable-next-line:no-any (res: any) => { @@ -186,9 +186,8 @@ export function promisify( const slice = Array.prototype.slice; const wrapper: any = function (this: typeof WithPromise) { - const span = startTrace( - 'cloud.google.com/nodejs/Spanner.' + originalMethod.name + '.promisify' - ); + const span = startTrace('Spanner.' + originalMethod.name); + // tslint:disable-next-line:no-any let last;