0

在我使用lightstep/opentelemetry-exporter-js之前,我可以同时使用自己的导出器和 Lightstep 导出器。

import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { NodeTracerProvider } from '@opentelemetry/node';
import { BatchSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/tracing';
import { LightstepExporter } from 'lightstep-opentelemetry-exporter';

const initTracer = () => {
  const serviceName = 'server-trace-service';
  const tracerProvider = new NodeTracerProvider({
    plugins: {
      http: {
        enabled: true,
        path: '@opentelemetry/plugin-http',
      },
    },
  });

  tracerProvider.addSpanProcessor(new BatchSpanProcessor(new ConsoleSpanExporter()));
  tracerProvider.addSpanProcessor(
    new BatchSpanProcessor(
      new CollectorTraceExporter({
        serviceName,
      })
    )
  );
  tracerProvider.addSpanProcessor(
    new BatchSpanProcessor(
      new LightstepExporter({
        serviceName,
        token: 'myToken',
      })
    )
  );

  tracerProvider.register();
};

但是,刚刚看到 lightstep/opentelemetry-exporter-js 已被弃用并被lightstep/otel-launcher-node取代。

我检查了它的源代码和演示,它看起来像是 OpenTelemetry 之上的一个“框架”。

const {
  lightstep,
  opentelemetry,
} = require('lightstep-opentelemetry-launcher-node');

const sdk = lightstep.configureOpenTelemetry({
  accessToken: 'YOUR ACCESS TOKEN',
  serviceName: 'locl-ex',
});

sdk.start().then(() => {
  const tracer = opentelemetry.trace.getTracer('otel-node-example');
  const span = tracer.startSpan('test-span');
  span.end();

  opentelemetry.trace.getTracerProvider().getActiveSpanProcessor().shutdown();
});

是否可以简单地将其用作 OpenTelemetry 导出器之一?

4

1 回答 1

2

lightstep-opentelemetry-launcher-node基本上为您捆绑所需的东西以便于配置,因此这不是出口商。如果您只是在代码中将“LightstepExporter”替换为“OpenTelemetry Collector Exporter”,您可以简单地执行此操作

  import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';

  tracerProvider.addSpanProcessor(
    new BatchSpanProcessor(
      new CollectorTraceExporter({
        url: 'YOUR_DIGEST_URL',
        headers: {
          'Lightstep-Access-Token': 'YOUR_TOKEN'
        }
      })
    )
  );

lightstep/otel-launcher-node的默认YOUR_DIGETS_URL值为https://ingest.lightstep.com:443/api/v2/otel/trace

于 2020-09-03T14:13:18.713 回答