How to use the @opencensus/core.CoreTracer function in @opencensus/core

To help you get started, we’ve selected a few @opencensus/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / redis.spec.ts View on Github external
// For these tests, mongo must be runing. Add OPENCENSUS_REDIS_TESTS to run
  // these tests.
  const OPENCENSUS_REDIS_TESTS =
      process.env.OPENCENSUS_REDIS_TESTS as string
  const OPENCENSUS_REDIS_HOST =
      process.env.OPENCENSUS_REDIS_HOST as string
  let shouldTest = true
  if (!OPENCENSUS_REDIS_TESTS) {
    console.log('Skipping test-redis. Run REDIS to test')
    shouldTest = false
  }

  const URL = `redis://${OPENCENSUS_REDIS_HOST || 'localhost'}:6379`
  const VERSION = '2.8.0'

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  let client: redis.RedisClient

  before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    plugin.enable(redis, tracer, VERSION, {}, '')
    client = redis.createClient({
      url: URL
    })
    client.on('error', (err: Error) => {
      console.log(
        'Skipping test-redis. Could not connect. Run Redis to test', err)
      shouldTest = false
      done()
    })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / ioredis.spec.ts View on Github external
// For these tests, mongo must be runing. Add OPENCENSUS_REDIS_TESTS to run
  // these tests.
  const OPENCENSUS_REDIS_TESTS =
      process.env.OPENCENSUS_REDIS_TESTS as string
  const OPENCENSUS_REDIS_HOST =
      process.env.OPENCENSUS_REDIS_HOST as string
  let shouldTest = true
  if (!OPENCENSUS_REDIS_TESTS) {
    console.log('Skipping test-redis. Run REDIS to test')
    shouldTest = false
  }

  const URL = `redis://${OPENCENSUS_REDIS_HOST || 'localhost'}:6379`
  const VERSION = '4.6.2'

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  let client: ioredis.Redis

  before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    plugin.enable(ioredis, tracer, VERSION, {}, '')
    client = new ioredis(URL)
    client.on('error', (err: Error) => {
      console.log(
        'Skipping test-redis. Could not connect. Run Redis to test', err)
      shouldTest = false
      done()
    })
    client.on('ready', done)
  })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / mysql2.spec.ts View on Github external
