How to use @opentelemetry/node - 8 common examples

To help you get started, we’ve selected a few @opentelemetry/node 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 GoogleCloudPlatform / esp-v2 / tests / endpoints / bookstore / http_bookstore.js View on Github external
// Used by e2e tests, only needs to build and push image when there is changes,
// by running:
//      make docker.build-bookstore
//      make docker.push-bookstore

'use strict';

const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { BatchSpanProcessor } = require('@opentelemetry/tracing');
const { TraceExporter } = require('@google-cloud/opentelemetry-cloud-trace-exporter');
const { AlwaysOnSampler, AlwaysOffSampler, ParentOrElseSampler } = require("@opentelemetry/core");
const { HttpTraceContext } = require("@opentelemetry/core");

// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
const provider = new NodeTracerProvider({
  // TODO(nareddyt): Only sample when the incoming request creates a new span.
  // Otherwise don't make new spans, but propagate the context.
  // sampler: new ParentOrElseSampler(new AlwaysOffSampler()),
  sampler: new AlwaysOnSampler(),
  plugins: {
    express: {
      enabled: true,
      path: '@opentelemetry/plugin-express',
      ignoreLayersType: [
          "middleware",
          "request_handler",
      ],
    },
    http: {
      enabled: true,
      path: '@opentelemetry/plugin-http',
github open-telemetry / opentelemetry-js / examples / http / setup.js View on Github external
function setupTracerAndExporters(service) {
  const tracer = new NodeTracer();

  let exporter;
  if (EXPORTER.toLowerCase().startsWith('z')) {
    exporter = new ZipkinExporter({
      serviceName: service,
    });
  } else {
    exporter = new JaegerExporter({
      serviceName: service,
    });
  }

  tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));

  // Initialize the OpenTelemetry APIs to use the BasicTracer bindings
  opentelemetry.initGlobalTracer(tracer);
github open-telemetry / opentelemetry-js / examples / grpc / setup.js View on Github external
function setupTracerAndExporters(service) {
  const tracer = new NodeTracer({
    plugins: {
      grpc: {
        enabled: true,
        // if it can't find the module, put the absolute path since the packages are not published yet
        path: '@opentelemetry/plugin-grpc'
      }
    }
  });

  let exporter;
  if (EXPORTER.toLowerCase().startsWith('z')) {
    exporter = new ZipkinExporter({
      serviceName: service,
    });
  } else {
    exporter = new JaegerExporter({
github open-telemetry / opentelemetry-js / examples / dns / setup.js View on Github external
function setupTracerAndExporters(service) {
  const tracer = new NodeTracer({
      plugins: {
          dns: {
            enabledtrue,
            path'@opentelemetry/plugin-dns',
            // Avoid dns lookup loop with http zipkin calls
            ignoreHostnames: ['localhost']
        }
      }
  });

  let exporter;
  if (EXPORTER.toLowerCase().startsWith('z')) {
    exporter = new ZipkinExporter({
      serviceName: service,
    });
  } else {
github open-telemetry / opentelemetry-js / examples / https / setup.js View on Github external
function setupTracerAndExporters(service) {
  let exporter;
  const tracer = new NodeTracer();

  if (EXPORTER.toLowerCase().startsWith('z')) {
    exporter = new ZipkinExporter({
      serviceName: service
    });
  } else {
    exporter = new JaegerExporter({
      serviceName: service,
    });
  }

  tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));

  // Initialize the OpenTelemetry APIs to use the BasicTracer bindings
  opentelemetry.initGlobalTracer(tracer);
}
github GoogleCloudPlatform / cloud-ops-sandbox / src / currencyservice / server.js View on Github external
}
});
require('@google-cloud/debug-agent').start({
  serviceContext: {
    service: 'currencyservice',
    version: 'VERSION'
  }
});

const opentelemetry = require('@opentelemetry/api');
const {NodeTracerProvider} = require('@opentelemetry/node');
const {BatchSpanProcessor} = require('@opentelemetry/tracing');
const {TraceExporter} = require('@google-cloud/opentelemetry-cloud-trace-exporter');

// OpenTelemetry tracing with exporter to Google Cloud Trace
const provider = new NodeTracerProvider({
  // Use grpc plugin to receive trace contexts from client
  plugins: {
    grpc: {
      enabled: true,
      path: '@opentelemetry/plugin-grpc',
    }
  }
});
// Cloud Trace Exporter handles credentials.
const exporter = new TraceExporter();
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
provider.register();
const tracer = opentelemetry.trace.getTracer('currency');

const path = require('path');
const grpc = require('grpc');
github GoogleCloudPlatform / cloud-ops-sandbox / src / paymentservice / tracer.js View on Github external
module.exports = () => {
    const provider = new NodeTracerProvider({
        // Use grpc plugin to receive trace contexts from client (checkout)
        plugins: {
            grpc: {
                enabled: true,
                path: '@opentelemetry/plugin-grpc',
            }
        }
    });
    provider.addSpanProcessor(new BatchSpanProcessor(new TraceExporter()));

    // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
    provider.register();

    return opentelemetry.trace.getTracer('payment');
}
github open-telemetry / opentelemetry-js / examples / mysql / setup.js View on Github external
function setupTracerAndExporters(service) {
  const tracer = new NodeTracer({
    plugins: {
      mysql: {
        enabled: true,
        path: "@opentelemetry/plugin-mysql"
      },
      http: {
        enabled: true,
        path: "@opentelemetry/plugin-http"
      }
    }
  });

  tracer.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
    serviceName: service,
  })));
  tracer.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({

@opentelemetry/node

OpenTelemetry Node SDK provides automatic telemetry (tracing, metrics, etc) for Node.js applications

Apache-2.0
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis