64 lines · 2.2 KB · TypeScript
RawDownload
import { Effect, Layer, References, Tracer } from "effect";import { OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability"; import { ServerConfig } from "../../config.ts";import { ServerLoggerLive } from "../../serverLogger.ts";import { makeLocalFileTracer } from "../LocalFileTracer.ts"; const otlpSerializationLayer = OtlpSerialization.layerJson; export const ObservabilityLive = Layer.unwrap(  Effect.gen(function* () {    const config = yield* ServerConfig;     const traceReferencesLayer = Layer.mergeAll(      Layer.succeed(Tracer.MinimumTraceLevel, config.traceMinLevel),      Layer.succeed(References.TracerTimingEnabled, config.traceTimingEnabled),    );     const tracerLayer = Layer.effect(      Tracer.Tracer,      Effect.gen(function* () {        const delegate =          config.otlpTracesUrl === undefined            ? undefined            : yield* OtlpTracer.make({                url: config.otlpTracesUrl,                exportInterval: `${config.otlpExportIntervalMs} millis`,                resource: {                  serviceName: config.otlpServiceName,                  attributes: {                    "service.runtime": "t3-server",                    "service.mode": config.mode,                  },                },              });         return yield* makeLocalFileTracer({          filePath: config.serverTracePath,          maxBytes: config.traceMaxBytes,          maxFiles: config.traceMaxFiles,          batchWindowMs: config.traceBatchWindowMs,          ...(delegate ? { delegate } : {}),        });      }),    ).pipe(Layer.provideMerge(otlpSerializationLayer));     const metricsLayer =      config.otlpMetricsUrl === undefined        ? Layer.empty        : OtlpMetrics.layer({            url: config.otlpMetricsUrl,            exportInterval: `${config.otlpExportIntervalMs} millis`,            resource: {              serviceName: config.otlpServiceName,              attributes: {                "service.runtime": "t3-server",                "service.mode": config.mode,              },            },          }).pipe(Layer.provideMerge(otlpSerializationLayer));     return Layer.mergeAll(ServerLoggerLive, traceReferencesLayer, tracerLayer, metricsLayer);  }),);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t