Search in sources :

Example 1 with SpanWrapper

use of org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper in project wso2-synapse by wso2.

the class ArtifactHolderBasedParentResolver method resolveAnonymousSequenceFromUnknownSynCtx.

/**
 * Finds known message context system identity hash code related to the given unknown message context,
 * and resolves an anonymous sequence for that. Returns null when nothing is returned.
 * @param child                         Child statistic data unit.
 * @param unknownSynCtx                 Unknown message context.
 * @param anonymousSequenceContainer    Span wrapper that contains one or more anonymous sequences.
 * @param spanStore                     Span store.
 * @return                              Resolved anonymous sequence span wrapper.
 */
private static SpanWrapper resolveAnonymousSequenceFromUnknownSynCtx(StatisticDataUnit child, MessageContext unknownSynCtx, SpanWrapper anonymousSequenceContainer, SpanStore spanStore) {
    Set<String> knownSynCtxHashCodes = new HashSet<>();
    for (SpanWrapper anonymousSequence : anonymousSequenceContainer.getAnonymousSequences().values()) {
        knownSynCtxHashCodes.addAll(anonymousSequence.getKnownSynCtxHashCodes());
    }
    String knownSynCtxHashCode = findKnownSynCtxHashCode(child, TracingUtils.getSystemIdentityHashCode(unknownSynCtx), knownSynCtxHashCodes, spanStore);
    if (knownSynCtxHashCode != null) {
        return resolveAnonymousSequenceFromKnownSynCtx(knownSynCtxHashCode, anonymousSequenceContainer);
    }
    return null;
}
Also used : SpanWrapper(org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper) HashSet(java.util.HashSet)

Example 2 with SpanWrapper

use of org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper in project wso2-synapse by wso2.

the class ArtifactHolderBasedParentResolver method resolveAnonymousSequence.

/**
 * Resolves the appropriate anonymous sequence which is contained by the given anonymous sequence container,
 * as the parent.
 * The message context's system identity hash code is used to find the appropriate anonymous sequence.
 * A span wrapper has a list of message context system identity hash codes (so does the anonymous sequence
 * container), which denotes the message contexts that are known by it.
 * A known message context is a message context, that the component denoted by the span wrapper has branched
 * (travelled) through.
 *
 * When the message context of the child is known by any of the anonymous sequences,
 * that anonymous sequence is resolved.
 * When it is unknown by any of those, a known message context is mapped and derived from the unknown message
 * context of the child, and the respective anonymous sequence is resolved.
 * When this too doesn't resolve an anonymous sequence directly, the latest anonymous sequence is returned.
 * @param anonymousSequenceContainer    A span wrapper which contains one or more anonymous sequences.
 * @param child                         Child statistic data unit.
 * @param spanStore                     Span store.
 * @param childSynCtx                   Message context of the child.
 * @return                              Resolved anonymous sequence.
 */
private static SpanWrapper resolveAnonymousSequence(SpanWrapper anonymousSequenceContainer, StatisticDataUnit child, SpanStore spanStore, MessageContext childSynCtx) {
    SpanWrapper parent = resolveAnonymousSequenceFromKnownSynCtx(TracingUtils.getSystemIdentityHashCode(childSynCtx), anonymousSequenceContainer);
    if (parent != null) {
        return parent;
    }
    /*
        SynCtx is not known. Identify it by going through synCtx's of message flow representation parents.
        */
    parent = resolveAnonymousSequenceFromUnknownSynCtx(child, childSynCtx, anonymousSequenceContainer, spanStore);
    if (parent != null) {
        return parent;
    }
    return anonymousSequenceContainer.getLatestAnonymousSequence();
}
Also used : SpanWrapper(org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)

Example 3 with SpanWrapper

use of org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper in project wso2-synapse by wso2.

the class JaegerSpanHandler method finishSpan.

