UNPKG

openclaw-grafana-lens

Version:

OpenClaw plugin that gives AI agents full Grafana access — 18 composable tools for PromQL/LogQL/TraceQL queries, dashboard creation, alerting, SRE investigation, security monitoring, data collection pipeline management via Grafana Alloy (29 recipes), and

43 lines (42 loc) 1.67 kB
/** * OTLP Logs Provider * * Central LoggerProvider lifecycle module. Creates an OpenTelemetry * LoggerProvider that pushes structured log records via OTLP HTTP/JSON * to the configured collector (LGTM stack, Grafana Cloud, etc.). * * Mirrors the otel-metrics.ts pattern exactly: * - Local provider only (NO global registration — avoids conflict with diagnostics-otel) * - Fire-and-forget emission via BatchLogRecordProcessor * - Same shared resource identity (service.name=openclaw, service.namespace=grafana-lens) * * Data flow: * Diagnostic events / tool calls → OTel LogRecord → OTLP exporter → Collector → Loki → Grafana */ import { SeverityNumber } from "@opentelemetry/api-logs"; import { LoggerProvider, BatchLogRecordProcessor, } from "@opentelemetry/sdk-logs"; import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http"; import { createOtelResource } from "./otel-resource.js"; export { SeverityNumber }; const DEFAULT_ENDPOINT = "http://localhost:4318/v1/logs"; export function createOtelLogs(config) { const exporter = new OTLPLogExporter({ url: config.endpoint || DEFAULT_ENDPOINT, headers: config.headers, }); const resource = createOtelResource(config); const provider = new LoggerProvider({ resource }); provider.addLogRecordProcessor(new BatchLogRecordProcessor(exporter, { scheduledDelayMillis: 5_000, })); const logger = provider.getLogger("grafana-lens"); return { logger, async forceFlush() { await provider.forceFlush(); }, async shutdown() { await provider.shutdown(); }, }; }