Class TraceContext

java.lang.Object
com.dynatrace.agent.api.TraceContext

public class TraceContext extends Object
Represents a W3C Trace Context containing traceparent and tracestate headers.

This object is returned by Dynatrace.generateTraceContext(String, String) and provides access to validated traceparent and tracestate values that can be used to manually tag HTTP requests for distributed tracing.

Usage example:

 TraceContext traceContext = Dynatrace.generateTraceContext(request.header("traceparent"), request.header("tracestate"));
 if(traceContext != null) {
     request = request.newBuilder()
             // maybe relevant for other libraries: addHeader or setHeader
             .addHeader("traceparent", traceContext.getTraceparent())
             .addHeader("tracestate", traceContext.getTracestate())
             .build();
 }
 
Since:
8.333
See Also:
  • Constructor Details

    • TraceContext

      public TraceContext(String traceparent, String tracestate)
      Generates a W3C Trace Context containing traceparent and tracestate headers.
      Parameters:
      traceparent - the traceparent header value
      tracestate - the tracestate header value
  • Method Details

    • getTraceparent

      public String getTraceparent()
      Returns the traceparent header value.

      The traceparent header is a W3C standard header that contains trace-id, parent-id (span-id), and trace-flags. This value can be used as the value for the "traceparent" HTTP header.

      Returns:
      the traceparent header value, never null
    • getTracestate

      public String getTracestate()
      Returns the tracestate header value.

      The tracestate header is a W3C standard header that contains vendor-specific trace information. This value can be used as the value for the "tracestate" HTTP header.

      Returns:
      the tracestate header value, never null (may be empty string)