Skip to content

Commit

Permalink
chore(opencensus): update opencensus to remove related warnings
Browse files Browse the repository at this point in the history
update opencensus to remove uuidv3 package warning and DeprecationWarning: Socket.prototype._handle
is deprecated

BREAKING CHANGE: need to fix tests, startChildSpan uses a object now, RootSpan was removed

may affect keymetrics#274
  • Loading branch information
David Lima committed Sep 18, 2021
1 parent b6b1bd7 commit 1e9b191
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 122 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/census/exporter.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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<null>((resolve, reject) => {
zipkinTraces.forEach(span => {
const isRootClient = span.kind === 'CLIENT' && !span.parentId
if (isRootClient && this.config.outbound === false) return
Expand All @@ -80,15 +80,15 @@ export class CustomCensusExporter implements Exporter {
this.transport.send('trace-span', span)
}
})
resolve()
resolve(null)
})
}

/**
* 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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/census/plugins/__tests__/express.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/census/plugins/__tests__/http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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) => {
Expand Down
14 changes: 7 additions & 7 deletions src/census/plugins/__tests__/http2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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) => {
Expand Down
14 changes: 7 additions & 7 deletions src/census/plugins/__tests__/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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) => {
Expand Down
22 changes: 11 additions & 11 deletions src/census/plugins/__tests__/ioredis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
* 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'

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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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()
Expand Down
Loading

0 comments on commit 1e9b191

Please sign in to comment.