public static CloudTraceContext toCloudTraceContext(SpanContext spanContext) {
checkNotNull(spanContext, "spanContext");
ByteBuffer traceIdBuf = ByteBuffer.wrap(spanContext.getTraceId().getBytes());
TraceIdProto traceIdProto =
TraceIdProto.newBuilder().setHi(traceIdBuf.getLong()).setLo(traceIdBuf.getLong()).build();
ByteBuffer spanIdBuf = ByteBuffer.wrap(spanContext.getSpanId().getBytes());
return new CloudTraceContext(
traceIdProto.toByteArray(),
spanIdBuf.getLong(),
spanContext.getTraceOptions().isSampled() ? 1L : 0L);
}