org.apache.skywalking.apm.agent.core.context.CarrierItem Java Examples
The following examples show how to use
org.apache.skywalking.apm.agent.core.context.CarrierItem.
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: 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 #2
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 #3
Source File: SWServerRPCPlugin.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void serverReceiveRequest(RPCContext context) { Map meta = context.requestCallMeta(); ContextCarrier carrier = new ContextCarrier(); CarrierItem items = carrier.items(); while (items.hasNext()) { items = items.next(); ByteBuffer buffer = (ByteBuffer) meta.get(new Utf8(items.getHeadKey())); items.setHeadValue(new String(buffer.array())); } String operationName = prefix + context.getMessage().getName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, carrier); SpanLayer.asRPCFramework(span); span.setComponent(ComponentsDefine.AVRO_SERVER); }
Example #4
Source File: HttpClientRequestImplInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) { HttpClientRequestContext requestContext = (HttpClientRequestContext) objInst.getSkyWalkingDynamicField(); if (!requestContext.sent) { HttpClientRequest request = (HttpClientRequest) objInst; ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(toPath(request.uri()), contextCarrier, requestContext.remotePeer); span.setComponent(ComponentsDefine.VERTX); SpanLayer.asHttp(span); Tags.HTTP.METHOD.set(span, request.method().toString()); Tags.URL.set(span, request.uri()); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); request.headers().add(next.getHeadKey(), next.getHeadValue()); } requestContext.vertxContext = new VertxContext(ContextManager.capture(), span.prepareForAsync()); } }
Example #5
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 #6
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 #7
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 #8
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 #9
Source File: HttpclientRequestHeadersInterceptor.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 { CarrierItem next = (CarrierItem) objInst.getSkyWalkingDynamicField(); if (next != null) { HttpHeaders headers = (HttpHeaders) allArguments[0]; while (next.hasNext()) { next = next.next(); headers.remove(next.getHeadKey()); headers.set(next.getHeadKey(), next.getHeadValue()); } } }
Example #10
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 #11
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 #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: Struts2Interceptor.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 { HttpServletRequest request = ServletActionContext.getRequest(); 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.STRUTS2); SpanLayer.asHttp(span); }
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #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: 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 #27
Source File: CodecUtils.java From skywalking with Apache License 2.0 | 6 votes |
/** * Encodes the swContextCarrier to byte array. * * SWContextCarrier consists of some strings, such as operation name, {@link CarrierItem#getHeadKey()}, * {@link CarrierItem#getHeadValue()}. We encode each string to byte array by * {@link #encodeStringToBytes(String)}, then assemble these byte arrays in a certain order, each byte array has * a fixed length of 4 bytes before it to record the length. The format as follow: * * |length of following byte array,4 byte|byte array|length of following byte array,4 byte|byte array|... * * The first byte array is operation name, followed by byte array of the key of first {@code CarrierItem}, * followed by byte array of the value of first {@code CarrierItem}, followed by byte array of second {@code * CarrierItem}, and so on. * * @param swContextCarrier the swContextCarrier to encode * @return */ static Buf encode(SWContextCarrier swContextCarrier) { if (StringUtil.isNotEmpty(swContextCarrier.getOperationName()) && swContextCarrier.getCarrier() != null) { ByteArrayOutputStream bos = getBos(); try (DataOutputStream dos = new DataOutputStream(bos)) { putString(dos, swContextCarrier.getOperationName()); CarrierItem next = swContextCarrier.getCarrier().items(); while (next.hasNext()) { next = next.next(); if (next.getHeadKey() != null && next.getHeadValue() != null) { putString(dos, next.getHeadKey()); putString(dos, next.getHeadValue()); } } bos.flush(); return Bufs.ownedBuf(bos.toByteArray()); } catch (Exception e) { LOGGER.error("encode swContextCarrier exception.", e); } } return Bufs.EMPTY; }
Example #28
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 #29
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; } }); }
Example #30
Source File: CodecUtilsTest.java From skywalking with Apache License 2.0 | 6 votes |
private void assertSwContextCarrier(SWContextCarrier expected, SWContextCarrier actual) { assertThat(expected.getOperationName(), is(actual.getOperationName())); Map<String, String> data = new HashMap<>(); if (actual.getCarrier() == null) { assertNull(expected.getCarrier()); } else { CarrierItem next = expected.getCarrier().items(); while (next.hasNext()) { next = next.next(); data.put(next.getHeadKey(), next.getHeadValue()); } next = actual.getCarrier().items(); while (next.hasNext()) { next = next.next(); assertThat(next.getHeadValue(), is(data.get(next.getHeadKey()))); } } }