Class SkyWalkingLogExporter

java.lang.Object
codes.grow.packages.skywalking.SkyWalkingLogExporter
All Implemented Interfaces:
LogExporter

public final class SkyWalkingLogExporter extends Object implements LogExporter
LogExporter that posts batches to OAP's native log API (POST /v3/logs, JSON array, port 12800). Native logs carry the trace context, register the service and are queryable a few seconds later. The body is sent uncompressed (gzip is not verified on OAP's HTTP receiver).

Mapping of a SPEC LogRecord to native LogData: resource["service.name"] → service, service.instance.id → serviceInstance, body → body.text.text, severityText → tag level, attributes (stringified, nested values as JSON) → tags, traceId → traceContext.traceId (enables relatedTrace queries), spanId → tag span_id.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Service name used when a record has no service.name resource attribute.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SkyWalkingLogExporter(HttpTransport transport, String serviceName, boolean ownsTransport)
    Creates an exporter on a transport whose base URL is the OAP REST URL.
  • Method Summary

    Modifier and Type
    Method
    Description
    export(List<LogRecord> records, ExportOptions options)
    Posts one batch; transport errors fail the future (the batch processor retries retryable ones).
    Idempotent; closes the transport when the exporter owns it.
    static String
    tagText(Object value)
    Converts an attribute value to SkyWalking's string tag form (JSON for lists and maps).
    static Map<String,Object>
    toLogData(LogRecord record, String defaultService)
    Maps a record to the native LogData JSON object (see the class description).
    static LogRecord
    Maps a stored log back to a SPEC record: tag level → severity and severity text (default INFO), a 16-hex span_id tag → spanId, a 32-hex traceId → traceId (native trace ids go to attribute sw.trace_id), other tags → attributes (strings), service/instance → resource service.name/service.instance.id, endpoint → resource sw.endpoint.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_SERVICE_NAME

      public static final String DEFAULT_SERVICE_NAME
      Service name used when a record has no service.name resource attribute.
      See Also:
  • Constructor Details

    • SkyWalkingLogExporter

      public SkyWalkingLogExporter(HttpTransport transport, String serviceName, boolean ownsTransport)
      Creates an exporter on a transport whose base URL is the OAP REST URL.
      Parameters:
      transport - transport (for example SkyWalkingClient.transport())
      serviceName - service name for records without service.name (null = "unknown_service")
      ownsTransport - close the transport on shutdown()
  • Method Details

    • tagText

      public static String tagText(Object value)
      Converts an attribute value to SkyWalking's string tag form (JSON for lists and maps).
      Parameters:
      value - attribute value
      Returns:
      the text
    • toLogData

      public static Map<String,Object> toLogData(LogRecord record, String defaultService)
      Maps a record to the native LogData JSON object (see the class description).
      Parameters:
      record - record
      defaultService - service name for records without service.name
      Returns:
      the LogData map
    • toRecord

      public static LogRecord toRecord(NativeLog log)
      Maps a stored log back to a SPEC record: tag level → severity and severity text (default INFO), a 16-hex span_id tag → spanId, a 32-hex traceId → traceId (native trace ids go to attribute sw.trace_id), other tags → attributes (strings), service/instance → resource service.name/service.instance.id, endpoint → resource sw.endpoint.
      Parameters:
      log - stored log
      Returns:
      the record
    • export

      public CompletableFuture<ExportResult> export(List<LogRecord> records, ExportOptions options)
      Posts one batch; transport errors fail the future (the batch processor retries retryable ones).
      Specified by:
      export in interface LogExporter
      Parameters:
      records - records
      options - export options (gzip is ignored: OAP's HTTP receiver gets plain JSON)
      Returns:
      a future with the result
    • shutdown

      public CompletableFuture<Void> shutdown()
      Idempotent; closes the transport when the exporter owns it.
      Specified by:
      shutdown in interface LogExporter
      Returns:
      a completed future