Search in sources :

Example 6 with StatisticDataUnit

use of org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit in project wso2-synapse by wso2.

the class CloseEventCollector method closeEntryEvent.

/**
 * Enqueue statistics event to the event queue. This method receives statistics events from synapse mediation
 * engine for all the component types.
 *
 * @param messageContext    synapse message context.
 * @param componentName     name of the component reporting statistics.
 * @param componentType     component type of the reporting component.
 * @param currentIndex      component's level in this message flow.
 * @param isContentAltering true if content is altered
 * @param propertyValue     value of the property
 */
public static void closeEntryEvent(MessageContext messageContext, String componentName, ComponentType componentType, Integer currentIndex, boolean isContentAltering, String propertyValue) {
    if (shouldReportStatistic(messageContext)) {
        Boolean isCollectingTracing = (Boolean) messageContext.getProperty(StatisticsConstants.FLOW_TRACE_IS_COLLECTED);
        StatisticDataUnit statisticDataUnit = new StatisticDataUnit();
        if (propertyValue != null) {
            statisticDataUnit.setPropertyValue(propertyValue);
        }
        statisticDataUnit.setComponentName(componentName);
        statisticDataUnit.setComponentType(componentType);
        if (currentIndex == null) {
            statisticDataUnit.setShouldTrackParent(true);
            statisticDataUnit.setCurrentIndex(StatisticDataCollectionHelper.getParentFlowPosition(messageContext, null));
            statisticDataUnit.setContinuationCall(true);
        } else {
            statisticDataUnit.setCurrentIndex(currentIndex);
        }
        StatisticDataCollectionHelper.collectData(messageContext, isContentAltering, isCollectingTracing, statisticDataUnit);
        StatisticsCloseEvent closeEvent = new StatisticsCloseEvent(statisticDataUnit);
        if (currentIndex == null) {
            addEvent(messageContext, closeEvent);
        } else {
            addEventAndDecrementCount(messageContext, closeEvent);
        }
        if (isOpenTracingEnabled()) {
            OpenTracingManagerHolder.getOpenTracingManager().getHandler().handleCloseEntryEvent(statisticDataUnit, messageContext);
        }
    }
}
Also used : StatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit) BasicStatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.BasicStatisticDataUnit) StatisticsCloseEvent(org.apache.synapse.aspects.flow.statistics.log.templates.StatisticsCloseEvent)

Example 7 with StatisticDataUnit

use of org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit in project wso2-synapse by wso2.

the class SpanTagger method setSpanTags.

/**
 * Sets tags to the span which is contained in the provided span wrapper, from information acquired from the
 * given basic statistic data unit.
 * @param spanWrapper               Span wrapper that contains the target span.
 */
public static void setSpanTags(SpanWrapper spanWrapper) {
    StatisticsLog openStatisticsLog = new StatisticsLog(spanWrapper.getStatisticDataUnit());
    Span span = spanWrapper.getSpan();
    if (OpenTracingManagerHolder.isCollectingPayloads() || OpenTracingManagerHolder.isCollectingProperties()) {
        if (OpenTracingManagerHolder.isCollectingPayloads()) {
            if (openStatisticsLog.getBeforePayload() != null) {
                span.setTag("beforePayload", openStatisticsLog.getBeforePayload());
            }
            StatisticDataUnit statisticDataUnit = spanWrapper.getCloseEventStatisticDataUnit();
            if (statisticDataUnit != null) {
                if (statisticDataUnit.getPayload() != null) {
                    span.setTag("afterPayload", statisticDataUnit.getPayload());
                }
            } else if (openStatisticsLog.getBeforePayload() != null) {
                // This means a close event hasn't been triggered so payload is equal to before payload
                span.setTag("afterPayload", openStatisticsLog.getBeforePayload());
            }
        }
        if (OpenTracingManagerHolder.isCollectingProperties()) {
            if (spanWrapper.getStatisticDataUnit().getContextPropertyMap() != null) {
                span.setTag("beforeContextPropertyMap", spanWrapper.getStatisticDataUnit().getContextPropertyMap().toString());
            }
            if (spanWrapper.getCloseEventStatisticDataUnit() != null) {
                if (spanWrapper.getCloseEventStatisticDataUnit().getContextPropertyMap() != null) {
                    span.setTag("afterContextPropertyMap", spanWrapper.getCloseEventStatisticDataUnit().getContextPropertyMap().toString());
                }
            } else if (openStatisticsLog.getContextPropertyMap() != null) {
                span.setTag("afterContextPropertyMap", openStatisticsLog.getContextPropertyMap().toString());
            }
            if (spanWrapper.getCloseEventStatisticDataUnit() != null && spanWrapper.getCloseEventStatisticDataUnit().getPropertyValue() != null) {
                span.setTag("propertyMediatorValue", spanWrapper.getCloseEventStatisticDataUnit().getPropertyValue());
            }
        }
    }
    if (openStatisticsLog.getComponentName() != null) {
        span.setTag("componentName", openStatisticsLog.getComponentName());
    }
    if (openStatisticsLog.getComponentTypeToString() != null) {
        span.setTag("componentType", openStatisticsLog.getComponentTypeToString());
    }
    span.setTag("threadId", Thread.currentThread().getId());
    if (openStatisticsLog.getComponentId() != null) {
        span.setTag("componentId", openStatisticsLog.getComponentId());
    }
    if (openStatisticsLog.getHashCode() != null) {
        span.setTag("hashcode", openStatisticsLog.getHashCode());
    }
    if (openStatisticsLog.getTransportHeaderMap() != null) {
        span.setTag("Transport Headers", openStatisticsLog.getTransportHeaderMap().toString());
    }
    if (openStatisticsLog.getStatusCode() != null) {
        span.setTag("Status code", openStatisticsLog.getStatusCode());
    }
    if (openStatisticsLog.getStatusDescription() != null) {
        span.setTag("Status description", openStatisticsLog.getStatusDescription());
    }
    if (openStatisticsLog.getEndpoint() != null) {
        span.setTag("Endpoint", String.valueOf(openStatisticsLog.getEndpoint().getJsonRepresentation()));
    }
}
Also used : StatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit) StatisticsLog(org.apache.synapse.aspects.flow.statistics.data.raw.StatisticsLog) Span(io.opentracing.Span)

