diff --git a/package.json b/package.json index 9b538ef9..71e15729 100644 --- a/package.json +++ b/package.json @@ -83,8 +83,8 @@ "all": true }, "dependencies": { - "@opencensus/core": "0.0.9", - "@opencensus/propagation-b3": "0.0.8", + "@opencensus/core": "0.0.22", + "@opencensus/propagation-b3": "0.0.22", "async": "~2.6.1", "debug": "~4.3.1", "eventemitter2": "^6.3.1", diff --git a/src/census/exporter.ts b/src/census/exporter.ts index fe9c1754..b4d46699 100644 --- a/src/census/exporter.ts +++ b/src/census/exporter.ts @@ -1,7 +1,7 @@ import { Transport } from '../services/transport' import { ServiceManager } from '../serviceManager' import { TracingConfig } from 'src/features/tracing' -import { Exporter, ExporterBuffer, ExporterConfig, RootSpan, Span, SpanKind, Attributes, CanonicalCode } from '@opencensus/core' +import { Exporter, ExporterBuffer, ExporterConfig, Span, SpanKind, Attributes, CanonicalCode } from '@opencensus/core' import { defaultConfig } from './config/default-config' import { Constants } from './constants' @@ -58,19 +58,19 @@ export class CustomCensusExporter implements Exporter { * Is called whenever a span is ended. * @param root the ended span */ - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.buffer.addToBuffer(root) } // tslint:disable-next-line:no-empty - onStartSpan (root: RootSpan) {} + onStartSpan (root: Span) {} /** * Send a trace to zipkin service * @param zipkinTraces Trace translated to Zipkin Service */ private sendTraces (zipkinTraces: TranslatedSpan[]) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { zipkinTraces.forEach(span => { const isRootClient = span.kind === 'CLIENT' && !span.parentId if (isRootClient && this.config.outbound === false) return @@ -80,7 +80,7 @@ export class CustomCensusExporter implements Exporter { this.transport.send('trace-span', span) } }) - resolve() + resolve(null) }) } @@ -88,7 +88,7 @@ export class CustomCensusExporter implements Exporter { * Mount a list (array) of spans translated to Zipkin format * @param rootSpans Rootspan array to be translated */ - private mountSpanList (rootSpans: RootSpan[]): TranslatedSpan[] { + private mountSpanList (rootSpans: Span[]): TranslatedSpan[] { const spanList: TranslatedSpan[] = [] for (const root of rootSpans) { @@ -109,7 +109,7 @@ export class CustomCensusExporter implements Exporter { * @param span Span to be translated * @param rootSpan Only necessary if the span has rootSpan */ - private translateSpan (span: Span | RootSpan): TranslatedSpan { + private translateSpan (span: Span | Span): TranslatedSpan { const spanTranslated = { traceId: span.traceId, name: span.name, @@ -138,7 +138,7 @@ export class CustomCensusExporter implements Exporter { * Send the rootSpans to zipkin service * @param rootSpans RootSpan array */ - publish (rootSpans: RootSpan[]) { + publish (rootSpans: Span[]) { const spanList = this.mountSpanList(rootSpans) return this.sendTraces(spanList).catch((err) => { diff --git a/src/census/plugins/__tests__/express.spec.ts b/src/census/plugins/__tests__/express.spec.ts index f7586d1c..5340aada 100644 --- a/src/census/plugins/__tests__/express.spec.ts +++ b/src/census/plugins/__tests__/express.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, SpanEventListener, logger } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger } from '@opencensus/core' import * as assert from 'assert' import * as express from 'express' import * as http from 'http' @@ -25,12 +25,12 @@ import { AddressInfo } from 'net' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } diff --git a/src/census/plugins/__tests__/http.spec.ts b/src/census/plugins/__tests__/http.spec.ts index aef761f6..640fe483 100644 --- a/src/census/plugins/__tests__/http.spec.ts +++ b/src/census/plugins/__tests__/http.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, HeaderGetter, HeaderSetter, Propagation, RootSpan, Span, SpanContext, SpanEventListener, logger } from '@opencensus/core' +import { CoreTracer, HeaderGetter, HeaderSetter, Propagation, Span, SpanContext, SpanEventListener, logger } from '@opencensus/core' import * as assert from 'assert' import * as http from 'http' import * as nock from 'nock' @@ -67,12 +67,12 @@ class DummyPropagation implements Propagation { } class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -195,7 +195,7 @@ describe('HttpPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1' doNock(urlHost, testPath, 200, 'Ok') const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { await httpRequest.get(`${urlHost}${testPath}`).then((result) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) assert.strictEqual(root.spans.length, 1) @@ -216,7 +216,7 @@ describe('HttpPlugin', () => { urlHost, testPath, httpErrorCodes[i], httpErrorCodes[i].toString()) const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { await httpRequest.get(`${urlHost}${testPath}`).then((result) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) assert.strictEqual(root.spans.length, 1) @@ -237,7 +237,7 @@ describe('HttpPlugin', () => { const num = 5 doNock(urlHost, testPath, 200, 'Ok', num) const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) for (let i = 0; i < num; i++) { await httpRequest.get(`${urlHost}${testPath}`).then((result) => { diff --git a/src/census/plugins/__tests__/http2.spec.ts b/src/census/plugins/__tests__/http2.spec.ts index 5cb1a863..8fe05306 100644 --- a/src/census/plugins/__tests__/http2.spec.ts +++ b/src/census/plugins/__tests__/http2.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, Span, SpanEventListener, logger } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger } from '@opencensus/core' import * as assert from 'assert' import * as http2 from 'http2' import * as semver from 'semver' @@ -24,12 +24,12 @@ import { plugin, Http2Plugin } from '../http2' const VERSION = process.versions.node class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (root: RootSpan): void { + onStartSpan (root: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -168,7 +168,7 @@ describe('Http2Plugin', () => { const requestOptions = { ':method': 'GET', ':path': testPath } const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { await http2Request.get(client, requestOptions).then((result) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) assert.strictEqual(root.spans.length, 1) @@ -189,7 +189,7 @@ describe('Http2Plugin', () => { const requestOptions = { ':method': 'GET', ':path': testPath } const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { await http2Request.get(client, requestOptions).then((result) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) assert.strictEqual(root.spans.length, 1) @@ -211,7 +211,7 @@ describe('Http2Plugin', () => { const num = 5 const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) for (let i = 0; i < num; i++) { await http2Request.get(client, requestOptions).then((result) => { diff --git a/src/census/plugins/__tests__/https.spec.ts b/src/census/plugins/__tests__/https.spec.ts index e121079c..62a4ef76 100644 --- a/src/census/plugins/__tests__/https.spec.ts +++ b/src/census/plugins/__tests__/https.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, Span, SpanEventListener, logger } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger } from '@opencensus/core' import * as assert from 'assert' import * as fs from 'fs' import * as https from 'https' @@ -64,12 +64,12 @@ const httpRequest = { const VERSION = process.versions.node class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -201,7 +201,7 @@ describe('HttpsPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1' doNock(urlHost, testPath, 200, 'Ok') const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { await requestMethod(`${urlHost}${testPath}`).then((result) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) assert.strictEqual(root.spans.length, 1) @@ -223,7 +223,7 @@ describe('HttpsPlugin', () => { urlHost, testPath, httpErrorCodes[i], httpErrorCodes[i].toString()) const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { await requestMethod(`${urlHost}${testPath}`).then((result) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) assert.strictEqual(root.spans.length, 1) @@ -244,7 +244,7 @@ describe('HttpsPlugin', () => { const num = 5 doNock(urlHost, testPath, 200, 'Ok', num) const options = { name: 'TestRootSpan' } - return tracer.startRootSpan(options, async (root: RootSpan) => { + return tracer.startRootSpan(options, async (root: Span) => { assert.ok(root.name.indexOf('TestRootSpan') >= 0) for (let i = 0; i < num; i++) { await requestMethod(`${urlHost}${testPath}`).then((result) => { diff --git a/src/census/plugins/__tests__/ioredis.spec.ts b/src/census/plugins/__tests__/ioredis.spec.ts index 6a3acc1d..b1a4e43c 100644 --- a/src/census/plugins/__tests__/ioredis.spec.ts +++ b/src/census/plugins/__tests__/ioredis.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, SpanEventListener, Span, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, SpanEventListener, Span, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as ioredis from 'ioredis' @@ -22,12 +22,12 @@ import { plugin, IORedisPluginConfig } from '../ioredis' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -114,7 +114,7 @@ describe('RedisPlugin', () => { /** Should intercept query */ describe('Instrumenting query operations', () => { it('should create a child span for hset', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.hset('hash', 'random', 'random', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -129,7 +129,7 @@ describe('RedisPlugin', () => { }) it('should create a child span for get', (done) => { - tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: Span) => { client.get('test', (err, result) => { assert.ifError(err) assert.strictEqual(result, 'data') @@ -145,7 +145,7 @@ describe('RedisPlugin', () => { }) it('should create a child span for del', (done) => { - tracer.startRootSpan({ name: 'removeRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'removeRootSpan' }, async (rootSpan: Span) => { await client.del('test') assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() @@ -161,7 +161,7 @@ describe('RedisPlugin', () => { plugin.disable() const conf: IORedisPluginConfig = { detailedCommands: true } plugin.enable(ioredis, tracer, VERSION, conf, '') - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.set('test', 'data', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -183,7 +183,7 @@ describe('RedisPlugin', () => { }) it('should not create a child span for insert', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.hset('hash', 'random', 'random', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -197,7 +197,7 @@ describe('RedisPlugin', () => { }) it('should not create a child span for get', (done) => { - tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: Span) => { client.get('test', (err, result) => { assert.ifError(err) assert.strictEqual(result, 'data') @@ -211,7 +211,7 @@ describe('RedisPlugin', () => { }) it('should not create a child span for del', (done) => { - tracer.startRootSpan({ name: 'removeRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'removeRootSpan' }, async (rootSpan: Span) => { await client.del('test') assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() diff --git a/src/census/plugins/__tests__/mongodb.spec.ts b/src/census/plugins/__tests__/mongodb.spec.ts index 7f1beadf..5f940989 100644 --- a/src/census/plugins/__tests__/mongodb.spec.ts +++ b/src/census/plugins/__tests__/mongodb.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, SpanEventListener, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as mongodb from 'mongodb-core' import { parse } from 'url' @@ -28,12 +28,12 @@ export type MongoDBAccess = { /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -139,7 +139,7 @@ describe('MongoDBPlugin', () => { it('should create a child span for insert', (done) => { const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }] - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.insert(`${DB_NAME}.${COLLECTION_NAME}`, insertData, (err, result) => { assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() @@ -151,7 +151,7 @@ describe('MongoDBPlugin', () => { }) it('should create a child span for update', (done) => { - tracer.startRootSpan({ name: 'updateRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'updateRootSpan' }, (rootSpan: Span) => { client.update(`${DB_NAME}.${COLLECTION_NAME}`, [ { q: { a: 2 }, u: { $set: { b: 1 } } }], (err, result) => { assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() @@ -163,7 +163,7 @@ describe('MongoDBPlugin', () => { }) it('should create a child span for remove', (done) => { - tracer.startRootSpan({ name: 'removeRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'removeRootSpan' }, (rootSpan: Span) => { client.remove(`${DB_NAME}.${COLLECTION_NAME}`, [{ q: { a: 3 }, limit: 0 }], (err, result) => { assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() @@ -178,7 +178,7 @@ describe('MongoDBPlugin', () => { /** Should intercept cursor */ describe('Instrumenting cursor operations', () => { it('should create a child span for find', (done) => { - tracer.startRootSpan({ name: 'findRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'findRootSpan' }, (rootSpan: Span) => { client.cursor(`${DB_NAME}.${COLLECTION_NAME}`, { find: `${DB_NAME}.${COLLECTION_NAME}`, query: {} @@ -196,7 +196,7 @@ describe('MongoDBPlugin', () => { /** Should intercept command */ describe('Instrumenting command operations', () => { it('should create a child span for count command', (done) => { - tracer.startRootSpan({ name: 'indexRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'indexRootSpan' }, (rootSpan: Span) => { client.command(`${DB_NAME}.${COLLECTION_NAME}`, { count: COLLECTION_NAME }, (err, result) => { assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() @@ -217,7 +217,7 @@ describe('MongoDBPlugin', () => { it('should not create a child span for query', (done) => { const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }] - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.insert(`${DB_NAME}.${COLLECTION_NAME}`, insertData, (err, result) => { assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() @@ -231,7 +231,7 @@ describe('MongoDBPlugin', () => { }) it('should not create a child span for cursor', (done) => { - tracer.startRootSpan({ name: 'findRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'findRootSpan' }, (rootSpan: Span) => { client.cursor(`${DB_NAME}.${COLLECTION_NAME}`, { find: `${DB_NAME}.${COLLECTION_NAME}`, query: {} @@ -248,7 +248,7 @@ describe('MongoDBPlugin', () => { }) it('should not create a child span for command', (done) => { - tracer.startRootSpan({ name: 'indexRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'indexRootSpan' }, (rootSpan: Span) => { client.command(`${DB_NAME}.${COLLECTION_NAME}`, { count: COLLECTION_NAME }, (err, result) => { assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) rootSpan.end() diff --git a/src/census/plugins/__tests__/mysql.spec.ts b/src/census/plugins/__tests__/mysql.spec.ts index e3f0be98..aac75ff5 100644 --- a/src/census/plugins/__tests__/mysql.spec.ts +++ b/src/census/plugins/__tests__/mysql.spec.ts @@ -1,4 +1,4 @@ -import { CoreTracer, RootSpan, SpanEventListener, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as mysql from 'mysql' import * as path from 'path' @@ -7,12 +7,12 @@ import { plugin } from '../mysql' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -124,7 +124,7 @@ describe('MysqlPlugin', () => { /** Should intercept query */ describe('Instrumenting connection operations', () => { it('should create a child span for select', done => { - tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: Span) => { const q = 'SELECT 1' client.query(q, (err, result) => { assert.strictEqual(result[0]['1'], 1) @@ -141,7 +141,7 @@ describe('MysqlPlugin', () => { }) it('should create a child span for errored query', done => { - tracer.startRootSpan({ name: 'errorRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'errorRootSpan' }, (rootSpan: Span) => { const q = 'SELECT * FROM notexisttable' client.query(q, (err, result) => { assert.ok(err instanceof Error) @@ -160,7 +160,7 @@ describe('MysqlPlugin', () => { describe('instrumenting pool operations', () => { it('should create a child span for select', done => { - tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: Span) => { const q = 'SELECT 1' pool.getConnection((err, conn) => { assert.ifError(err) diff --git a/src/census/plugins/__tests__/mysql2.spec.ts b/src/census/plugins/__tests__/mysql2.spec.ts index 6d59a443..acdac743 100644 --- a/src/census/plugins/__tests__/mysql2.spec.ts +++ b/src/census/plugins/__tests__/mysql2.spec.ts @@ -1,4 +1,4 @@ -import { CoreTracer, RootSpan, SpanEventListener, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as mysql from 'mysql2' import * as path from 'path' @@ -7,12 +7,12 @@ import { plugin } from '../mysql2' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -124,7 +124,7 @@ describe('Mysql2Plugin', () => { /** Should intercept query */ describe('Instrumenting connection operations', () => { it('should create a child span for select', done => { - tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: Span) => { const q = 'SELECT 1' client.query(q, (err, result) => { assert.strictEqual(result[0]['1'], 1) @@ -141,7 +141,7 @@ describe('Mysql2Plugin', () => { }) it('should create a child span for errored query', done => { - tracer.startRootSpan({ name: 'errorRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'errorRootSpan' }, (rootSpan: Span) => { const q = 'SELECT * FROM notexisttable' client.query(q, (err, result) => { assert.ok(err instanceof Error) @@ -160,7 +160,7 @@ describe('Mysql2Plugin', () => { describe('instrumenting pool operations', () => { it('should create a child span for select', done => { - tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectRootSpan' }, (rootSpan: Span) => { const q = 'SELECT 1' pool.getConnection((err, conn) => { assert.ifError(err) diff --git a/src/census/plugins/__tests__/net.spec.ts b/src/census/plugins/__tests__/net.spec.ts index 92b9f694..fb54933a 100644 --- a/src/census/plugins/__tests__/net.spec.ts +++ b/src/census/plugins/__tests__/net.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, SpanEventListener, logger } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger } from '@opencensus/core' import * as assert from 'assert' import * as express from 'express' import * as http from 'http' @@ -25,12 +25,12 @@ import { plugin } from '../net' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } diff --git a/src/census/plugins/__tests__/pg.spec.ts b/src/census/plugins/__tests__/pg.spec.ts index dbba1227..20553437 100644 --- a/src/census/plugins/__tests__/pg.spec.ts +++ b/src/census/plugins/__tests__/pg.spec.ts @@ -1,4 +1,4 @@ -import { CoreTracer, RootSpan, SpanEventListener, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, Span, SpanEventListener, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as path from 'path' import * as pg from 'pg' @@ -7,12 +7,12 @@ import { plugin } from '../pg' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -102,7 +102,7 @@ describe('PGPlugin', () => { /** Should intercept query */ describe('Instrumenting connection operations', () => { it('should create a child span for select with callback', done => { - tracer.startRootSpan({ name: 'selectCallbackRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectCallbackRootSpan' }, (rootSpan: Span) => { const q = 'SELECT 1 as value' client.query(q, (err, result) => { assert.strictEqual(result.rows[0].value, 1) @@ -119,7 +119,7 @@ describe('PGPlugin', () => { }) it('should create a span for select with promise', done => { - tracer.startRootSpan({ name: 'selectPromRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectPromRootSpan' }, async (rootSpan: Span) => { const q = 'SELECT 2 as value' const result = await client.query(q) assert.strictEqual(result.rows[0].value, 2) @@ -134,7 +134,7 @@ describe('PGPlugin', () => { }) it('should create a child span for errored query', done => { - tracer.startRootSpan({ name: 'errorCallbackRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'errorCallbackRootSpan' }, (rootSpan: Span) => { const q = 'SELECT * FROM notexisttable' client.query(q, (err, result) => { assert.ok(err instanceof Error) @@ -151,7 +151,7 @@ describe('PGPlugin', () => { }) it('should create a child span for select with eventemitter', done => { - tracer.startRootSpan({ name: 'selectEventRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'selectEventRootSpan' }, (rootSpan: Span) => { const q = 'SELECT 4 as value' // Must use new Query for eventemitter // https://node-postgres.com/guides/upgrading#client-query-submittable- diff --git a/src/census/plugins/__tests__/redis.spec.ts b/src/census/plugins/__tests__/redis.spec.ts index a2d72000..06d793c9 100644 --- a/src/census/plugins/__tests__/redis.spec.ts +++ b/src/census/plugins/__tests__/redis.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, SpanEventListener, Span, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, SpanEventListener, Span, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as redis from 'redis' @@ -22,12 +22,12 @@ import { plugin, RedisPluginConfig } from '../redis' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -117,7 +117,7 @@ describe('RedisPlugin', () => { /** Should intercept query */ describe('Instrumenting query operations', () => { it('should create a child span for hset', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.hset('hash', 'random', 'random', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -132,7 +132,7 @@ describe('RedisPlugin', () => { }) it('should create a child span for get', (done) => { - tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: Span) => { client.get('test', (err, result) => { assert.ifError(err) assert.strictEqual(result, 'data') @@ -148,7 +148,7 @@ describe('RedisPlugin', () => { }) it('should create a child span for del', (done) => { - tracer.startRootSpan({ name: 'removeRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'removeRootSpan' }, (rootSpan: Span) => { client.del('test', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -166,7 +166,7 @@ describe('RedisPlugin', () => { plugin.disable() const conf: RedisPluginConfig = { detailedCommands: true } plugin.enable(redis, tracer, VERSION, conf, '') - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.set('test', 'data', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -188,7 +188,7 @@ describe('RedisPlugin', () => { }) it('should not create a child span for insert', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, (rootSpan: Span) => { client.hset('hash', 'random', 'random', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) @@ -202,7 +202,7 @@ describe('RedisPlugin', () => { }) it('should not create a child span for get', (done) => { - tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'getRootSpan' }, (rootSpan: Span) => { client.get('test', (err, result) => { assert.ifError(err) assert.strictEqual(result, 'data') @@ -216,7 +216,7 @@ describe('RedisPlugin', () => { }) it('should not create a child span for del', (done) => { - tracer.startRootSpan({ name: 'removeRootSpan' }, (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'removeRootSpan' }, (rootSpan: Span) => { client.del('test', (err, result) => { assert.ifError(err) assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0) diff --git a/src/census/plugins/__tests__/vue.spec.ts b/src/census/plugins/__tests__/vue.spec.ts index 34dc4a02..8056276a 100644 --- a/src/census/plugins/__tests__/vue.spec.ts +++ b/src/census/plugins/__tests__/vue.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CoreTracer, RootSpan, SpanEventListener, Span, logger, SpanKind } from '@opencensus/core' +import { CoreTracer, SpanEventListener, Span, logger, SpanKind } from '@opencensus/core' import * as assert from 'assert' import * as vueServerRenderer from 'vue-server-renderer' import * as Vue from 'vue' @@ -24,12 +24,12 @@ import { plugin } from '../vue' /** Collects ended root spans to allow for later analysis. */ class RootSpanVerifier implements SpanEventListener { - endedRootSpans: RootSpan[] = [] + endedRootSpans: Span[] = [] - onStartSpan (span: RootSpan): void { + onStartSpan (span: Span): void { return } - onEndSpan (root: RootSpan) { + onEndSpan (root: Span) { this.endedRootSpans.push(root) } } @@ -90,7 +90,7 @@ describe('VuePlugin', () => { /** Should intercept renderer */ describe('Instrumenting normal renderer operations', () => { it('should create a child span for renderToString', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: Span) => { const renderer = vueServerRenderer.createRenderer() renderer.renderToString(vueVM, (err, html) => { assert.ifError(err) @@ -107,7 +107,7 @@ describe('VuePlugin', () => { /** Should bundle renderer */ describe('Instrumenting normal bundle operations', () => { it('should create a child span for renderToString', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: Span) => { const renderer = vueServerRenderer.createBundleRenderer( require('./fixtures/vue-ssr-bundle.json'), { @@ -136,7 +136,7 @@ describe('VuePlugin', () => { }) it('should not create a child span for renderToString', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: Span) => { const renderer = vueServerRenderer.createRenderer() renderer.renderToString(vueVM, (err, html) => { assert.ifError(err) @@ -152,7 +152,7 @@ describe('VuePlugin', () => { }) it('should not create a child span for renderToString', (done) => { - tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: RootSpan) => { + tracer.startRootSpan({ name: 'insertRootSpan' }, async (rootSpan: Span) => { const renderer = vueServerRenderer.createBundleRenderer( require(__dirname + '/fixtures/vue-ssr-bundle.json'), { diff --git a/src/census/plugins/express.ts b/src/census/plugins/express.ts index b91a7cbe..e2cff1c8 100644 --- a/src/census/plugins/express.ts +++ b/src/census/plugins/express.ts @@ -97,7 +97,7 @@ export class ExpressPlugin extends BasePlugin { } else if (layer.name === 'router') { spanName = `Router - ${layerPath}` } - const span = plugin.tracer.startChildSpan(spanName, SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: spanName, kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) arguments[2] = function () { if (!(req.route && arguments[0] instanceof Error)) { diff --git a/src/census/plugins/http.ts b/src/census/plugins/http.ts index 59083937..2f060f64 100644 --- a/src/census/plugins/http.ts +++ b/src/census/plugins/http.ts @@ -337,8 +337,10 @@ export class HttpPlugin extends BasePlugin { plugin.getMakeRequestTraceFunction(request, options, plugin)) } else { plugin.logger.debug('outgoingRequest starting a child span') - const span = plugin.tracer.startChildSpan( - traceOptions.name, traceOptions.kind) + const span = plugin.tracer.startChildSpan({ + name: traceOptions.name, + kind: traceOptions.kind + }) return (plugin.getMakeRequestTraceFunction(request, options, plugin))( span) } @@ -447,7 +449,7 @@ export class HttpPlugin extends BasePlugin { private createSpan (options: TraceOptions, fn: (span: Span) => T): T { const forceChildspan = this.options.createSpanWithNet === true if (forceChildspan) { - const span = this.tracer.startChildSpan(options.name, options.kind) + const span = this.tracer.startChildSpan({ name: options.name, kind: options.kind }) return fn(span) } else { return this.tracer.startRootSpan(options, fn) diff --git a/src/census/plugins/http2.ts b/src/census/plugins/http2.ts index 67d8de68..9f672c58 100644 --- a/src/census/plugins/http2.ts +++ b/src/census/plugins/http2.ts @@ -108,8 +108,10 @@ export class Http2Plugin extends HttpPlugin { plugin.getMakeHttp2RequestTraceFunction( request, headers, authority, plugin)) } else { - const span = plugin.tracer.startChildSpan( - traceOptions.name, traceOptions.kind) + const span = plugin.tracer.startChildSpan({ + name: traceOptions.name, + kind: traceOptions.kind + }) return (plugin.getMakeHttp2RequestTraceFunction( request, headers, authority, plugin))(span) } diff --git a/src/census/plugins/ioredis.ts b/src/census/plugins/ioredis.ts index d1856901..6db09019 100644 --- a/src/census/plugins/ioredis.ts +++ b/src/census/plugins/ioredis.ts @@ -72,7 +72,7 @@ export class IORedisPlugin extends BasePlugin { return original.apply(this, arguments) } - const span = plugin.tracer.startChildSpan(`redis-${command.name}`, SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: `redis-${command.name}`, kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) span.addAttribute('command', command.name) diff --git a/src/census/plugins/mongodb.ts b/src/census/plugins/mongodb.ts index 5aa417ae..c540085d 100644 --- a/src/census/plugins/mongodb.ts +++ b/src/census/plugins/mongodb.ts @@ -100,7 +100,7 @@ export class MongoDBPlugin extends BasePlugin { type = 'command' } - const span = plugin.tracer.startChildSpan(label, SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: label, kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) span.addAttribute('database', ns) span.addAttribute('type', type) @@ -129,7 +129,7 @@ export class MongoDBPlugin extends BasePlugin { return function (...args: any[]) { let resultHandler = args[0] if (plugin.tracer.currentRootSpan && typeof resultHandler === 'function') { - const span = plugin.tracer.startChildSpan('mongodb-find', SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: 'mongodb-find', kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) resultHandler = plugin.patchEnd(span, resultHandler) diff --git a/src/census/plugins/mysql.ts b/src/census/plugins/mysql.ts index 288f467e..f478007b 100644 --- a/src/census/plugins/mysql.ts +++ b/src/census/plugins/mysql.ts @@ -69,7 +69,7 @@ export class MysqlPlugin extends BasePlugin { const plugin = this return (original: Function) => { return function (...args: any[]) { - const span = plugin.tracer.startChildSpan('mysql-query', SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: 'mysql-query', kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) const query = original.apply(this, arguments) diff --git a/src/census/plugins/mysql2.ts b/src/census/plugins/mysql2.ts index bbe82d03..cd691920 100644 --- a/src/census/plugins/mysql2.ts +++ b/src/census/plugins/mysql2.ts @@ -69,7 +69,7 @@ export class Mysql2Plugin extends BasePlugin { const plugin = this return (original: Function) => { return function (...args: any[]) { - const span = plugin.tracer.startChildSpan('mysql-query', SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: 'mysql-query', kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) const query = original.apply(this, arguments) diff --git a/src/census/plugins/pg.ts b/src/census/plugins/pg.ts index 06b78902..4a3ce8f6 100644 --- a/src/census/plugins/pg.ts +++ b/src/census/plugins/pg.ts @@ -63,7 +63,7 @@ export class PGPlugin extends BasePlugin { const plugin = this return (original: Function) => { return function (...args: any[]) { - const span = plugin.tracer.startChildSpan('pg-query', SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: 'pg-query', kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) let pgQuery diff --git a/src/census/plugins/redis.ts b/src/census/plugins/redis.ts index 90302fec..cf3abeaf 100644 --- a/src/census/plugins/redis.ts +++ b/src/census/plugins/redis.ts @@ -103,7 +103,7 @@ export class RedisPlugin extends BasePlugin { // New versions of redis (2.4+) use a single options object instead // of separate named arguments. if (arguments.length === 1 && typeof cmd === 'object') { - const span = plugin.tracer.startChildSpan(`redis-${cmd.command}`, SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: `redis-${cmd.command}`, kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) span.addAttribute('command', cmd.command) @@ -115,7 +115,7 @@ export class RedisPlugin extends BasePlugin { } // older commands where using multiple arguments, focus on supporting if (typeof cmd === 'string' && Array.isArray(args) && typeof cb === 'function') { - const span = plugin.tracer.startChildSpan(`redis-${cmd}`, SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: `redis-${cmd}`, kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) span.addAttribute('command', cmd) diff --git a/src/census/plugins/vue.ts b/src/census/plugins/vue.ts index 9bad2f14..d0c5953d 100644 --- a/src/census/plugins/vue.ts +++ b/src/census/plugins/vue.ts @@ -75,7 +75,7 @@ export class VuePlugin extends BasePlugin { if (!plugin.tracer.currentRootSpan) { return original.apply(this, arguments) } - const span = plugin.tracer.startChildSpan(`vue-renderer`, SpanKind.CLIENT) + const span = plugin.tracer.startChildSpan({ name: `vue-renderer`, kind: SpanKind.CLIENT }) if (span === null) return original.apply(this, arguments) const promise = original.apply(this, arguments) diff --git a/src/features/tracing.ts b/src/features/tracing.ts index 0b0417af..15fbee26 100644 --- a/src/features/tracing.ts +++ b/src/features/tracing.ts @@ -183,7 +183,7 @@ export class TracingFeature implements Feature { (process.env.DEBUG.indexOf('axm:*') >= 0 || process.env.DEBUG.indexOf('axm:tracing') >= 0) } - getTracer (): core.Tracer | undefined { + getTracer (): core.TracerBase | undefined { return this.tracer ? this.tracer.tracer : undefined } diff --git a/src/pmx.ts b/src/pmx.ts index 52342ba3..0ffc33cb 100644 --- a/src/pmx.ts +++ b/src/pmx.ts @@ -20,7 +20,7 @@ import { MetricConfig } from './features/metrics' import { ProfilingConfig } from './features/profiling' import { RuntimeStatsService } from './services/runtimeStats' import { Entrypoint } from './features/entrypoint' -import { Tracer } from '@opencensus/core' +import { TracerBase } from '@opencensus/core' export class IOConfig { /** @@ -387,7 +387,7 @@ export default class PMX { /** * Get the tracing agent to add more information about traces */ - getTracer (): Tracer | undefined { + getTracer (): TracerBase | undefined { const tracing = this.featureManager.get('tracing') as TracingFeature return tracing.getTracer() } diff --git a/test/api.spec.ts b/test/api.spec.ts index 422c0aa3..cd515dde 100644 --- a/test/api.spec.ts +++ b/test/api.spec.ts @@ -171,6 +171,7 @@ describe('API', function () { assert(!!res.data.message.match(/Cannot read property/)) } if (res === 'callback') { + console.log(res) done() } }) diff --git a/test/fixtures/metrics/tracingChild.ts b/test/fixtures/metrics/tracingChild.ts index e981f64c..1cffe37e 100644 --- a/test/fixtures/metrics/tracingChild.ts +++ b/test/fixtures/metrics/tracingChild.ts @@ -24,7 +24,7 @@ app.get('/', function (req, res) { http.get('http://localhost:' + (server.address() as AddressInfo).port + '/toto', (_) => { const tracer = pmx.getTracer() if (tracer === undefined) throw new Error('tracer undefined') - const customSpan = tracer.startChildSpan('customspan', SpanKind.CLIENT) + const customSpan = tracer.startChildSpan({ name: 'customspan', kind: SpanKind.CLIENT }) customSpan.addAttribute('test', true) setTimeout(_ => { customSpan.end()