How to use the @opencensus/nodejs.start function in @opencensus/nodejs

To help you get started, we’ve selected a few @opencensus/nodejs 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 census-ecosystem / opencensus-experiments / interoptest / src / nodejsservice / server.js View on Github external
function main () {
  // Setup Tracer
  const tracer = tracing.start({
    samplingRate: 1,
    propagation: new propagation.TraceContextFormat()
  }).tracer;

  // Setup Exporter, Enable GRPC and HTTP plugin
  enableJaegerTraceExporter(tracer);
  enableHttpPlugin(tracer);
  //enableGrpcPlugin(tracer);

  // Start GRPC Server
  grpcServer.start(interop.ServicePort.NODEJS_GRPC_BINARY_PROPAGATION_PORT, '0.0.0.0');

  // Start HTTP Server
  httpServer.start(interop.ServicePort.NODEJS_HTTP_TRACECONTEXT_PROPAGATION_PORT, '0.0.0.0');
}
github census-instrumentation / opencensus-node / examples / grpc / capitalize_server.js View on Github external
// A Stackdriver workspace is required and provided through the environment as ${GOOGLE_PROJECT_ID}
  const projectId = process.env.GOOGLE_PROJECT_ID;

  // GOOGLE_APPLICATION_CREDENTIALS are expected by a dependency of this code
  // Not this code itself. Checking for existence here but not retaining (as not needed)
  if (!projectId || !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
    throw Error('Unable to proceed without a Project ID');
  }
  // Creates Stackdriver exporter
  const exporter = new StackdriverTraceExporter({ projectId: projectId });

  // Starts Stackdriver exporter
  tracing.registerExporter(exporter).start();

  // Starts tracing and set sampling rate
  const tracer = tracing.start({
    samplingRate: 1 // For demo purposes, always sample
  }).tracer;

  // Defines basedir and version
  const basedir = path.dirname(require.resolve('grpc'));
  const version = require(path.join(basedir, 'package.json')).version;

  // Enables GRPC plugin: Method that enables the instrumentation patch.
  plugin.enable(grpc, tracer, version, /** plugin options */{}, basedir);

  return tracer;
}
github census-instrumentation / opencensus-node / examples / http / client.js View on Github external
function setupTracerAndExporters () {
  const zipkinOptions = {
    url: 'http://localhost:9411/api/v2/spans',
    serviceName: 'opencensus_tutorial'
  };

  // Creates Zipkin exporter
  const exporter = new ZipkinTraceExporter(zipkinOptions);

  // Starts tracing and set sampling rate, exporter and propagation
  const tracer = tracing.start({
    exporter,
    samplingRate: 1, // For demo purposes, always sample
    propagation: new TraceContextFormat(),
    logLevel: 1 // show errors, if any
  }).tracer;

  return tracer;
}
github census-instrumentation / opencensus-node / examples / grpc / capitalize_client.js View on Github external
const projectId = process.env.GOOGLE_PROJECT_ID;

  // GOOGLE_APPLICATION_CREDENTIALS are expected by a dependency of this code
  // Not this code itself. Checking for existence here but not retaining (as not needed)
  if (!projectId || !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
    throw Error('Unable to proceed without a Project ID');
  }

  // Creates Stackdriver exporter
  const exporter = new StackdriverTraceExporter({ projectId: projectId });

  // Starts Stackdriver exporter
  tracing.registerExporter(exporter).start();

  // Starts tracing and set sampling rate
  const tracer = tracing.start({
    samplingRate: 1 // For demo purposes, always sample
  }).tracer;

  // Defines basedir and version
  const basedir = path.dirname(require.resolve('grpc'));
  const version = require(path.join(basedir, 'package.json')).version;

  // Enables GRPC plugin: Method that enables the instrumentation patch.
  plugin.enable(grpc, tracer, version, /** plugin options */{}, basedir);

  return tracer;
}
github census-instrumentation / opencensus-web / examples / user_interaction / server / server.js View on Github external
function setupTracerAndExporters() {
  const zipkinOptions = {
    url: 'http://localhost:9411/api/v2/spans',
    serviceName: 'opencensus_web_server'
  };

  // Creates Zipkin exporter
  const exporter = new ZipkinTraceExporter(zipkinOptions);

  // Starts tracing and set sampling rate, exporter and propagation
  const tracer = tracing.start({
    exporter,
    samplingRate: 1, // For demo purposes, always sample
    propagation: new TraceContextFormat(),
    logLevel: 1 // show errors, if any
  }).tracer;

  return tracer;
}
github census-instrumentation / opencensus-node / examples / trace / multi-span-tracing.js View on Github external
*      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/** Example showing how to directly create a child span and add annotations. */
const tracing = require('@opencensus/nodejs');
const { ZipkinTraceExporter } = require('@opencensus/exporter-zipkin');

// 1. Get the global singleton Tracer object
// 2. Configure 100% sample rate, otherwise, few traces will be sampled.
const tracer = tracing.start({ samplingRate: 1 }).tracer;

// 3. Configure exporter to export traces to Zipkin.
tracer.registerSpanEventListener(new ZipkinTraceExporter({
  url: 'http://localhost:9411/api/v2/spans',
  serviceName: 'node.js-quickstart'
}));

function main () {
  // 4. Create a span. A span must be closed.
  // For any of the web frameworks for which we provide built-in plugins (http,
  // grpc, mongodb etc), a root span is automatically started whenever an
  // incoming request is received (in other words, all middleware already runs
  // within a root span).
  tracer.startRootSpan({ name: 'main' }, rootSpan => {
    for (let i = 0; i < 10; i++) {
      doWork();
github unlock-protocol / unlock / locksmith / src / app.ts View on Github external
import bodyParser from 'body-parser'
import cors from 'cors'
import express from 'express'
import tracing from '@opencensus/nodejs'
import { JaegerTraceExporter } from '@opencensus/exporter-jaeger'
import { ApolloServer } from 'apollo-server-express'
import { typeDefs } from './graphql/typeDefinitions'
import { resolvers } from './graphql/resolvers'

const env = process.env.NODE_ENV || 'development'
const config = require('../config/config')[env]

const exporter = new JaegerTraceExporter(config.jaeger)

if (env != 'test') {
  tracing.start({ exporter: exporter })
}

const app = express()

const server = new ApolloServer({
  typeDefs,
  resolvers,
})
server.applyMiddleware({ app })

let transactionRouter = require('./routes/transaction')
let lockRouter = require('./routes/lock')
let blockRouter = require('./routes/block')
let userRouter = require('./routes/user')
let eventRouter = require('./routes/event')
let purchaseRouter = require('./routes/purchase')
github VilledeMontreal / workit / packages / workit-core / src / opentelemetry / jaeger / tracerService.ts View on Github external
public start(): void {
    if (tracing.active) {
      return;
    }

    tracing.start(this._configs);
  }
}

@opencensus/nodejs

OpenCensus is a toolkit for collecting application performance and behavior data.

Apache-2.0
Latest version published 4 years ago

Package Health Score

47 / 100
Full package analysis