use of org.wso2.carbon.apimgt.tracing.TracingSpan in project carbon-apimgt by wso2.
the class GatewayUtils method setAPIRelatedTags.
public static void setAPIRelatedTags(TracingSpan tracingSpan, org.apache.synapse.MessageContext messageContext) {
API api = GatewayUtils.getAPI(messageContext);
Object electedResource = messageContext.getProperty(APIMgtGatewayConstants.API_ELECTED_RESOURCE);
if (electedResource != null) {
Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_RESOURCE, (String) electedResource);
}
if (api != null) {
Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_API_NAME, api.getApiName());
Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_API_VERSION, api.getApiVersion());
}
Object consumerKey = messageContext.getProperty(APIMgtGatewayConstants.CONSUMER_KEY);
if (consumerKey != null) {
Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_APPLICATION_CONSUMER_KEY, (String) consumerKey);
}
}
use of org.wso2.carbon.apimgt.tracing.TracingSpan in project carbon-apimgt by wso2.
the class APIMgtGoogleAnalyticsTrackingHandler method handleRequest.
@MethodStats
@Override
public boolean handleRequest(MessageContext msgCtx) {
TracingSpan span = null;
TracingTracer tracer = null;
Map<String, String> tracerSpecificCarrier = new HashMap<>();
if (Util.tracingEnabled()) {
TracingSpan responseLatencySpan = (TracingSpan) msgCtx.getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);
tracer = Util.getGlobalTracer();
span = Util.startSpan(APIMgtGatewayConstants.GOOGLE_ANALYTICS_HANDLER, responseLatencySpan, tracer);
}
try {
if (configKey == null) {
throw new SynapseException("Google Analytics configuration unspecified for the API");
}
Entry entry = msgCtx.getConfiguration().getEntryDefinition(configKey);
if (entry == null) {
log.warn("Cannot find Google Analytics configuration using key: " + configKey);
return true;
}
Object entryValue = null;
boolean reCreate = false;
if (entry.isDynamic()) {
if ((!entry.isCached()) || (entry.isExpired()) || config == null) {
entryValue = msgCtx.getEntry(this.configKey);
if (this.version != entry.getVersion()) {
reCreate = true;
}
}
} else if (config == null) {
entryValue = msgCtx.getEntry(this.configKey);
}
if (reCreate || config == null) {
if (entryValue == null || !(entryValue instanceof OMElement)) {
log.warn("Unable to load Google Analytics configuration using key: " + configKey);
return true;
}
version = entry.getVersion();
config = getGoogleAnalyticsConfig((OMElement) entryValue);
}
if (config == null) {
log.warn("Unable to create Google Analytics configuration using key: " + configKey);
return true;
}
if (!config.isEnabled()) {
return true;
}
try {
if (Util.tracingEnabled()) {
Util.inject(span, tracer, tracerSpecificCarrier);
if (org.apache.axis2.context.MessageContext.getCurrentMessageContext() != null) {
Map headers = (Map) org.apache.axis2.context.MessageContext.getCurrentMessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
headers.putAll(tracerSpecificCarrier);
org.apache.axis2.context.MessageContext.getCurrentMessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headers);
}
}
trackPageView(msgCtx);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return true;
} catch (Exception e) {
if (Util.tracingEnabled() && span != null) {
Util.setTag(span, APIMgtGatewayConstants.ERROR, APIMgtGatewayConstants.GOOGLE_ANALYTICS_ERROR);
}
throw e;
} finally {
if (Util.tracingEnabled()) {
Util.finishSpan(span);
}
}
}
use of org.wso2.carbon.apimgt.tracing.TracingSpan in project carbon-apimgt by wso2.
the class APIMgtLatencySynapseHandler method handleResponseInFlow.
@Override
public boolean handleResponseInFlow(MessageContext messageContext) {
if (Util.tracingEnabled() && messageContext.getProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN) != null) {
TracingSpan backendLatencySpan = (TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN);
GatewayUtils.setEndpointRelatedInformation(backendLatencySpan, messageContext);
Util.finishSpan(backendLatencySpan);
}
return true;
}
use of org.wso2.carbon.apimgt.tracing.TracingSpan in project carbon-apimgt by wso2.
the class APIMgtLatencySynapseHandler method handleRequestInFlow.
@Override
public boolean handleRequestInFlow(MessageContext messageContext) {
TracingTracer tracer = ServiceReferenceHolder.getInstance().getTracer();
if (Util.tracingEnabled()) {
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
Map headersMap = (Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
TracingSpan spanContext = Util.extract(tracer, headersMap);
TracingSpan responseLatencySpan = Util.startSpan(APIMgtGatewayConstants.RESPONSE_LATENCY, spanContext, tracer);
Util.setTag(responseLatencySpan, APIMgtGatewayConstants.SPAN_KIND, APIMgtGatewayConstants.SERVER);
GatewayUtils.setRequestRelatedTags(responseLatencySpan, messageContext);
messageContext.setProperty(APIMgtGatewayConstants.RESPONSE_LATENCY, responseLatencySpan);
}
return true;
}
use of org.wso2.carbon.apimgt.tracing.TracingSpan in project carbon-apimgt by wso2.
the class APIMgtLatencySynapseHandler method handleRequestOutFlow.
@Override
public boolean handleRequestOutFlow(MessageContext messageContext) {
TracingTracer tracer = ServiceReferenceHolder.getInstance().getTracer();
Map<String, String> tracerSpecificCarrier = new HashMap<>();
if (Util.tracingEnabled()) {
TracingSpan parentSpan = (TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);
TracingSpan backendLatencySpan = Util.startSpan(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN, parentSpan, tracer);
messageContext.setProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN, backendLatencySpan);
Util.inject(backendLatencySpan, tracer, tracerSpecificCarrier);
if (org.apache.axis2.context.MessageContext.getCurrentMessageContext() != null) {
Map headers = (Map) org.apache.axis2.context.MessageContext.getCurrentMessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
headers.putAll(tracerSpecificCarrier);
org.apache.axis2.context.MessageContext.getCurrentMessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headers);
}
}
return true;
}
Aggregations