Example 8 with StatisticDataUnit

use of org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit 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 9 with StatisticDataUnit

use of org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit in project wso2-synapse by wso2.

the class LatestActiveParentResolver method resolveParentForEndpointOrInboundEndpoint.

/**
 * Resolves the latest active span wrapper - which is either a Call mediator, a Send mediator,
 * or a flow continuable mediator, as the parent span wrapper for endpoints or inbound endpoints.
 * @param spanStore The span store object.
 * @return          Resolved parent span wrapper.
 */
public static SpanWrapper resolveParentForEndpointOrInboundEndpoint(SpanStore spanStore) {
    List<SpanWrapper> parentableSpans = spanStore.getActiveSpanWrappers();
    for (int i = parentableSpans.size() - 1; i >= 0; i--) {
        SpanWrapper spanWrapper = parentableSpans.get(i);
        StatisticDataUnit statisticDataUnit = spanWrapper.getStatisticDataUnit();
        if (isCallMediator(statisticDataUnit) || isSendMediator(statisticDataUnit) || isFlowContinuableMediator(statisticDataUnit)) {
            return spanWrapper;
        }
    }
    return null;
}
Also used : StatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit) SpanWrapper(org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)

Example 10 with StatisticDataUnit

use of org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit in project wso2-synapse by wso2.

the class StatisticDataCollectionHelperTest method testCollectData.

/**
 * Test collectData method by validating dataUnit.
 */
@Test
public void testCollectData() {
    PowerMockito.mockStatic(RuntimeStatisticCollector.class);
    PowerMockito.when(RuntimeStatisticCollector.isCollectingPayloads()).thenReturn(true);
    PowerMockito.when(RuntimeStatisticCollector.isCollectingProperties()).thenReturn(true);
    StatisticDataUnit dataUnit = new StatisticDataUnit();
    StatisticDataCollectionHelper.collectData(messageContext, true, true, dataUnit);
    Assert.assertNotNull("context properties should be inserted", dataUnit.getContextPropertyMap());
    Assert.assertNotNull("transport properties should be inserted", dataUnit.getTransportPropertyMap());
    Assert.assertNotNull("payload should be inserted", dataUnit.getPayload());
}
Also used : StatisticDataUnit(org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StatisticDataUnit (org.apache.synapse.aspects.flow.statistics.data.raw.StatisticDataUnit)12 BasicStatisticDataUnit (org.apache.synapse.aspects.flow.statistics.data.raw.BasicStatisticDataUnit)8 StatisticsLog (org.apache.synapse.aspects.flow.statistics.data.raw.StatisticsLog)2 SpanWrapper (org.apache.synapse.aspects.flow.statistics.opentracing.models.SpanWrapper)2 Span (io.opentracing.Span)1 StatisticsCloseEvent (org.apache.synapse.aspects.flow.statistics.log.templates.StatisticsCloseEvent)1 StatisticsOpenEvent (org.apache.synapse.aspects.flow.statistics.log.templates.StatisticsOpenEvent)1 TracingScope (org.apache.synapse.aspects.flow.statistics.opentracing.management.scoping.TracingScope)1 ContinuationStateSequenceInfo (org.apache.synapse.aspects.flow.statistics.opentracing.models.ContinuationStateSequenceInfo)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1