@Override public Span load(SpanIdent ident) throws Exception { // collect all from same trace as we expect them to be asked in same point of time // this way we don't do round-trips to only get one span // example: // - you ask for span id 1 and trace id 2 // - I load all spans with trace id 2, which might be few of them // - the spans not having id 1 I add to the cache manually // - i "load" the one with id 1, which will effectively add it also to the cache.. Collection<? extends Span> spans = service.getSpans(ident.getTraceId()); // add other spans from the trace to the cache and returned the one we tried to load if (CollectionUtils.isNotEmpty(spans)) { Span value = null; for (Span span : spans) { if (Objects.equals(ident, span.getSpanIdent())) { value = span; } else { cache.put(span.getSpanIdent(), span); } } // return asked one if (null != value) { return value; } } // if we can not locate, throw exception as per loading cache api throw new Exception("Span with ident " + ident + " can not be found."); } });
@Test public void transformerInterface() { SpanContextImpl context = new SpanContextImpl(1, 2, 3, null, Collections.<String, String> emptyMap()); SpanIdent spanIdent = SpanContextTransformer.INSTANCE.transform(context); assertThat(spanIdent.getId(), is(1L)); assertThat(spanIdent.getTraceId(), is(2L)); }
@Test public void happyPath() { SpanContextImpl context = new SpanContextImpl(1, 2, 3, null, Collections.<String, String> emptyMap()); SpanIdent spanIdent = SpanContextTransformer.transformSpanContext(context); assertThat(spanIdent.getId(), is(1L)); assertThat(spanIdent.getTraceId(), is(2L)); }
@Test public void context() { when(spanImpl.context()).thenReturn(new SpanContextImpl(1, 2, 3, null, Collections.<String, String> emptyMap())); AbstractSpan span = SpanTransformer.transformSpan(spanImpl); SpanIdent spanIdent = span.getSpanIdent(); assertThat(spanIdent.getId(), is(1L)); assertThat(spanIdent.getTraceId(), is(2L)); assertThat(span.getParentSpanId(), is(3L)); }
@Test public void transformerInterface() { when(spanImpl.context()).thenReturn(new SpanContextImpl(1, 2, 3, null, Collections.<String, String> emptyMap())); AbstractSpan span = SpanTransformer.INSTANCE.transform(spanImpl); SpanIdent spanIdent = span.getSpanIdent(); assertThat(spanIdent.getId(), is(1L)); assertThat(spanIdent.getTraceId(), is(2L)); assertThat(span.getParentSpanId(), is(3L)); }
@Test public void testAllDataAvailable() throws IOException { ObjectNode node = buildEventListenerRecord(); EUMSpan span = performDeserialization(node); assertThat(span.getDetails(), instanceOf(JSEventListenerExecution.class)); assertThat(span.getSpanIdent().getId(), equalTo(ELEMENT_ID)); assertThat(span.getSpanIdent().getTraceId(), equalTo(TRACE_ID)); assertThat(span.getParentSpanId(), equalTo(PARENT_ID)); assertThat(span.getTimeStamp().getTime(), equalTo(ENTER_TIMESTAMP)); assertThat(span.getDuration(), equalTo(DURATION)); JSEventListenerExecution exec = (JSEventListenerExecution) span.getDetails(); assertThat(exec.getFunctionName(), equalTo(FUNCTION_NAME)); assertThat(exec.getEventType(), equalTo(EVENT_TYPE)); }
@Test public void testDefaultTraceId() throws IOException { ObjectNode node = buildEventListenerRecord(); node.remove("traceId"); EUMSpan span = performDeserialization(node); assertThat(span.getDetails(), instanceOf(JSEventListenerExecution.class)); assertThat(span.getSpanIdent().getId(), equalTo(ELEMENT_ID)); assertThat(span.getSpanIdent().getTraceId(), equalTo(ELEMENT_ID)); assertThat(span.getParentSpanId(), equalTo(PARENT_ID)); assertThat(span.getTimeStamp().getTime(), equalTo(ENTER_TIMESTAMP)); assertThat(span.getDuration(), equalTo(DURATION)); JSEventListenerExecution exec = (JSEventListenerExecution) span.getDetails(); assertThat(exec.getFunctionName(), equalTo(FUNCTION_NAME)); assertThat(exec.getEventType(), equalTo(EVENT_TYPE)); }
@Test public void testDefaultParentId() throws IOException { ObjectNode node = buildEventListenerRecord(); node.remove("parentId"); EUMSpan span = performDeserialization(node); assertThat(span.getDetails(), instanceOf(JSEventListenerExecution.class)); assertThat(span.getSpanIdent().getId(), equalTo(ELEMENT_ID)); assertThat(span.getSpanIdent().getTraceId(), equalTo(TRACE_ID)); assertThat(span.getParentSpanId(), equalTo(0L)); assertThat(span.getTimeStamp().getTime(), equalTo(ENTER_TIMESTAMP)); assertThat(span.getDuration(), equalTo(DURATION)); JSEventListenerExecution exec = (JSEventListenerExecution) span.getDetails(); assertThat(exec.getFunctionName(), equalTo(FUNCTION_NAME)); assertThat(exec.getEventType(), equalTo(EVENT_TYPE)); }
SpanIdent spanIdent = spanIdentAware.getSpanIdent(); if (null != spanIdent) { traceIdSet.add(spanIdent.getTraceId());
/** * {@inheritDoc} */ @Override protected void processData(DefaultData data, EntityManager entityManager) { if (data instanceof EUMSpan) { EUMSpan frontEndSpan = (EUMSpan) data; AbstractEUMSpanDetails details = frontEndSpan.getDetails(); if (details instanceof PageLoadRequest) { long traceId = frontEndSpan.getSpanIdent().getTraceId(); long eumSpanId = frontEndSpan.getSpanIdent().getId(); // if the ids are equal no correlation takes place, e.g. because the html was // cached. if (traceId != eumSpanId) { EumSpanCorrelationTask correlationTask = new EumSpanCorrelationTask(traceId, eumSpanId); correlationTask.schedule(true); } } } }
/** * Returns the styled text for a specific column. * * @param data * The data object to extract the information from. * @param enumId * The enumeration ID. * @return The styled string containing the information from the data object. */ private StyledString getStyledTextForColumn(Span data, Column enumId) { switch (enumId) { case TIME: return new StyledString(NumberFormatter.formatTimeWithMillis(data.getTimeStamp())); case DURATION: return new StyledString(NumberFormatter.formatDouble(data.getDuration(), timeDecimalPlaces)); case PROPAGATION: return TextFormatter.getPropagationStyled(data.getPropagationType()); case DETAILS: return TextFormatter.getSpanDetailsShort(data, cachedDataService); case ORIGIN: return TextFormatter.getSpanOriginStyled(data, cachedDataService.getPlatformIdentForId(data.getPlatformIdent())); case TRACE_ID: return new StyledString(Long.toHexString(data.getSpanIdent().getTraceId())); default: return new StyledString("error"); } } }
editorPropertiesData.setSensorName(SensorTypeEnum.TRACING.getDisplayName()); editorPropertiesData.setSensorImage(SensorTypeEnum.TRACING.getImage()); editorPropertiesData.setViewName("Details (" + Long.toHexString(spanIdent.getTraceId()) + ")"); editorPropertiesData.setViewImage(InspectIT.getDefault().getImage(InspectITImages.IMG_PROPERTIES)); editorPropertiesData.setPartNameFlag(PartType.VIEW); traceInputDefinitionExtra.setTraceId(spanIdent.getTraceId()); inputDefinition.addInputDefinitonExtra(InputDefinitionExtrasMarkerFactory.TRACE_EXTRAS_MARKER, traceInputDefinitionExtra);