Skip to content
CodeSook
CodeSook

08.Telemetry


install dependencies

Terminal window
pnpm add @effect/opentelemetry
pnpm add @opentelemetry/exporter-trace-otlp-http
pnpm add @opentelemetry/sdk-trace-base
pnpm add @opentelemetry/sdk-trace-node
pnpm add @opentelemetry/sdk-trace-web
pnpm add @opentelemetry/sdk-metrics
pnpm add @opentelemetry/exporter-prometheus
pnpm add @opentelemetry/auto-instrumentations-node

สร้าง folder telemetry

Terminal window
src
├── configure
├── controllers
├── index.ts
├── repositories
├── runtimes
└── index.ts
├── schema
├── services
├── telemetry
└── node-sdk.ts
└── types
src/telemetry/node-sdk.ts
src/telemetry/node-sdk.ts
import { NodeSdk } from "@effect/opentelemetry"
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node"
import { PrometheusExporter } from "@opentelemetry/exporter-prometheus"
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base"
export const NodeSdkLive = NodeSdk.layer(() => {
return {
instrumentations: [getNodeAutoInstrumentations()],
metricReader: new PrometheusExporter({
port: 9464,
}),
resource: {
serviceName: "Overtime Tracking API",
},
spanProcessor: new BatchSpanProcessor(
new OTLPTraceExporter({
url: "http://34.126.124.178:4318/v1/traces", // Tempo OTLP HTTP
}),
),
}
})