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);
}
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());
}
}
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());
}
}
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());
}
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));
}
Aggregations