use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.
the class CallServerInterceptor method interceptCall.
@Override
public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, ServerCallHandler handler) {
Map<String, String> headerMap = new HashMap<String, String>();
for (String key : headers.keys()) {
if (!key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
String value = headers.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER));
headerMap.put(key, value);
}
}
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
String contextValue = headerMap.get(next.getHeadKey());
if (!StringUtil.isEmpty(contextValue)) {
next.setHeadValue(contextValue);
}
}
final AbstractSpan span = ContextManager.createEntrySpan(OperationNameFormatUtil.formatOperationName(call.getMethodDescriptor()), contextCarrier);
span.setComponent(ComponentsDefine.GRPC);
return new ServerCallListener(handler.startCall(new ForwardingServerCall.SimpleForwardingServerCall(call) {
@Override
public void sendHeaders(Metadata responseHeaders) {
delegate().sendHeaders(responseHeaders);
}
}, headers), call.getMethodDescriptor());
}
use of org.apache.skywalking.apm.agent.core.context.ContextCarrier in project incubator-skywalking by apache.
the class StateInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
if (null == allArguments[0]) {
return;
}
HttpRequestWrapper httpRequest = (HttpRequestWrapper) allArguments[0];
String uri = httpRequest.getOriginal().getRequestLine().getUri();
AbstractSpan span = null;
final ContextCarrier contextCarrier = new ContextCarrier();
try {
URL url = new URL(httpRequest.getOriginal().getRequestLine().getUri());
String remotePeer = url.getHost() + ":" + url.getPort();
span = ContextManager.createExitSpan(url.getPath(), contextCarrier, remotePeer);
} catch (MalformedURLException e) {
throw e;
}
span.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT);
Tags.URL.set(span, uri);
Tags.HTTP.METHOD.set(span, httpRequest.getOriginal().getRequestLine().getMethod());
SpanLayer.asHttp(span);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
httpRequest.setHeader(next.getHeadKey(), next.getHeadValue());
}
}
Aggregations