How to use the @opencensus/core.logger.logger 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__ / mysql2.spec.ts View on Github external
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) => {
        console.log(
            'Skipping test-mysql2. Could not connect. Run Mysql to test', err)
        shouldTest = false
        done()
      })
  })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / http2.spec.ts View on Github external
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 ?
          +pathHeader.slice(1) :
          200
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / redis.spec.ts View on Github external
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()
    })
    client.on('ready', done)
  })
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`,
            /^https:\/\/fake\.service\.io\/ignored\/regexp$/,
            (url: string) => url === `${urlHost}/ignored/function`
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / pg.spec.ts View on Github external
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__ / net.spec.ts View on Github external
before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    plugin.enable(net, tracer, VERSION, {}, '')
    httpPlugin.plugin.enable(http, tracer, process.versions.node, {
      createSpanWithNet: true
    }, '')
    return done()
  })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / express.spec.ts View on Github external
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()
  })
github census-instrumentation / opencensus-node / packages / opencensus-exporter-zipkin / src / zipkin.ts View on Github external
constructor(options: ZipkinExporterOptions) {
    this.zipkinUrl =
      (options.url && url.parse(options.url)) ||
      url.parse(ZipkinTraceExporter.DEFAULT_URL);
    this.serviceName = options.serviceName;
    this.buffer = new ExporterBuffer(this, options);
    this.logger = options.logger || logger.logger();
  }
github census-instrumentation / opencensus-node / packages / opencensus-nodejs-base / src / trace / tracing-base.ts View on Github external
stop() {
    this.activeLocal = false;
    this.tracer.stop();
    if (this.pluginLoader) {
      this.pluginLoader.unloadPlugins();
    }
    this.configLocal = {};
    this.logger = logger.logger();
  }
github census-instrumentation / opencensus-node / packages / opencensus-nodejs-base / src / trace / tracing-base.ts View on Github external
import { PluginLoader } from './instrumentation/plugin-loader';

const NOOP_EXPORTER = new core.NoopExporter();

/** Implements a Tracing. */
export class TracingBase implements core.Tracing {
  /** A tracer object */
  readonly tracer: core.TracerBase;
  /** A plugin loader object */
  private pluginLoader?: PluginLoader;
  /** Plugin names */
  protected defaultPlugins: core.PluginNames;
  /** A configuration object to start the tracing */
  private configLocal: core.Config = {};
  /** An object to log information to. Logs to the JS console by default. */
  private logger: core.Logger = logger.logger();
  /** Singleton instance */
  private static singletonInstance: core.Tracing;
  /** Indicates if the tracing is active */
  private activeLocal = false;

  /** Constructs a new TracingImpl instance. */
  constructor(pluginNames: string[] = []) {
    this.tracer = new core.CoreTracerBase();
    this.defaultPlugins = PluginLoader.defaultPluginsFromArray(pluginNames);
  }

  /** Gets the tracing instance. */
  static get instance(): core.Tracing {
    return this.singletonInstance || (this.singletonInstance = new this());
  }