@Test public void when_anEntityIsGiven_then_ContextIsReturned() { when(segment.getParentSegment()).thenReturn(segment); when(segment.getTraceId()).thenReturn(xrayTraceId); when(segment.getId()).thenReturn(SEGMENT_ID); when(segment.isSampled()).thenReturn(true); when(segment.getParentId()).thenReturn(SEGMENT_ID); assertEquals(context, ContextUtils.entityToSpanContext(segment)); }
public static SpanContext entityToSpanContext(final Entity entity) { TraceId traceId = TraceId .fromLowerBase16(xrayTraceIdToOT(entity.getParentSegment().getTraceId().toString()), 0); SpanId spanId = SpanId.fromLowerBase16(entity.getId(), 0); TraceFlags flags = TraceFlags.builder() .setIsSampled(entity.getParentSegment().isSampled()) .build(); Tracestate state = Tracestate.getDefault(); if (entity instanceof Segment && entity.getParentId() != null) { return SpanContext.createFromRemoteParent(traceId, spanId, flags, state); } else { return SpanContext.create(traceId, spanId, flags, state); } }
ContextUtils { public static SpanContext entityToSpanContext(final Entity entity) { TraceId traceId = TraceId .fromLowerBase16(xrayTraceIdToOT(entity.getParentSegment().getTraceId().toString()), 0); SpanId spanId = SpanId.fromLowerBase16(entity.getId(), 0); TraceFlags flags = TraceFlags.builder() .setIsSampled(entity.getParentSegment().isSampled()) .build(); Tracestate state = Tracestate.getDefault(); if (entity instanceof Segment && entity.getParentId() != null) { return SpanContext.createFromRemoteParent(traceId, spanId, flags, state); } else { return SpanContext.create(traceId, spanId, flags, state); } } }
ContextUtils { public static SpanContext entityToSpanContext(final Entity entity) { TraceId traceId = TraceId .fromLowerBase16(xrayTraceIdToOT(entity.getParentSegment().getTraceId().toString()), 0); SpanId spanId = SpanId.fromLowerBase16(entity.getId(), 0); TraceFlags flags = TraceFlags.builder() .setIsSampled(entity.getParentSegment().isSampled()) .build(); Tracestate state = Tracestate.getDefault(); if (entity instanceof Segment && entity.getParentId() != null) { return SpanContext.createFromRemoteParent(traceId, spanId, flags, state); } else { return SpanContext.create(traceId, spanId, flags, state); } }  }
ContextUtils { public static SpanContext entityToSpanContext(final Entity entity) { TraceId traceId = TraceId .fromLowerBase16(xrayTraceIdToOT(entity.getParentSegment().getTraceId().toString()), 0); SpanId spanId = SpanId.fromLowerBase16(entity.getId(), 0); TraceFlags flags = TraceFlags.builder() .setIsSampled(entity.getParentSegment().isSampled()) .build(); Tracestate state = Tracestate.getDefault(); if (entity instanceof Segment && entity.getParentId() != null) { return SpanContext.createFromRemoteParent(traceId, spanId, flags, state); } else { return SpanContext.create(traceId, spanId, flags, state); } }  static SpanContext entityToSpanContext(final Entity entity); static SpanContext headerToSpanContext(final TraceHeader header); static TraceHeader spanContextToHeader(final SpanContext context); }
ContextUtils { public static SpanContext entityToSpanContext(final Entity entity) { TraceId traceId = TraceId .fromLowerBase16(xrayTraceIdToOT(entity.getParentSegment().getTraceId().toString()), 0); SpanId spanId = SpanId.fromLowerBase16(entity.getId(), 0); TraceFlags flags = TraceFlags.builder() .setIsSampled(entity.getParentSegment().isSampled()) .build(); Tracestate state = Tracestate.getDefault(); if (entity instanceof Segment && entity.getParentId() != null) { return SpanContext.createFromRemoteParent(traceId, spanId, flags, state); } else { return SpanContext.create(traceId, spanId, flags, state); } }  static SpanContext entityToSpanContext(final Entity entity); static SpanContext headerToSpanContext(final TraceHeader header); static TraceHeader spanContextToHeader(final SpanContext context);  }