/** * Same as {@link #isRoot()}. Needed for querying. * * @return {@link #isRoot()} */ public boolean getRoot() { // NOPMD return isRoot(); }
/** * {@inheritDoc} */ @Override public long getObjectSize(IObjectSizes objectSizes) { return getObjectSize(objectSizes, true); }
/** * {@inheritDoc} */ @Override public String toString() { return "AbstractSpan [isCaller()=" + this.isCaller() + ", getSpanIdent()=" + this.getSpanIdent() + ", getDuration()=" + this.getDuration() + ", getPropagationType()=" + this.getPropagationType() + ", getReferenceType()=" + this.getReferenceType() + ", getParentSpanId()=" + this.getParentSpanId() + ", isRoot()=" + this.isRoot() + ", getTags()=" + this.getTags() + "]"; }
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; }
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; }
/** * 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; }
@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 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()); }
/** * 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(); }
/** * Creates {@link ClientSpan} or {@link ServerSpan} based on the information from the given * {@link SpanImpl}. * * @param spanImpl * opentracing span impl * @return {@link AbstractSpan} */ private static AbstractSpan createCorrectSpanType(SpanImpl spanImpl) { if (spanImpl.isClient()) { ClientSpan clientSpan = new ClientSpan(); return clientSpan; } else { ServerSpan serverSpan = new ServerSpan(); return serverSpan; } }
/** * 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()); }
InvocationSequenceData createSequence(Span span) { InvocationSequenceData data = new InvocationSequenceData(); data.setId(idSequence++); if (span != null) { data.setSpanIdent(span.getSpanIdent()); } data.setTimeStamp(new Timestamp(timeSequence++)); return data; }
/** * Returns descriptive reference for a span if one is provided. * * @param span * span * @return Reference more descriptive * @see Reference more descriptive */ public static String getDescriptiveReference(Span span) { String referenceType = span.getReferenceType(); if (References.CHILD_OF.equals(referenceType)) { return "Synchronous"; } else if (References.FOLLOWS_FROM.equals(referenceType)) { return "Non-Synchronous"; } return "N/A"; }
/** * Returns the timestamp of this element. The time stamp will be gathered from the data object. * * @return the {@link Timestamp} of this element */ private Timestamp getTimeStamp() { if (dataElement instanceof Span) { return ((Span) dataElement).getTimeStamp(); } else if (dataElement instanceof InvocationSequenceData) { return ((InvocationSequenceData) dataElement).getTimeStamp(); } return null; }
/** * Returns result of {@link #valueOf(String)} if the given parameter is not <code>null</code>. * * @param propagation * as string * @return {@link PropagationType} enum or <code>null</code> */ public static PropagationType safeValueOf(String propagation) { if (null != propagation) { return valueOf(propagation); } else { return null; } }
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver instanceof ISpanIdentAware) { if (NOT_NULL_PROPERTY.equals(property)) { return null != ((ISpanIdentAware) receiver).getSpanIdent(); } } if (receiver instanceof SpanIdent) { if (NOT_NULL_PROPERTY.equals(property)) { return true; } } return false; }
/** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = (prime * result) + ((this.activeAgentModules == null) ? 0 : this.activeAgentModules.hashCode()); result = (prime * result) + ((this.details == null) ? 0 : this.details.hashCode()); result = (prime * result) + (int) (this.sessionId ^ (this.sessionId >>> 32)); result = (prime * result) + (int) (this.tabId ^ (this.tabId >>> 32)); return result; }
ServerSpan createSdkSpan(Span parent) { ServerSpan span = createServerSpan(parent); span.setPropagationType(null); return span; }
/** * Creates a new {@link InvocationTreeElement} which is related to the given parent and contains * the given data objet. * * @param dataElement * the data element of the created {@link InvocationTreeElement} * @param parent * the parent element * @return the newly created {@link InvocationTreeElement} */ private InvocationTreeElement createTreeElement(Object dataElement, InvocationTreeElement parent) { InvocationTreeElement element = new InvocationTreeElement(dataElement); if (parent != null) { parent.addChild(element); } if (dataElement instanceof Span) { Span span = (Span) dataElement; // put the span into the `spansExistingInTree` map in order to mark that it is existing // in the tree, now spansExistingInTree.put(span.getSpanIdent().getId(), element); } return element; }
/** * Resolves additional span details (e.g. has nested exception or SQL data) for the given * {@link InvocationTreeElement}. * * @param element * the {@link InvocationTreeElement} which details should be resolved * @param spanToInvocationSequenceMap * lookup map for mapping the spans to {@link InvocationSequenceData} */ private void resolveSpanDetails(InvocationTreeElement element, Map<Long, InvocationSequenceData> spanToInvocationSequenceMap) { if (!element.isSpan()) { return; } InvocationSequenceData sequenceData = spanToInvocationSequenceMap.get(((Span) element.getDataElement()).getSpanIdent().getId()); if (sequenceData != null) { element.setHasNestedSqls((sequenceData.isNestedSqlStatements() != null) && sequenceData.isNestedSqlStatements()); element.setHasNestedExceptions((sequenceData.isNestedExceptions() != null) && sequenceData.isNestedExceptions()); } }