Java Code Examples for org.apache.skywalking.apm.agent.core.context.ContextManager#createExitSpan()
The following examples show how to use
org.apache.skywalking.apm.agent.core.context.ContextManager#createExitSpan() .
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: TransportActionNodeProxyExecuteMethodsInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { TransportClientEnhanceInfo enhanceInfo = (TransportClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); ActionRequest request = (ActionRequest) allArguments[1]; String opType = request.getClass().getSimpleName(); String operationName = Constants.DB_TYPE + "/" + opType; AbstractSpan span = ContextManager.createExitSpan(operationName, enhanceInfo.transportAddresses()); span.setComponent(ComponentsDefine.TRANSPORT_CLIENT); Tags.DB_TYPE.set(span, Constants.DB_TYPE); Tags.DB_INSTANCE.set(span, enhanceInfo.getClusterName()); span.tag(Constants.ES_NODE, ((DiscoveryNode) allArguments[0]).getAddress().toString()); parseRequestInfo(request, span); SpanLayer.asDB(span); }
Example 2
Source File: StatementExecuteMethodsInterceptor.java From java-plugin-extensions with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); if (cacheObject != null && cacheObject.getConnectionInfo() != null) { ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); String sql = ""; if (allArguments.length > 0) { sql = (String)allArguments[0]; } Tags.DB_STATEMENT.set(span, sql); span.setComponent(connectInfo.getComponent()); SpanLayer.asDB(span); } }
Example 3
Source File: SyncHttpRequestSendInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { HttpRequest request = (HttpRequest) objInst; ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(request.getURI() .getPath(), contextCarrier, request.getHost() + ":" + request .getPort()); span.setComponent(ComponentsDefine.JETTY_CLIENT); Tags.HTTP.METHOD.set(span, getHttpMethod(request)); Tags.URL.set(span, request.getURI().toString()); SpanLayer.asHttp(span); CarrierItem next = contextCarrier.items(); HttpFields field = request.getHeaders(); while (next.hasNext()) { next = next.next(); field.add(next.getHeadKey(), next.getHeadValue()); } }
Example 4
Source File: RestExecuteInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { final URI requestURL = (URI) allArguments[0]; final HttpMethod httpMethod = (HttpMethod) allArguments[1]; final ContextCarrier contextCarrier = new ContextCarrier(); String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL .getScheme()) ? 443 : 80); String formatURIPath = requestURL.getPath(); AbstractSpan span = ContextManager.createExitSpan(formatURIPath, contextCarrier, remotePeer); span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL .getPath()); Tags.HTTP.METHOD.set(span, httpMethod.toString()); SpanLayer.asHttp(span); Object[] cacheValues = new Object[3]; cacheValues[0] = formatURIPath; cacheValues[1] = contextCarrier; objInst.setSkyWalkingDynamicField(cacheValues); }
Example 5
Source File: PreparedStatementExecuteMethodsInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); if (connectInfo == null) { return; } AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject .getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, cacheObject.getSql()); span.setComponent(connectInfo.getComponent()); if (Config.Plugin.MARIADB.TRACE_SQL_PARAMETERS) { final Object[] parameters = cacheObject.getParameters(); if (parameters != null && parameters.length > 0) { int maxIndex = cacheObject.getMaxIndex(); SQL_PARAMETERS.set(span, getParameterString(parameters, maxIndex)); } } SpanLayer.asDB(span); }
Example 6
Source File: SyncHttpRequestSendInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { HttpRequest request = (HttpRequest) objInst; ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(request.getURI() .getPath(), contextCarrier, request.getHost() + ":" + request .getPort()); span.setComponent(ComponentsDefine.JETTY_CLIENT); Tags.HTTP.METHOD.set(span, getHttpMethod(request)); Tags.URL.set(span, request.getURI().toString()); SpanLayer.asHttp(span); CarrierItem next = contextCarrier.items(); HttpFields field = request.getHeaders(); while (next.hasNext()) { next = next.next(); field.add(next.getHeadKey(), next.getHeadValue()); } }
Example 7
Source File: StatementExecuteMethodsInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); if (connectInfo != null) { AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject .getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); String sql = allArguments.length > 0 ? (String) allArguments[0] : ""; Tags.DB_STATEMENT.set(span, sql); span.setComponent(connectInfo.getComponent()); SpanLayer.asDB(span); } }
Example 8
Source File: MessageSendInterceptor.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 { Message message = (Message) allArguments[2]; ContextCarrier contextCarrier = new ContextCarrier(); String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField()); AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress); span.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER); Tags.MQ_BROKER.set(span, (String) allArguments[0]); Tags.MQ_TOPIC.set(span, message.getTopic()); SpanLayer.asMQ(span); SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) allArguments[3]; StringBuilder properties = new StringBuilder(requestHeader.getProperties()); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (!StringUtil.isEmpty(next.getHeadValue())) { properties.append(next.getHeadKey()); properties.append(NAME_VALUE_SEPARATOR); properties.append(next.getHeadValue()); properties.append(PROPERTY_SEPARATOR); } } requestHeader.setProperties(properties.toString()); if (allArguments[6] != null) { ((EnhancedInstance) allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager .capture())); } }
Example 9
Source File: RealCallInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
/** * Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host, * port, kind, component, url from {@link okhttp3.Request}. Through the reflection of the way, set the http header * of context data into {@link okhttp3.Request#headers}. * * @param result change this result, if you want to truncate the method. */ @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { Request request = (Request) objInst.getSkyWalkingDynamicField(); ContextCarrier contextCarrier = new ContextCarrier(); HttpUrl requestUrl = request.url(); AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri() .getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl .port()); span.setComponent(ComponentsDefine.OKHTTP); Tags.HTTP.METHOD.set(span, request.method()); Tags.URL.set(span, requestUrl.uri().toString()); SpanLayer.asHttp(span); Field headersField = Request.class.getDeclaredField("headers"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL); headersField.setAccessible(true); Headers.Builder headerBuilder = request.headers().newBuilder(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); headerBuilder.add(next.getHeadKey(), next.getHeadValue()); } headersField.set(request, headerBuilder.build()); }
Example 10
Source File: Armeria084ClientInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable { final UserClient userClient = (UserClient) objInst; final URI uri = userClient.uri(); final HttpMethod httpMethod = (HttpMethod) allArguments[1]; final String path = (String) allArguments[2]; final Object req = allArguments[5]; if (!(req instanceof HttpRequest)) { return; } final HttpRequest httpReq = (HttpRequest) req; final ContextCarrier contextCarrier = new ContextCarrier(); final String remotePeer = uri.getHost() + ":" + uri.getPort(); final AbstractSpan exitSpan = ContextManager.createExitSpan(path, contextCarrier, remotePeer); exitSpan.setComponent(ComponentsDefine.ARMERIA); exitSpan.setLayer(SpanLayer.HTTP); Tags.HTTP.METHOD.set(exitSpan, httpMethod.name()); HttpHeaders headers = httpReq.headers(); for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) { item = item.next(); headers.add(AsciiString.of(item.getHeadKey()), item.getHeadValue()); } }
Example 11
Source File: PreparedStatementExecuteMethodsInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); /** * For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor, * before the interceptor sets the connectionInfo. * * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) */ if (connectInfo != null) { AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject .getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, cacheObject.getSql()); span.setComponent(connectInfo.getComponent()); if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { final Object[] parameters = cacheObject.getParameters(); if (parameters != null && parameters.length > 0) { int maxIndex = cacheObject.getMaxIndex(); String parameterString = getParameterString(parameters, maxIndex); SQL_PARAMETERS.set(span, parameterString); } } SpanLayer.asDB(span); } }
Example 12
Source File: ConnectionServiceMethodInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { ConnectionInfo connectInfo = (ConnectionInfo) objInst.getSkyWalkingDynamicField(); if (connectInfo != null) { AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), connectInfo .getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, ""); span.setComponent(connectInfo.getComponent()); SpanLayer.asDB(span); } }
Example 13
Source File: HttpClientExecuteInterceptor.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 (allArguments[0] == null || allArguments[1] == null) { // illegal args, can't trace. ignore. return; } final HttpHost httpHost = (HttpHost) allArguments[0]; HttpRequest httpRequest = (HttpRequest) allArguments[1]; final ContextCarrier contextCarrier = new ContextCarrier(); String remotePeer = httpHost.getHostName() + ":" + port(httpHost); String uri = httpRequest.getRequestLine().getUri(); String requestURI = getRequestURI(uri); String operationName = requestURI; AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer); span.setComponent(ComponentsDefine.HTTPCLIENT); Tags.URL.set(span, buildSpanValue(httpHost, uri)); Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod()); SpanLayer.asHttp(span); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); httpRequest.setHeader(next.getHeadKey(), next.getHeadValue()); } }
Example 14
Source File: AsyncCallInterceptor.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 { EnhanceRequiredInfo enhanceRequiredInfo = (EnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); Request request = (Request) enhanceRequiredInfo.getRealCallEnhance().getSkyWalkingDynamicField(); HttpUrl requestUrl = request.url(); AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri() .getPath(), requestUrl.host() + ":" + requestUrl.port()); ContextManager.continued(enhanceRequiredInfo.getContextSnapshot()); ContextCarrier contextCarrier = new ContextCarrier(); ContextManager.inject(contextCarrier); span.setComponent(ComponentsDefine.OKHTTP); Tags.HTTP.METHOD.set(span, request.method()); Tags.URL.set(span, requestUrl.uri().toString()); SpanLayer.asHttp(span); Field headersField = Request.class.getDeclaredField("headers"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL); headersField.setAccessible(true); Headers.Builder headerBuilder = request.headers().newBuilder(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); headerBuilder.add(next.getHeadKey(), next.getHeadValue()); } headersField.set(request, headerBuilder.build()); }
Example 15
Source File: XMemcachedMethodInterceptor.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 { String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); AbstractSpan span = ContextManager.createExitSpan(XMEMCACHED + method.getName(), peer); span.setComponent(ComponentsDefine.XMEMCACHED); Tags.DB_TYPE.set(span, ComponentsDefine.XMEMCACHED.getName()); SpanLayer.asCache(span); Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]); }
Example 16
Source File: MongoDBCollectionMethodInterceptor.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 { String remotePeer = (String) objInst.getSkyWalkingDynamicField(); String operation = method.getName(); AbstractSpan span = ContextManager.createExitSpan(MONGO_DB_OP_PREFIX + operation, new ContextCarrier(), remotePeer); span.setComponent(ComponentsDefine.MONGO_DRIVER); Tags.DB_TYPE.set(span, DB_TYPE); SpanLayer.asDB(span); }
Example 17
Source File: ExecuteEventListener.java From skywalking with Apache License 2.0 | 5 votes |
private void handle(AbstractExecutionEvent event, String operation) { switch (event.getEventExecutionType()) { case BEFORE_EXECUTE: AbstractSpan span = ContextManager.createExitSpan("/SJDBC/BRANCH/" + operation, event.getDataSource()); if (ExecutorDataMap.getDataMap().containsKey(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)) { ContextManager.continued((ContextSnapshot) ExecutorDataMap.getDataMap() .get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)); } Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, event.getDataSource()); Tags.DB_STATEMENT.set(span, event.getSql()); if (!event.getParameters().isEmpty()) { String variables = event.getParameters() .stream() .map(String::valueOf) .collect(Collectors.joining(",")); Tags.DB_BIND_VARIABLES.set(span, variables); } span.setComponent(ComponentsDefine.SHARDING_JDBC); SpanLayer.asDB(span); break; case EXECUTE_FAILURE: span = ContextManager.activeSpan(); span.errorOccurred(); if (event.getException().isPresent()) { span.log(event.getException().get()); } case EXECUTE_SUCCESS: ContextManager.stopSpan(); } }
Example 18
Source File: HttpClientRequestInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable { AbstractSpan span = ContextManager.activeSpan(); URL url = new URL((String) allArguments[1]); ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan abstractSpan = ContextManager.createExitSpan( "SpringCloudGateway/sendRequest", contextCarrier, getPeer(url)); abstractSpan.prepareForAsync(); Tags.URL.set(abstractSpan, String.valueOf(allArguments[1])); abstractSpan.setComponent(SPRING_CLOUD_GATEWAY); ContextManager.stopSpan(abstractSpan); Function<? super HttpClientRequest, ? extends Publisher<Void>> handler = (Function<? super HttpClientRequest, ? extends Publisher<Void>>) allArguments[2]; allArguments[2] = new Function<HttpClientRequest, Publisher<Void>>() { @Override public Publisher<Void> apply(final HttpClientRequest httpClientRequest) { // CarrierItem next = contextCarrier.items(); if (httpClientRequest instanceof EnhancedInstance) { ((EnhancedInstance) httpClientRequest).setSkyWalkingDynamicField(next); } return handler.apply(httpClientRequest); } }; objInst.setSkyWalkingDynamicField(new EnhanceCacheObject(span, abstractSpan)); }
Example 19
Source File: ClusterClientHealthMethodsInterceptor.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 { RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); if (restClientEnhanceInfo != null) { AbstractSpan span = ContextManager.createExitSpan(Constants.CLUSTER_HEALTH_NAME, restClientEnhanceInfo.getPeers()); span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT); Tags.DB_TYPE.set(span, DB_TYPE); SpanLayer.asDB(span); } }
Example 20
Source File: SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { ConnectionInfo connectionInfo = (ConnectionInfo) objInst.getSkyWalkingDynamicField(); if (connectionInfo == null) { return; } Statement statement = (Statement) allArguments[0]; String remotePeer = statement.getHost() == null ? connectionInfo.getContactPoints() : (statement.getHost() .getSocketAddress() .getHostName() + ":" + statement .getHost() .getSocketAddress() .getPort()); String keyspace = statement.getKeyspace() == null ? connectionInfo.getKeyspace() : statement.getKeyspace(); String query = statement.toString(); if (statement instanceof BoundStatement) { query = ((BoundStatement) statement).preparedStatement().getQueryString(); } AbstractSpan span = ContextManager.createExitSpan(Constants.CASSANDRA_OP_PREFIX + method.getName(), remotePeer); span.setComponent(ComponentsDefine.CASSANDRA_JAVA_DRIVER); Tags.DB_TYPE.set(span, Constants.CASSANDRA_DB_TYPE); Tags.DB_INSTANCE.set(span, keyspace); Tags.DB_STATEMENT.set(span, query); SpanLayer.asDB(span); }