@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)); }
/** * Transforms the {@link SpanContextImpl} to the {@link SpanIdent}. * * @param context * context. * @return {@link SpanIdent}. */ public static SpanIdent transformSpanContext(SpanContextImpl context) { if (null == context) { return null; } return new SpanIdent(context.getId(), context.getTraceId()); }
/** * Tryies to get the span with the given {@link SpanIdent}. * * @param ident * the span identifier to search for * @return an {@link Optional} which may contain the {@link Span} with belongs to the given * {@link SpanIdent} */ private Optional<Span> getSpan(SpanIdent ident) { return spans.stream().filter(s -> s.getSpanIdent().equals(ident)).findAny(); }
/** * Returns whether the current tree contains already a span with an id equals to the one of the * given span ident. * * @param spanIdent * span ident to check * @return <code>true</code> if the tree contains a span with the id of the given span ident */ private boolean isSpanInTree(SpanIdent spanIdent) { return spansExistingInTree.containsKey(spanIdent.getId()); }
ServerSpan createServerSpan(Span parent) { ServerSpan span = new ServerSpan(); span.setSpanIdent(new SpanIdent(idSequence++, 0)); span.setTimeStamp(new Timestamp(timeSequence++)); span.setPropagationType(PropagationType.PROCESS); if (parent != null) { span.setParentSpanId(parent.getSpanIdent().getId()); } return span; }
@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."); } });
/** * Resolves a span element. * * @param parent * a {@link InvocationTreeElement} from type {@link TreeElementType#SPAN}. */ private void resolveSpan(InvocationTreeElement parent) { Span currentSpan = (Span) parent.getDataElement(); if (!currentSpan.isCaller()) { // server span - expect invocation sequence for (InvocationSequenceData data : invocationSequences) { if (InvocationSequenceDataHelper.hasSpanIdent(data) && data.getSpanIdent().equals(currentSpan.getSpanIdent())) { InvocationTreeElement child = createTreeElement(data, parent); resolveInvocationSequence(child); } } } for (Span span : spans) { // if span is already in the tree, skip it if (isSpanInTree(span.getSpanIdent())) { continue; } if (span.getParentSpanId() == currentSpan.getSpanIdent().getId()) { InvocationTreeElement child = createTreeElement(span, parent); resolveSpan(child); } } }
/** * {@inheritDoc} */ @Override public long getObjectSize(IObjectSizes objectSizes) { return getObjectSize(objectSizes, true); }
/** * Calculates a key which is used for the lookup map and identifying * {@link InvocationTreeElement} based on the contained data object. * * @param object * the object to generate a key for * @return the key of the given object */ public static String calculateLookupKey(Object object) { if (object == null) { return null; } if (object instanceof Span) { return "span_" + ((Span) object).getSpanIdent().getId(); } else if (object instanceof InvocationSequenceData) { return "isd_" + ((InvocationSequenceData) object).getId(); } else if (object instanceof SpanIdent) { return "span_" + ((SpanIdent) object).getId(); } return null; }
ClientSpan createClientSpan(Span parent) { ClientSpan span = new ClientSpan(); span.setSpanIdent(new SpanIdent(idSequence++, 0)); span.setTimeStamp(new Timestamp(timeSequence++)); span.setPropagationType(PropagationType.PROCESS); if (parent != null) { span.setParentSpanId(parent.getSpanIdent().getId()); } return span; }
SpanIdent spanIdent = spanIdentAware.getSpanIdent(); if (null != spanIdent) { traceIdSet.add(spanIdent.getTraceId());
@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)); }
@Override public void run() { boolean reschedule = true; try { SpanIdent backEndSpanIdent = new SpanIdent(traceId, traceId); AbstractSpan backEndSpan = spanDao.get(backEndSpanIdent); if (backEndSpan != null) { backEndSpan.setParentSpanId(eumSpanId); reschedule = false; } } finally { if (reschedule) { schedule(false); // retry later } } }
/** * 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"); } } }
return false; } else if (!this.spanIdent.equals(other.spanIdent)) { return false;
/** * {@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); } } } }
/** * Resolve the span details (like has nested exceptions, has SQL statement..). */ private void resolveSpanDetails() { // Load invocation sequences for calculating span details. We are doing this here again, // because we did not loaded any invocations at the beginning because we don't needed them // to build the tree. if (mode == Mode.ONLY_SPANS_WITH_SDK) { invocationSequences = loadInvocationSequences(); } // Creating a mapping from span ids to invocation sequences in order to prevent a continuous // iteration over the invocation sequences - when two spans refers the same // trace, we are trying to return the invocation sequence which follows the span (= is a // root span). Map<Long, InvocationSequenceData> spanToInvocationSequenceMap = InvocationSequenceDataHelper.asStream(invocationSequences).filter(InvocationSequenceDataHelper::hasSpanIdent) .collect(Collectors.toMap(i -> i.getSpanIdent().getId(), Function.identity(), (i1, i2) -> InvocationSequenceDataHelper.isRootElementInSequence(i1) ? i1 : i2)); // now we actually resolves the span details (like has nested exceptions..) tree.asStream().filter(e -> e.getType() == TreeElementType.SPAN).forEach(e -> resolveSpanDetails(e, spanToInvocationSequenceMap)); }
throw new JsonParseException(jp, "Could not parse EUM Span, expected numeric values.", ne); // NOPMD result.setSpanIdent(new SpanIdent(id, traceId)); result.setParentSpanId(parentId);
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);