在我使用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 导出器之一?