Bỏ qua, đến nội dung

@digiforce-nc/plugin-telemetry

Plugin OpenTelemetry — thu thập traces, metrics và logs theo chuẩn OpenTelemetry, gửi đến backend quan sát (Jaeger, Zipkin, OTLP collector).

Plugin này làm gì?

Khi ứng dụng gặp vấn đề hiệu suất hoặc lỗi, cần dữ liệu quan sát (observability) để phân tích. Plugin tích hợp OpenTelemetry SDK vào server, tự động instrument HTTP request, database query, và cho phép plugin khác thêm custom spans/metrics.

Cơ chế hoạt động

Tính năng chính

#Tính năngMô tả
1Distributed tracingTheo dõi request xuyên suốt các service
2Auto-instrumentationTự động trace HTTP, database, Redis
3Custom spansPlugin khác thêm span riêng
4MetricsThu thập metrics (request count, latency, error rate)
5OTLP exportGửi dữ liệu qua OTLP protocol (gRPC/HTTP)
6SamplingCấu hình tỉ lệ sampling để giảm overhead

Cấu hình

Tham sốMặc địnhMô tả
enabledfalseBật/tắt telemetry
serviceNamedigiforceTên service trong traces
exporterTypeotlpLoại exporter (otlp, jaeger, zipkin)
endpointhttp://localhost:4318OTLP collector endpoint
samplingRate1.0Tỉ lệ sampling (0.0 - 1.0)
enabledInstrumentations['http', 'db']Danh sách auto-instrumentation

Kiến trúc nội bộ

Dependencies

PackageVai trò
@digiforce-nc/serverServer framework
@opentelemetry/sdk-nodeOpenTelemetry Node.js SDK
@opentelemetry/exporter-trace-otlp-httpOTLP trace exporter
@opentelemetry/exporter-metrics-otlp-httpOTLP metrics exporter
@opentelemetry/auto-instrumentations-nodeAuto-instrumentation

Lưu ý triển khai

  • Telemetry tăng nhẹ overhead (~1-3% CPU) — dùng sampling trong production
  • Cần OTLP collector (Jaeger, Grafana Tempo, hoặc OpenTelemetry Collector)
  • Trace context tự động propagate qua HTTP headers

Mục lục chi tiết