opentelemetry-js/getting-started/traced-example/tracing.js

39 lines
1.2 KiB
JavaScript

"use strict";
const { NodeTracerProvider } = require("@opentelemetry/node");
const { SimpleSpanProcessor } = require("@opentelemetry/tracing");
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "getting-started",
})
});
provider.addSpanProcessor(
new SimpleSpanProcessor(
new ZipkinExporter({
// If you are running your tracing backend on another host,
// you can point to it using the `url` parameter of the
// exporter config.
})
)
);
provider.register();
// load old default plugins
registerInstrumentations({
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
],
});
console.log("tracing initialized");