How to use the @opentelemetry/tracing.BatchSpanProcessor function in @opentelemetry/tracing

To help you get started, we’ve selected a few @opentelemetry/tracing 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
express: {
      enabled: true,
      path: '@opentelemetry/plugin-express',
      ignoreLayersType: [
          "middleware",
          "request_handler",
      ],
    },
    http: {
      enabled: true,
      path: '@opentelemetry/plugin-http',
    }
  }
});
const exporter = new TraceExporter();
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
provider.register();

// Registration. Use W3C trace context propagation with `traceparent` header.
opentelemetry.trace.setGlobalTracerProvider(provider);
opentelemetry.propagation.setGlobalPropagator(new HttpTraceContext());

// Load express afterwords.
var express = require('express');
var bodyParser = require('body-parser');
var swaggerTools = require('swagger-tools');


/**
 * @typedef {Object} InitializationOptions
 * @property {Boolean} log Log incoming requests.
 * @property {Object} swagger Swagger document object.
github GoogleCloudPlatform / cloud-ops-sandbox / src / currencyservice / server.js View on Github external
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');
const request = require('request');
const xml2js = require('xml2js');
const pino = require('pino');
const protoLoader = require('@grpc/proto-loader');

const MAIN_PROTO_PATH = path.join(__dirname, './proto/demo.proto');
const HEALTH_PROTO_PATH = path.join(__dirname, './proto/grpc/health/v1/health.proto');

const PORT = 7000;
const DATA_URL = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
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 / basic-tracer-node / multi_exporter.js View on Github external
const { BasicTracer, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } =  require('@opentelemetry/exporter-collector');

const tracer = new BasicTracer();

const zipkinExporter = new ZipkinExporter({serviceName: 'basic-service'});
const jaegerExporter = new JaegerExporter({
  serviceName: 'basic-service',
});
const collectorExporter = new CollectorExporter({serviceName: 'basic-service'});

// It is recommended to use this BatchSpanProcessor for better performance
// and optimization, especially in production.
tracer.addSpanProcessor(new BatchSpanProcessor(zipkinExporter, {
  bufferSize: 10 // This is added for example, default size is 100.
}));

// It is recommended to use SimpleSpanProcessor in case of Jaeger exporter as
// it's internal client already handles the spans with batching logic.
tracer.addSpanProcessor(new SimpleSpanProcessor(jaegerExporter));

tracer.addSpanProcessor(new SimpleSpanProcessor(collectorExporter));

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(tracer);

// Create a span. A span must be closed.
const span = opentelemetry.getTracer().startSpan('main');
for (let i = 0; i < 10; i++) {
  doWork(span);

@opentelemetry/tracing

OpenTelemetry Tracing

Apache-2.0
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis