Class LogRecord

java.lang.Object
org.bluezoo.gumdrop.telemetry.LogRecord

public class LogRecord extends Object
A log record that can be associated with a span. In OpenTelemetry, logs contain traceId and spanId for correlation.
Author:
Chris Burdess
  • Field Details

  • Constructor Details

    • LogRecord

      public LogRecord(Span span, int severityNumber, String body)
      Creates a log record from the current span context.
      Parameters:
      span - the span to correlate with
      severityNumber - the severity level
      body - the log message
    • LogRecord

      public LogRecord(int severityNumber, String body)
      Creates a log record without span correlation.
      Parameters:
      severityNumber - the severity level
      body - the log message
  • Method Details

    • getTimeUnixNano

      public long getTimeUnixNano()
      Returns the timestamp in nanoseconds since Unix epoch.
    • getSeverityNumber

      public int getSeverityNumber()
      Returns the severity number.
    • getSeverityText

      public String getSeverityText()
      Returns the severity text.
    • getBody

      public String getBody()
      Returns the log body.
    • getTraceId

      public TraceId getTraceId()
      Returns the trace ID, or null if not correlated.
    • getSpanId

      public SpanId getSpanId()
      Returns the span ID, or null if not correlated.
    • hasSpanContext

      public boolean hasSpanContext()
      Returns true if this log is correlated with a span.
    • getAttributes

      public List<Attribute> getAttributes()
      Returns an unmodifiable view of the log attributes.
    • addAttribute

      public void addAttribute(Attribute attribute)
      Adds an attribute to this log record.
      Parameters:
      attribute - the attribute
    • addAttribute

      public void addAttribute(String key, String value)
      Adds a string attribute to this log record.
      Parameters:
      key - the attribute key
      value - the attribute value
    • info

      public static LogRecord info(Span span, String body)
      Creates an INFO level log record.
      Parameters:
      span - the span to correlate with
      body - the log message
      Returns:
      a new log record
    • warn

      public static LogRecord warn(Span span, String body)
      Creates a WARN level log record.
      Parameters:
      span - the span to correlate with
      body - the log message
      Returns:
      a new log record
    • error

      public static LogRecord error(Span span, String body)
      Creates an ERROR level log record.
      Parameters:
      span - the span to correlate with
      body - the log message
      Returns:
      a new log record
    • toString

      public String toString()
      Overrides:
      toString in class Object