Search in sources :

Example 36 with ContextCarrier

use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.

the class MongoDBCollectionMethodInterceptor method beforeMethod.

@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.MONGODB);
    Tags.DB_TYPE.set(span, DB_TYPE);
    SpanLayer.asDB(span);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 37 with ContextCarrier

use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.

the class SyncHttpRequestSendInterceptor method beforeMethod.

@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());
    }
}
Also used : HttpRequest(org.eclipse.jetty.client.HttpRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) HttpFields(org.eclipse.jetty.http.HttpFields) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 38 with ContextCarrier

use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.

the class SenderSendInterceptor method beforeMethod.

@Override
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable {
    Request req = (Request) objInst.getSkyWalkingDynamicField();
    final URI requestURL = req.getUrl().toURI();
    final METHOD httpMethod = req.getMethod();
    final ContextCarrier contextCarrier = new ContextCarrier();
    String remotePeer = requestURL.getHost() + ":" + requestURL.getPort();
    AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer);
    span.setComponent(ComponentsDefine.NUTZ_HTTP);
    Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath());
    Tags.HTTP.METHOD.set(span, httpMethod.toString());
    SpanLayer.asHttp(span);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        req.getHeader().set(next.getHeadKey(), next.getHeadValue());
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Request(org.nutz.http.Request) METHOD(org.nutz.http.Request.METHOD) URI(java.net.URI) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 39 with ContextCarrier

use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.

the class AsyncCallInterceptor method beforeMethod.

@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());
}
Also used : Field(java.lang.reflect.Field) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Headers(okhttp3.Headers) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 40 with ContextCarrier

use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.

the class DefaultHttpClientInterceptor method beforeMethod.

/**
 * Get the {@link feign.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host, port,
 * kind, component, url from {@link feign.Request}. Through the reflection of the way, set the http header of
 * context data into {@link feign.Request#headers}.
 *
 * @param method
 * @param result change this result, if you want to truncate the method.
 * @throws Throwable
 */
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Request request = (Request) allArguments[0];
    URL url = new URL(request.url());
    ContextCarrier contextCarrier = new ContextCarrier();
    int port = url.getPort() == -1 ? 80 : url.getPort();
    String remotePeer = url.getHost() + ":" + port;
    String operationName = url.getPath();
    if (operationName == null || operationName.length() == 0) {
        operationName = "/";
    }
    AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);
    span.setComponent(ComponentsDefine.FEIGN);
    Tags.HTTP.METHOD.set(span, request.method());
    Tags.URL.set(span, request.url());
    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);
    Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        List<String> contextCollection = new LinkedList<String>();
        contextCollection.add(next.getHeadValue());
        headers.put(next.getHeadKey(), contextCollection);
    }
    headers.putAll(request.headers());
    headersField.set(request, Collections.unmodifiableMap(headers));
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Request(feign.Request) URL(java.net.URL) LinkedList(java.util.LinkedList) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan) LinkedHashMap(java.util.LinkedHashMap) Field(java.lang.reflect.Field) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Collection(java.util.Collection)

Aggregations

ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)42 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)36 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)35 URI (java.net.URI)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Metadata (io.grpc.Metadata)3 Field (java.lang.reflect.Field)3 URL (java.net.URL)3 List (java.util.List)3 EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)3 Request (com.weibo.api.motan.rpc.Request)2 ForwardingClientCallListener (io.grpc.ForwardingClientCallListener)2 Format (io.opentracing.propagation.Format)2 TextMap (io.opentracing.propagation.TextMap)2 Invocation (io.servicecomb.core.Invocation)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 Headers (okhttp3.Headers)2 HttpUrl (okhttp3.HttpUrl)2 Request (okhttp3.Request)2