Class DatadogSpanErrors

java.lang.Object
codes.grow.packages.datadogapm.DatadogSpanErrors

public final class DatadogSpanErrors extends Object
Datadog error attributes (DECISIONS.md #2). The Datadog Agent keeps an OTLP exception only inside the events JSON and does not fill error.type / error.stack, so this package sets error.type, error.message and error.stack span attributes itself, which Datadog Error Tracking reads.

recordException(java.lang.Throwable) and setError(java.lang.Throwable) replace the generic helpers of Spans of the same name. The generic helpers (and withSpan, @Traced, the HTTP adapters and plain OpenTelemetry recordException calls) also get the attributes when spans are exported through DatadogTracing.initTracing(): its exporter fills them from the exception event (withDatadogErrorAttributes(SpanData)).

  • Field Details

  • Method Details

    • datadogErrorAttributes

      public static Map<String,String> datadogErrorAttributes(Throwable error)
      The Datadog error attributes for an exception: error.type (canonical class name, the same as OpenTelemetry's exception.type), error.message (when the exception has a message) and error.stack (the printed stack trace). null gives an empty map.
      Parameters:
      error - exception
      Returns:
      attributes
    • setErrorAttributes

      public static void setErrorAttributes(io.opentelemetry.api.trace.Span span, Throwable error)
      Sets the Datadog error attributes for error on span. No-op for null.
      Parameters:
      span - span
      error - exception
    • setErrorAttributes

      public static void setErrorAttributes(Throwable error)
      Sets the Datadog error attributes for error on the current span.
      Parameters:
      error - exception
    • recordException

      public static void recordException(Throwable error)
      Records an exception event on the current span (like Spans.recordException(java.lang.Throwable)) and sets the Datadog error attributes. The status is unchanged. null is ignored.
      Parameters:
      error - exception
    • setError

      public static void setError(Throwable error)
      Sets ERROR status (with the message) on the current span, records the exception event (like Spans.setError(Throwable)) and sets the Datadog error attributes. null is ignored.
      Parameters:
      error - exception
    • derivedErrorAttributes

      public static io.opentelemetry.api.common.Attributes derivedErrorAttributes(io.opentelemetry.sdk.trace.data.SpanData span)
      The Datadog error attributes derived from a finished span: from its last exception event (exception.type, exception.message, exception.stacktrace) or, for an ERROR status without an event message, error.message from the status description. Empty when the span already has error.type or error.message, or has no error.
      Parameters:
      span - finished span
      Returns:
      attributes to add
    • withDatadogErrorAttributes

      public static io.opentelemetry.sdk.trace.data.SpanData withDatadogErrorAttributes(io.opentelemetry.sdk.trace.data.SpanData span)
      span with the derivedErrorAttributes(SpanData) added, or span itself when there is nothing to add.
      Parameters:
      span - finished span
      Returns:
      span data