const OPENCENSUS_MYSQL_DATABASE =
      process.env.OPENCENSUS_MYSQL_DATABASE as string
  const OPENCENSUS_MYSQL_USER =
      process.env.OPENCENSUS_MYSQL_USER as string
  const OPENCENSUS_MYSQL_PASSWORD =
      process.env.OPENCENSUS_MYSQL_PASSWORD as string
  let shouldTest = true
  if (!OPENCENSUS_MYSQL_TESTS) {
    console.log('Skipping test-mysql2. Run Mysql to test')
    shouldTest = false
  }

  const URL = `mysql://${OPENCENSUS_MYSQL_USER || 'root'}:${OPENCENSUS_MYSQL_PASSWORD || 'password'}@${OPENCENSUS_MYSQL_HOST || 'localhost'}/${OPENCENSUS_MYSQL_DATABASE || 'test'}`
  const VERSION = '3.1.13'

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  let client: any
  let pool: any

  before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    const basedir = path.dirname(require.resolve('mysql2'))
    plugin.enable(mysql, tracer, VERSION, {}, basedir)
    connectConnection(URL)
      .then(server => {
        client = server
        pool = createPool(URL)
        done()
      })
      .catch((err: Error) => {
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / http2.spec.ts View on Github external
resolve(data)
        })
        request.on('error', err => {
          reject(err)
        })
      })
    }
  }

  let server: http2.Http2Server
  let client: http2.ClientHttp2Session
  const serverPort = 8080
  const host = `localhost:${serverPort}`
  const authority = `http://${host}`

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  tracer.start({ samplingRate: 1, logger: logger.logger(4) })

  it('should return a plugin', () => {
    assert.ok(plugin instanceof Http2Plugin)
  })

  before(() => {
    tracer.registerSpanEventListener(rootSpanVerifier)

    plugin.enable(http2, tracer, VERSION, {}, '')
    server = http2.createServer()
    server.on('stream', (stream, requestHeaders) => {
      const pathHeader = requestHeaders[':path']
      if (pathHeader === undefined) throw new Error(`Undefined path header`)
      const statusCode = pathHeader.length > 1 ?
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / http.spec.ts View on Github external
describe('HttpPlugin', () => {
  const hostName = 'fake.service.io'
  const urlHost = `http://${hostName}`

  let server: http.Server
  let serverPort = 0
  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  tracer.start({
    samplingRate: 1,
    logger: logger.logger(4),
    propagation: new DummyPropagation()
  })

  it('should return a plugin', () => {
    assert.ok(plugin instanceof HttpPlugin)
  })

  before(() => {
    plugin.enable(
        http, tracer, VERSION, {
          ignoreIncomingPaths: [
            '/ignored/string', /^\/ignored\/regexp/,
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / https.spec.ts View on Github external
describe('HttpsPlugin', () => {
  const hostName = 'fake.service.io'
  const urlHost = `https://${hostName}`
  let serverPort = 3000

  let server: https.Server
  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  tracer.start({ samplingRate: 1, logger: logger.logger(4) })

  it('should return a plugin', () => {
    assert.ok(plugin instanceof HttpsPlugin)
  })

  before(() => {
    plugin.enable(
        https, tracer, VERSION, {
          ignoreIncomingPaths: [
            '/ignored/string', /^\/ignored\/regexp/,
            (url: string) => url === '/ignored/function'
          ],
          ignoreOutgoingUrls: [
            `${urlHost}/ignored/string`,
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / pg.spec.ts View on Github external
process.env.OPENCENSUS_PG_PASSWORD as string
  let shouldTest = true
  if (!OPENCENSUS_PG_TESTS) {
    console.log('Skipping test-pg. Run Postgres to test')
    shouldTest = false
  }

  const CONFIG = {
    user: OPENCENSUS_PG_USER || 'postgres',
    host: OPENCENSUS_PG_HOST || 'localhost',
    database: OPENCENSUS_PG_DATABASE || 'test',
    password: OPENCENSUS_PG_PASSWORD || 'password'
  }
  const VERSION = '7.8.0'

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  let client: any
  let pool: any

  before(async () => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    const basedir = path.dirname(require.resolve("pg/package.json")); //require.resolve was returning direct path to lib, as in current pg version they have defined "main" path section which was breaking this test case. We need only path of PG nodule not lib folder. This fixes this issue.
    plugin.enable(pg, tracer, VERSION, {}, basedir)
    client = new pg.Client(CONFIG)
    try {
      await client.connect()
    } catch (err) {
      console.log(
        'Skipping test-pg. Could not connect. Run Postgres to test', err)
      shouldTest = false
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / express.spec.ts View on Github external
describe('VuePlugin', () => {

  const VERSION = '4.16.0'
  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()

  before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    httpPlugin.plugin.enable(http, tracer, process.versions.node, {}, '')
    plugin.enable(express, tracer, VERSION, {}, '')
    return done()
  })

  beforeEach(function redisBeforeEach () {
    rootSpanVerifier.endedRootSpans = []
  })

  /** Should intercept renderer */
  describe('Instrumenting normal get operations', () => {
github keymetrics / pm2-io-apm / src / census / tracer.ts View on Github external
constructor () {
    this.tracer = new core.CoreTracer()
    this.defaultPlugins = PluginLoader.defaultPluginsFromArray(
        Constants.DEFAULT_INSTRUMENTATION_MODULES)
  }
github census-instrumentation / opencensus-node / packages / opencensus-nodejs / src / trace / tracing.ts View on Github external
constructor() {
    /** Default list of target modules to be instrumented */
    super(DEFAULT_INSTRUMENTATION_MODULES);
    this.tracer = new core.CoreTracer();
  }
}