Skip to content

Instantly share code, notes, and snippets.

@taylor-lindores-reeves
Created September 21, 2022 15:02
Show Gist options
  • Save taylor-lindores-reeves/9b8a85eef9f266997ed940e5c8adcbf4 to your computer and use it in GitHub Desktop.
Save taylor-lindores-reeves/9b8a85eef9f266997ed940e5c8adcbf4 to your computer and use it in GitHub Desktop.
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { Resource } from "@opentelemetry/resources";
import { JaegerExporter } from "@opentelemetry/exporter-jaeger";
import { Logger } from "@api/services/LoggerService";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
/**
* Jaeger UI: http://localhost:16686/
* How to setup Docker: https://www.jaegertracing.io/docs/1.6/getting-started/
* This file configures Prisma, Express & HTTP tracing
*/
// eslint-disable-next-line import/prefer-default-export
export const initJaegerTracing = () => {
const jaegerExporter = new JaegerExporter({
// host: 'localhost', // optional
// port: 6832, // optional
// OR you can use the HTTPSender as follows
/* The endpoint for the jaeger-agent. */
endpoint: process.env.JAEGER_URL || "http://localhost:14268/api/traces",
maxPacketSize: 65000, // optional
});
const provider: NodeTracerProvider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "carhuna-api",
}),
});
provider.addSpanProcessor(new BatchSpanProcessor(jaegerExporter));
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new HttpInstrumentation(),
new ExpressInstrumentation(),
new PrismaInstrumentation(),
],
});
provider.register();
Logger.verbose("Jaeger tracing running");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment