Java Code Examples for org.apache.skywalking.apm.agent.core.context.ContextManager#activeSpan()
The following examples show how to use
org.apache.skywalking.apm.agent.core.context.ContextManager#activeSpan() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpClientExecuteInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, final Object ret) { if (ret != null) { final int statusCode = (Integer) ret; final AbstractSpan span = ContextManager.activeSpan(); if (statusCode >= 400) { span.errorOccurred(); Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); } } ContextManager.stopSpan(); return ret; }
Example 2
Source File: SolrClientInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { if (!ContextManager.isActive()) { return ret; } AbstractSpan span = ContextManager.activeSpan(); if (ret != null) { NamedList<Object> result = (NamedList<Object>) ret; NamedList<Object> header = (NamedList<Object>) result.get("responseHeader"); if (header != null) { span.tag(SolrjTags.TAG_Q_TIME, String.valueOf(header.get("QTime"))); } SolrDocumentList list = (SolrDocumentList) result.get("response"); if (list != null) { span.tag(SolrjTags.TAG_NUM_FOUND, String.valueOf(list.getNumFound())); } } ContextManager.stopSpan(); return ret; }
Example 3
Source File: TomcatInvokeInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { Request request = (Request) allArguments[0]; HttpServletResponse response = (HttpServletResponse) allArguments[1]; AbstractSpan span = ContextManager.activeSpan(); if (IS_SERVLET_GET_STATUS_METHOD_EXIST && response.getStatus() >= 400) { span.errorOccurred(); Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); } // Active HTTP parameter collection automatically in the profiling context. if (!Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS && span.isProfiling()) { collectHttpParam(request, span); } ContextManager.stopSpan(); ContextManager.getRuntimeContext().remove(Constants.FORWARD_REQUEST_FLAG); return ret; }
Example 4
Source File: DefaultHttpClientInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
/** * Get the status code from {@link Response}, when status code greater than 400, it means there was some errors in * the server. Finish the {@link AbstractSpan}. * * @param method intercept method * @param ret the method's original return value. * @return origin ret */ @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) { Response response = (Response) ret; if (response != null) { int statusCode = response.status(); AbstractSpan span = ContextManager.activeSpan(); if (statusCode >= 400) { span.errorOccurred(); Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); } } ContextManager.stopSpan(); return ret; }
Example 5
Source File: SenderSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, Object ret) throws Throwable { Response response = (Response) ret; int statusCode = response.getStatus(); AbstractSpan span = ContextManager.activeSpan(); if (statusCode >= 400) { span.errorOccurred(); Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); } ContextManager.stopSpan(); return ret; }
Example 6
Source File: RedisChannelWriterInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred(); span.log(t); }
Example 7
Source File: FiberInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred(); span.log(t); }
Example 8
Source File: MessageOrderlyConsumeInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { ConsumeOrderlyStatus status = (ConsumeOrderlyStatus) ret; if (status == ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT) { AbstractSpan activeSpan = ContextManager.activeSpan(); activeSpan.errorOccurred(); Tags.STATUS_CODE.set(activeSpan, status.name()); } ContextManager.stopSpan(); return ret; }
Example 9
Source File: TransportClientHandlerInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { Invocation invocation = (Invocation) allArguments[0]; if (!checkRegisterStatus(invocation)) { return; } AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred(); span.log(t); }
Example 10
Source File: ForwardInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { if (ContextManager.isActive()) { AbstractSpan abstractTracingSpan = ContextManager.activeSpan(); Map<String, String> eventMap = new HashMap<String, String>(); eventMap.put("forward-url", objInst.getSkyWalkingDynamicField() == null ? "" : String.valueOf(objInst.getSkyWalkingDynamicField())); abstractTracingSpan.log(System.currentTimeMillis(), eventMap); ContextManager.getRuntimeContext().put(Constants.FORWARD_REQUEST_FLAG, true); } }
Example 11
Source File: RealCallInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan.errorOccurred(); abstractSpan.log(t); }
Example 12
Source File: ForwardInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { if (ContextManager.isActive()) { AbstractSpan abstractTracingSpan = ContextManager.activeSpan(); Map<String, String> eventMap = new HashMap<String, String>(); eventMap.put("forward-url", objInst.getSkyWalkingDynamicField() == null ? "" : String.valueOf(objInst.getSkyWalkingDynamicField())); abstractTracingSpan.log(System.currentTimeMillis(), eventMap); ContextManager.getRuntimeContext().put(Constants.FORWARD_REQUEST_FLAG, true); } }
Example 13
Source File: ServerInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { AbstractSpan activeSpan = ContextManager.activeSpan(); activeSpan.errorOccurred(); activeSpan.log(t); }
Example 14
Source File: AdapterActionFutureActionGetMethodsInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { if (!isTrace(objInst)) { return ret; } AbstractSpan span = ContextManager.activeSpan(); parseResponseInfo((ActionResponse) ret, span); ContextManager.stopSpan(); return ret; }
Example 15
Source File: ForwardInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { if (ContextManager.isActive()) { AbstractSpan abstractTracingSpan = ContextManager.activeSpan(); Map<String, String> eventMap = new HashMap<String, String>(); eventMap.put("forward-url", (String) objInst.getSkyWalkingDynamicField()); abstractTracingSpan.log(System.currentTimeMillis(), eventMap); ContextManager.getRuntimeContext().put(Constants.FORWARD_REQUEST_FLAG, true); } }
Example 16
Source File: HttpClientFinalizerSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { EnhanceObjectCache enhanceObjectCache = (EnhanceObjectCache) objInst.getSkyWalkingDynamicField(); AbstractSpan span = ContextManager.activeSpan(); span.prepareForAsync(); if (!StringUtil.isEmpty(enhanceObjectCache.getUrl())) { URL url = new URL(enhanceObjectCache.getUrl()); ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan abstractSpan = ContextManager.createExitSpan( "SpringCloudGateway/sendRequest", contextCarrier, getPeer(url)); Tags.URL.set(abstractSpan, enhanceObjectCache.getUrl()); abstractSpan.prepareForAsync(); abstractSpan.setComponent(SPRING_CLOUD_GATEWAY); ContextManager.stopSpan(abstractSpan); ContextManager.stopSpan(span); BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>> finalSender = (BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>>) allArguments[0]; allArguments[0] = new BiFunction<HttpClientRequest, NettyOutbound, Publisher<Void>>() { @Override public Publisher<Void> apply(HttpClientRequest request, NettyOutbound outbound) { Publisher publisher = finalSender.apply(request, outbound); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); request.requestHeaders().remove(next.getHeadKey()); request.requestHeaders().set(next.getHeadKey(), next.getHeadValue()); } return publisher; } }; enhanceObjectCache.setCacheSpan(abstractSpan); } enhanceObjectCache.setSpan1(span); }
Example 17
Source File: DubboInterceptor.java From skywalking with Apache License 2.0 | 4 votes |
/** * Log the throwable, which occurs in Dubbo RPC service. */ private void dealException(Throwable throwable) { AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred(); span.log(throwable); }
Example 18
Source File: SofaRpcProviderInterceptor.java From skywalking with Apache License 2.0 | 4 votes |
/** * Log the throwable, which occurs in Dubbo RPC service. */ private void dealException(Throwable throwable) { AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred(); span.log(throwable); }
Example 19
Source File: HttpClientParseHttpInterceptor.java From skywalking with Apache License 2.0 | 4 votes |
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred().log(t); }
Example 20
Source File: AbstractMethodInterceptor.java From skywalking with Apache License 2.0 | 4 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { Boolean forwardRequestFlag = (Boolean) ContextManager.getRuntimeContext().get(FORWARD_REQUEST_FLAG); /** * Spring MVC plugin do nothing if current request is forward request. * Ref: https://github.com/apache/skywalking/pull/1325 */ if (forwardRequestFlag != null && forwardRequestFlag) { return ret; } HttpServletRequest request = (HttpServletRequest) ContextManager.getRuntimeContext() .get(REQUEST_KEY_IN_RUNTIME_CONTEXT); if (request != null) { StackDepth stackDepth = (StackDepth) ContextManager.getRuntimeContext().get(CONTROLLER_METHOD_STACK_DEPTH); if (stackDepth == null) { throw new IllegalMethodStackDepthException(); } else { stackDepth.decrement(); } AbstractSpan span = ContextManager.activeSpan(); if (stackDepth.depth() == 0) { HttpServletResponse response = (HttpServletResponse) ContextManager.getRuntimeContext() .get(RESPONSE_KEY_IN_RUNTIME_CONTEXT); if (response == null) { throw new ServletResponseNotFoundException(); } if (IS_SERVLET_GET_STATUS_METHOD_EXIST && response.getStatus() >= 400) { span.errorOccurred(); Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); } ContextManager.getRuntimeContext().remove(REQUEST_KEY_IN_RUNTIME_CONTEXT); ContextManager.getRuntimeContext().remove(RESPONSE_KEY_IN_RUNTIME_CONTEXT); ContextManager.getRuntimeContext().remove(CONTROLLER_METHOD_STACK_DEPTH); } // Active HTTP parameter collection automatically in the profiling context. if (!Config.Plugin.SpringMVC.COLLECT_HTTP_PARAMS && span.isProfiling()) { collectHttpParam(request, span); } ContextManager.stopSpan(); } return ret; }