log2trace-ui - v1.0.0-RC1
    Preparing search index...

    Function transformLogs

    • Convert an array of arbitrary log records into OpenTelemetry-shaped TraceData.

      This is the entry point of the log-to-trace pipeline that the <trace-visualizer> component uses internally when given raw logs via the logData setter. It is also exported for callers that want to perform the transformation up-front.

      The transform runs in five phases:

      1. Group by trace — bucket logs by config.traceIdField.
      2. Group into spans — within each trace, bucket logs by config.spanGroupFields (composite key) or, if absent, treat each log as its own span keyed by config.spanIdField.
      3. Build spans — derive name (mode of spanNameField), start/end timestamps from timestampField / endTimeField, status from statusCodeField, kind from spanKindRules / defaultSpanKind, and one OTel Event per source log.
      4. Resolve parents — when parentSpanLookupFields is set, link spans whose lookup values match another span's leading composite-key components, preferring an encompassing parent and falling back to the latest span starting before the child.
      5. Group by service — bucket the resulting spans into ResourceSpans keyed by serviceNameField.

      Trace and span IDs are deterministic (DJB2-derived hex), so re-running the transform on the same input yields identical IDs.

      Parameters

      • logs: LogEntry[]

        The raw log records to transform. May be empty.

      • config: TransformConfig

        Field-mapping configuration. The four fields traceIdField, spanNameField, serviceNameField, and timestampField are required by the type.

      Returns TraceData

      OTel TraceData ready for TraceTree.build (from trace-tree.ts) or for passing to the traceData setter on <trace-visualizer>.

      import { transformLogs } from 'log2trace-ui';

      const trace = transformLogs(myLogs, {
      traceIdField: 'text.BTMID',
      spanGroupFields: ['text.InitiatingApplication', 'text.Action'],
      spanNameField: 'text.Action',
      serviceNameField: 'text.MachineName',
      timestampField: 'text.Timestamp',
      });