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);
}
}
}
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()));
}
}
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
}
}
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;
}
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());
}
Aggregations