/**
 * Ends a span which is related to the provided basic statistic data unit, and performs necessary updates or
 * removals in the provided span store.
 * @param basicStatisticDataUnit    Basic statistic data unit object, which was collected during a statistic event.
 * @param synCtx                    Message context.
 * @param spanStore                 Span store object.
 * @param tracingScope              The tracing scope of the appropriate span.
 */
private void finishSpan(BasicStatisticDataUnit basicStatisticDataUnit, MessageContext synCtx, SpanStore spanStore, TracingScope tracingScope) {
    String spanWrapperId = TracingUtils.extractId(basicStatisticDataUnit);
    SpanWrapper spanWrapper = spanStore.getSpanWrapper(spanWrapperId);
    // Set the statistic data unit of the close event into the span wrapper
    if (spanWrapper != null && (basicStatisticDataUnit instanceof StatisticDataUnit)) {
        spanWrapper.setCloseEventStatisticDataUnit((StatisticDataUnit) basicStatisticDataUnit);
    }
    if (!Objects.equals(spanWrapper, spanStore.getOuterLevelSpanWrapper())) {
        // A non-outer level span
        spanStore.finishSpan(spanWrapper);
    } else {
        // An outer level span
        if (tracingScope.isEventCollectionFinished(synCtx)) {
            cleanupContinuationStateSequences(spanStore);
            spanStore.finishSpan(spanWrapper);
            tracingScopeManager.cleanupTracingScope(tracingScope.getTracingScopeId());
        }
    // Else - Absorb. Will be handled when all the callbacks are completed
    }
}
Also used : BasicStatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.BasicStatisticDataUnit) StatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit) SpanWrapper(org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)

Example 4 with SpanWrapper

use of org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper in project wso2-synapse by wso2.

the class JaegerSpanHandler method finishSpanForContinuationStateSequence.

/**
 * Finishes a span, which has been added as a continuation state sequence.
 * @param continuationStateSequenceInfo Object that contains information about the continuation state sequence.
 * @param spanStore             Span store object.
 */
private void finishSpanForContinuationStateSequence(ContinuationStateSequenceInfo continuationStateSequenceInfo, SpanStore spanStore) {
    String spanWrapperId = continuationStateSequenceInfo.getSpanReferenceId();
    SpanWrapper spanWrapper = spanStore.getSpanWrapper(spanWrapperId);
    spanStore.finishSpan(spanWrapper);
}
Also used : SpanWrapper(org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)

Example 5 with SpanWrapper

use of org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper in project wso2-synapse by wso2.

the class JaegerSpanHandler method handleCallbackFinishEvent.

private void handleCallbackFinishEvent(MessageContext messageContext) {
    TracingScope tracingScope = tracingScopeManager.getTracingScope(messageContext);
    tracingScope.removeCallback();
    // The last callback received in a scope will finish the outer level span
    if (tracingScope.isEventCollectionFinished(messageContext)) {
        synchronized (tracingScope.getSpanStore()) {
            cleanupContinuationStateSequences(tracingScope.getSpanStore());
            SpanWrapper outerLevelSpanWrapper = tracingScope.getSpanStore().getOuterLevelSpanWrapper();
            tracingScope.getSpanStore().finishSpan(outerLevelSpanWrapper);
            tracingScopeManager.cleanupTracingScope(tracingScope.getTracingScopeId());
        }
    }
}
Also used : SpanWrapper(org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper) TracingScope(org.apache.synapse.aspects.flow.statistics.opentracing.management.scoping.TracingScope)

Aggregations

SpanWrapper (org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)11 StatisticDataUnit (org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit)2 Span (io.opentracing.Span)1 SpanContext (io.opentracing.SpanContext)1 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)1 TextMapInjectAdapter (io.opentracing.propagation.TextMapInjectAdapter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BasicStatisticDataUnit (org.apache.synapse.aspects.flow.statistics.data.raw.BasicStatisticDataUnit)1 TracingScope (org.apache.synapse.aspects.flow.statistics.opentracing.management.scoping.TracingScope)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1