class ContextUtils {

  public static TraceHeader spanContextToHeader(final SpanContext context) {
    String otTraceId = context.getTraceId().toLowerBase16();
    String xrayTraceId =
        XRAY_VERSION_PREFIX + otTraceId.substring(0, 8) + XRAY_SEPARATOR + otTraceId.substring(8);
    TraceID xrayId = TraceID.fromString(xrayTraceId);
    TraceHeader header = new TraceHeader();
    header.setSampled(context.getTraceFlags().isSampled()
        ? TraceHeader.SampleDecision.SAMPLED : TraceHeader.SampleDecision.NOT_SAMPLED);
    header.setRootTraceId(xrayId);
    header.setParentId(context.getSpanId().toLowerBase16());

    return header;
  }

}