org.apache.skywalking.apm.agent.core.context.ContextCarrier Java Examples
The following examples show how to use
org.apache.skywalking.apm.agent.core.context.ContextCarrier.
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: ServerInterceptor.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 { Request request = (Request) allArguments[0]; ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); if (request.getKvAttachment() == null) { request.setKvAttachment(new HashMap<>()); } while (next.hasNext()) { next = next.next(); next.setHeadValue((String) request.getKvAttachment().get(next.getHeadKey())); } AbstractSpan span = ContextManager.createEntrySpan(generateOperationName(request), contextCarrier); SpanLayer.asRPCFramework(span); span.setComponent(ComponentsDefine.BRPC_JAVA); }
Example #2
Source File: TransportClientHandlerInterceptor.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 { Invocation invocation = (Invocation) allArguments[0]; if (!checkRegisterStatus(invocation)) { return; } URI uri = new URI(invocation.getEndpoint().toString()); String peer = uri.getHost() + ":" + uri.getPort(); String operationName = invocation.getMicroserviceQualifiedName(); final ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); invocation.getContext().put(next.getHeadKey(), next.getHeadValue()); } String url = invocation.getOperationMeta().getOperationPath(); Tags.URL.set(span, url); span.setComponent(ComponentsDefine.SERVICECOMB); SpanLayer.asRPCFramework(span); }
Example #3
Source File: SkywalkingTracerInjectInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { Format format = (Format) allArguments[1]; if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) { TextMap carrier = (TextMap) allArguments[2]; ContextCarrier contextCarrier = new ContextCarrier(); ContextManager.inject(contextCarrier); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); carrier.put(next.getHeadKey(), next.getHeadValue()); } } else { //Don't support other format yet. } return null; }
Example #4
Source File: ResinV4Interceptor.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 { CauchoRequest request = (CauchoRequest)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.getPageURI(), contextCarrier); span.setComponent(ComponentsDefine.RESIN); Tags.URL.set(span, appendRequestURL(request)); SpanLayer.asHttp(span); }
Example #5
Source File: SkywalkingTraceFactory.java From joyrpc with Apache License 2.0 | 6 votes |
@Override public void begin(final String name, final String component, final Map<String, String> tags) { Map<String, String> ctx = (Map<String, String>) invocation.removeAttachment(HIDDEN_KEY_TRACE_SKYWALKING); ContextCarrier contextCarrier = new ContextCarrier(); if (ctx != null) { CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); next.setHeadValue(ctx.get(next.getHeadKey())); } } span = ContextManager.createEntrySpan(name, contextCarrier); span.setComponent(new OfficialComponent(componentId, component)); tag(tags); SpanLayer.asRPCFramework(span); }
Example #6
Source File: AbstractMessageConsumeInterceptor.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) throws Throwable { List<MessageExt> msgs = (List<MessageExt>) allArguments[0]; ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0)); AbstractSpan span = ContextManager.createEntrySpan(CONSUMER_OPERATION_NAME_PREFIX + msgs.get(0) .getTopic() + "/Consumer", contextCarrier); span.setComponent(ComponentsDefine.ROCKET_MQ_CONSUMER); SpanLayer.asMQ(span); for (int i = 1; i < msgs.size(); i++) { ContextManager.extract(getContextCarrierFromMessage(msgs.get(i))); } }
Example #7
Source File: ServerInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public <REQUEST, RESPONSE> ServerCall.Listener<REQUEST> interceptCall(ServerCall<REQUEST, RESPONSE> call, Metadata headers, ServerCallHandler<REQUEST, RESPONSE> handler) { final ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); String contextValue = headers.get(Metadata.Key.of(next.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER)); if (!StringUtil.isEmpty(contextValue)) { next.setHeadValue(contextValue); } } final AbstractSpan span = ContextManager.createEntrySpan(OperationNameFormatUtil.formatOperationName(call.getMethodDescriptor()), contextCarrier); span.setComponent(ComponentsDefine.GRPC); span.setLayer(SpanLayer.RPC_FRAMEWORK); try { return new TracingServerCallListener<>(handler.startCall(new TracingServerCall<>(call, ContextManager.capture()), headers), call .getMethodDescriptor(), ContextManager.capture()); } finally { ContextManager.stopSpan(); } }
Example #8
Source File: SkywalkingTracerExtractInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { Format format = (Format) allArguments[0]; if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) { TextMap textMapCarrier = (TextMap) allArguments[1]; ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); Iterator<Map.Entry<String, String>> iterator = textMapCarrier.iterator(); while (iterator.hasNext()) { Map.Entry<String, String> entry = iterator.next(); if (next.getHeadKey().equals(entry.getKey())) { next.setHeadValue(entry.getValue()); break; } } } ContextManager.extract(contextCarrier); } return new SkywalkingContext(); }
Example #9
Source File: HttpClientWriteRequestInterceptor.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 { HttpURLConnection connection = (HttpURLConnection) objInst.getSkyWalkingDynamicField(); MessageHeader headers = (MessageHeader) allArguments[0]; URL url = connection.getURL(); ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(getPath(url), contextCarrier, getPeer(url)); span.setComponent(ComponentsDefine.JDK_HTTP); Tags.HTTP.METHOD.set(span, connection.getRequestMethod()); Tags.URL.set(span, url.toString()); SpanLayer.asHttp(span); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); headers.add(next.getHeadKey(), next.getHeadValue()); } }
Example #10
Source File: SolrConnectorInterceptor.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 { if (ContextManager.isActive()) { HttpRequestBase request = (HttpRequestBase) allArguments[0]; ContextCarrier carrier = new ContextCarrier(); ContextManager.inject(carrier); CarrierItem items = carrier.items(); while (items.hasNext()) { items = items.next(); request.setHeader(items.getHeadKey(), items.getHeadValue()); } } }
Example #11
Source File: ProducerOperationHandlerInterceptor.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 { Invocation invocation = (Invocation) allArguments[0]; ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); next.setHeadValue(invocation.getContext().get(next.getHeadKey())); } String operationName = invocation.getMicroserviceQualifiedName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); String url = invocation.getOperationMeta().getOperationPath(); Tags.URL.set(span, url); span.setComponent(ComponentsDefine.SERVICECOMB); SpanLayer.asRPCFramework(span); }
Example #12
Source File: TomcatInvokeInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
/** * * 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 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) 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); if (Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS) { collectHttpParam(request, span); } }
Example #13
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); objInst.setSkyWalkingDynamicField(contextCarrier); }
Example #14
Source File: RabbitMQConsumerInterceptor.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 { ContextCarrier contextCarrier = new ContextCarrier(); String url = (String) objInst.getSkyWalkingDynamicField(); Envelope envelope = (Envelope) allArguments[1]; AMQP.BasicProperties properties = (AMQP.BasicProperties) allArguments[2]; AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + "Topic/" + envelope.getExchange() + "Queue/" + envelope .getRoutingKey() + CONSUMER_OPERATE_NAME_SUFFIX, null).start(System.currentTimeMillis()); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_TOPIC.set(activeSpan, envelope.getExchange()); Tags.MQ_QUEUE.set(activeSpan, envelope.getRoutingKey()); activeSpan.setComponent(ComponentsDefine.RABBITMQ_CONSUMER); SpanLayer.asMQ(activeSpan); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (properties.getHeaders() != null && properties.getHeaders().get(next.getHeadKey()) != null) { next.setHeadValue(properties.getHeaders().get(next.getHeadKey()).toString()); } } ContextManager.extract(contextCarrier); }
Example #15
Source File: AbstractMessageConsumeInterceptor.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) throws Throwable { List<MessageExt> msgs = (List<MessageExt>) allArguments[0]; ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0)); AbstractSpan span = ContextManager.createEntrySpan(CONSUMER_OPERATION_NAME_PREFIX + msgs.get(0) .getTopic() + "/Consumer", contextCarrier); span.setComponent(ComponentsDefine.ROCKET_MQ_CONSUMER); span.setLayer(SpanLayer.MQ); for (int i = 1; i < msgs.size(); i++) { ContextManager.extract(getContextCarrierFromMessage(msgs.get(i))); } }
Example #16
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 #17
Source File: ClientInterceptor.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 { Request request = (Request) allArguments[0]; InetSocketAddress remoteAddress = (InetSocketAddress) request.getChannel().remoteAddress(); InetAddress address = remoteAddress.getAddress(); final ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(generateOperationName(request), contextCarrier, address.getHostAddress() + ":" + remoteAddress.getPort()); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (request.getKvAttachment() == null) { request.setKvAttachment(new HashMap<>()); } request.getKvAttachment().put(next.getHeadKey(), next.getHeadValue()); } span.setComponent(ComponentsDefine.BRPC_JAVA); SpanLayer.asRPCFramework(span); }
Example #18
Source File: SenderSendInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@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()); } }
Example #19
Source File: ArmeriaClientInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
protected void beforeMethod(final URI uri, final HttpMethod httpMethod, final String path) { 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()); ContextManager.getRuntimeContext().put(KEY_SAFE_CLOSEABLE, Clients.withHttpHeaders(headers -> { HttpHeadersBuilder builder = headers.toBuilder(); for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) { item = item.next(); builder.add(AsciiString.of(item.getHeadKey()), item.getHeadValue()); } return builder.build(); })); }
Example #20
Source File: Armeria085ServerInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, final MethodInterceptResult result) { DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1]; HttpHeaders headers = httpRequest.headers(); ContextCarrier carrier = new ContextCarrier(); for (CarrierItem item = carrier.items(); item.hasNext(); ) { item = item.next(); item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey()))); } AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier); entrySpan.setComponent(ComponentsDefine.ARMERIA); entrySpan.setLayer(SpanLayer.HTTP); entrySpan.setPeer(httpRequest.authority()); Tags.URL.set(entrySpan, httpRequest.path()); Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name()); }
Example #21
Source File: MotanConsumerInterceptor.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 { URL url = (URL) objInst.getSkyWalkingDynamicField(); Request request = (Request) allArguments[0]; if (url != null) { ContextCarrier contextCarrier = new ContextCarrier(); String remotePeer = url.getHost() + ":" + url.getPort(); AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer); span.setComponent(ComponentsDefine.MOTAN); Tags.URL.set(span, url.getIdentity()); SpanLayer.asRPCFramework(span); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); request.setAttachment(next.getHeadKey(), next.getHeadValue()); } } }
Example #22
Source File: SynchronousDispatcherInterceptor.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) allArguments[0]; ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey())); } AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier); Tags.URL.set(span, toPath(request.getUri().getRequestUri().toString())); Tags.HTTP.METHOD.set(span, request.getHttpMethod()); span.setComponent(ComponentsDefine.RESTEASY); SpanLayer.asHttp(span); }
Example #23
Source File: PulsarConsumerInterceptor.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 { if (allArguments[0] != null) { ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); Message msg = (Message) allArguments[0]; ContextCarrier carrier = new ContextCarrier(); CarrierItem next = carrier.items(); while (next.hasNext()) { next = next.next(); next.setHeadValue(msg.getProperty(next.getHeadKey())); } AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopic() + CONSUMER_OPERATE_NAME + requiredInfo .getSubscriptionName(), carrier); activeSpan.setComponent(ComponentsDefine.PULSAR_CONSUMER); SpanLayer.asMQ(activeSpan); Tags.MQ_BROKER.set(activeSpan, requiredInfo.getServiceUrl()); Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopic()); } }
Example #24
Source File: SofaRpcProviderInterceptor.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 { SofaRequest sofaRequest = (SofaRequest) allArguments[0]; AbstractSpan span = null; ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); final String headKey = next.getHeadKey(); final Object attachment = sofaRequest.getRequestProp(SKYWALKING_PREFIX + headKey); if (attachment != null) { next.setHeadValue(attachment.toString()); } else { next.setHeadValue(""); } } span = ContextManager.createEntrySpan(generateViewPoint(sofaRequest), contextCarrier); span.setComponent(ComponentsDefine.SOFARPC); SpanLayer.asRPCFramework(span); }
Example #25
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 #26
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 #27
Source File: HandleInterceptor.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 { HttpChannel httpChannel = (HttpChannel) objInst; 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); }
Example #28
Source File: ContextCarrierHelper.java From skywalking with Apache License 2.0 | 6 votes |
/** * In {@link ClientTracingFilterInterceptor}, we create {@link ExitSpan} without op name and peer information, and * we use {@link AnnotationInterceptor.Rpc} and {@link ClientDestTracingFilterInterceptor} to put op name and * peer information into LocalContext, but the order of these two interceptors are uncertain, so after each * interceptor, we check if the op name and peer information are exists in LocalContext, if it exists, we set it * to span and inject to contextCarrier. */ static void tryInjectContext(AbstractSpan span) { /* * this may be a {@link NoopSpan}. */ if (span != null && span.isExit()) { String operationName = span.getOperationName(); if (PENDING_OP_NAME.equals(operationName)) { return; } String peer = getPeerHost(); if (peer == null) { return; } span.setPeer(peer); ContextCarrier contextCarrier = new ContextCarrier(); ((ExitTypeSpan) span).inject(contextCarrier); SWContextCarrier swContextCarrier = getSWContextCarrier(); // we can ensure swContextCarrier is not null here swContextCarrier.setContextCarrier(contextCarrier); swContextCarrier.setOperationName(operationName); } }
Example #29
Source File: Armeria084ServerInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable { DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1]; HttpHeaders headers = httpRequest.headers(); ContextCarrier carrier = new ContextCarrier(); for (CarrierItem item = carrier.items(); item.hasNext(); ) { item = item.next(); item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey()))); } AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier); entrySpan.setComponent(ComponentsDefine.ARMERIA); entrySpan.setLayer(SpanLayer.HTTP); entrySpan.setPeer(httpRequest.authority()); Tags.URL.set(entrySpan, httpRequest.path()); Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name()); }
Example #30
Source File: ServerTracingFilterInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
private void runWithContext(final TestFunction function) { ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (next.getHeadKey().equals(SW8CarrierItem.HEADER_NAME)) { next.setHeadValue("1-My40LjU=-MS4yLjM=-3-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA="); } } SWContextCarrier swContextCarrier = new SWContextCarrier(); swContextCarrier.setContextCarrier(contextCarrier); swContextCarrier.setOperationName(rpc); Contexts.broadcast().let(SWContextCarrier$.MODULE$, swContextCarrier, new AbstractFunction0<Void>() { @Override public Void apply() { try { function.apply(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } return null; } }); }