Search in sources :

Example 21 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 22 with ContextCarrier

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

the class HandleInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    HttpChannel httpChannel = (HttpChannel) allArguments[0];
    HttpServletRequest servletRequest = httpChannel.getRequest();
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(servletRequest.getHeader(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier);
    Tags.URL.set(span, servletRequest.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, servletRequest.getMethod());
    span.setComponent(ComponentsDefine.JETTY_SERVER);
    SpanLayer.asHttp(span);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) HttpChannel(org.eclipse.jetty.server.HttpChannel) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 23 with ContextCarrier

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

the class KafkaConsumerInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    Map<TopicPartition, List<ConsumerRecord<?, ?>>> records = (Map<TopicPartition, List<ConsumerRecord<?, ?>>>) ret;
    // 
    if (records.size() > 0) {
        ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField();
        AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopics() + CONSUMER_OPERATE_NAME_SUFFIX, null).start(requiredInfo.getStartTime());
        activeSpan.setComponent(ComponentsDefine.KAFKA);
        SpanLayer.asMQ(activeSpan);
        Tags.MQ_BROKER.set(activeSpan, requiredInfo.getBrokerServers());
        Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopics());
        for (List<ConsumerRecord<?, ?>> consumerRecords : records.values()) {
            for (ConsumerRecord<?, ?> record : consumerRecords) {
                ContextCarrier contextCarrier = new ContextCarrier();
                CarrierItem next = contextCarrier.items();
                while (next.hasNext()) {
                    next = next.next();
                    Iterator<Header> iterator = record.headers().headers(next.getHeadKey()).iterator();
                    if (iterator.hasNext()) {
                        next.setHeadValue(new String(iterator.next().value()));
                    }
                }
                ContextManager.extract(contextCarrier);
            }
        }
        ContextManager.stopSpan();
    }
    return ret;
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Header(org.apache.kafka.common.header.Header) TopicPartition(org.apache.kafka.common.TopicPartition) List(java.util.List) Map(java.util.Map)

Example 24 with ContextCarrier

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

the class TomcatInvokeInterceptor method beforeMethod.

/**
 * * The {@link TraceSegment#refs} of current trace segment will reference to the
 * trace segment id of the previous level if the serialized context is not null.
 *
 * @param objInst
 * @param method
 * @param allArguments
 * @param argumentsTypes
 * @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 {
    HttpServletRequest request = (HttpServletRequest) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier);
    Tags.URL.set(span, request.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, request.getMethod());
    span.setComponent(ComponentsDefine.TOMCAT);
    SpanLayer.asHttp(span);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 25 with ContextCarrier

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

the class RestExecuteInterceptor method beforeMethod.

@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);
    AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), 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] = requestURL;
    cacheValues[1] = contextCarrier;
    objInst.setSkyWalkingDynamicField(cacheValues);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

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