io.opentracing.propagation.Format.Builtin Java Examples

The following examples show how to use io.opentracing.propagation.Format.Builtin. 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: Client.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
public void send() throws InterruptedException {
  Message message = new Message();

  Span span =
      tracer
          .buildSpan("send")
          .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
          .withTag(Tags.COMPONENT.getKey(), "example-client")
          .start();
  try (Scope scope = tracer.activateSpan(span)) {
    tracer.inject(span.context(), Builtin.TEXT_MAP_INJECT, new TextMapInjectAdapter(message));
    queue.put(message);
  } finally {
    span.finish();
  }
}
 
Example #2
Source File: OpenTracingTracingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private WebClient withTrace(final WebClient client, final JaegerSpanContext spanContext) {
    tracer.inject(spanContext, Builtin.HTTP_HEADERS, new TextMap() {

        @Override
        public void put(String key, String value) {
            client.header(key, value);
        }

        @Override
        public Iterator<Entry<String, String>> iterator() {
            return null;
        }
    });

    return client;
}
 
Example #3
Source File: Server.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Bean
Tracer tracer() {
    return new Configuration("camel-server")
        .withSampler(
            new SamplerConfiguration()
                .withType(ConstSampler.TYPE)
                .withParam(1))
        .withReporter(new ReporterConfiguration().withSender(
            new SenderConfiguration()
                .withEndpoint("http://localhost:14268/api/traces")
        ))
        .withCodec(
            new CodecConfiguration()
                .withCodec(Builtin.TEXT_MAP, new TextMapCodec(true))
        )
        .getTracer();
}
 
Example #4
Source File: PulsarClientAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void internalSendAsyncEnter(final Object thiz, final Object arg) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final MessageImpl<?> message = (MessageImpl<?>)arg;
  final Producer<?> producer = (Producer<?>)thiz;

  final Tracer tracer = GlobalTracer.get();
  final Span span = tracer
    .buildSpan("send")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_PRODUCER)
    .withTag(Tags.MESSAGE_BUS_DESTINATION, producer.getTopic())
    .withTag(Tags.PEER_SERVICE, "pulsar")
    .start();

  message.getProperties();

  tracer.inject(span.context(), Builtin.TEXT_MAP, new PropertiesMapInjectAdapter(message.getMessageBuilder()));

  final Scope scope = tracer.activateSpan(span);
  LocalSpanContext.set(COMPONENT_NAME, span, scope);
}
 
Example #5
Source File: PulsarClientAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static void buildConsumerSpan(final Consumer<?> consumer, final Message<?> message) {
  final Tracer tracer = GlobalTracer.get();
  final SpanContext parentContext = tracer.extract(Builtin.TEXT_MAP, new TextMapAdapter(message.getProperties()));

  final SpanBuilder spanBuilder = tracer
    .buildSpan("receive")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER)
    .withTag("topic", consumer.getTopic())
    .withTag("subscription", consumer.getSubscription())
    .withTag(Tags.PEER_SERVICE, "pulsar");

  if (parentContext != null)
    spanBuilder.addReference(References.FOLLOWS_FROM, parentContext);

  spanBuilder.start().finish();
}
 
Example #6
Source File: AkkaAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static Object requestStart(final Object arg0) {
  if (LocalSpanContext.get(COMPONENT_NAME_CLIENT) != null) {
    LocalSpanContext.get(COMPONENT_NAME_CLIENT).increment();
    return arg0;
  }

  final HttpRequest request = (HttpRequest)arg0;
  final Tracer tracer = GlobalTracer.get();
  final Span span = tracer
    .buildSpan(request.method().value())
    .withTag(Tags.COMPONENT, COMPONENT_NAME_CLIENT)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CLIENT)
    .withTag(Tags.HTTP_METHOD, request.method().value())
    .withTag(Tags.HTTP_URL, request.getUri().toString())
    .withTag(Tags.PEER_HOSTNAME, request.getUri().host().address())
    .withTag(Tags.PEER_PORT, request.getUri().port())
    .start();

  final HttpHeadersInjectAdapter injectAdapter = new HttpHeadersInjectAdapter(request);
  tracer.inject(span.context(), Builtin.HTTP_HEADERS, injectAdapter);

  LocalSpanContext.set(COMPONENT_NAME_CLIENT, span, tracer.activateSpan(span));

  return injectAdapter.getHttpRequest();
}
 
Example #7
Source File: PlayAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void applyStart(final Object arg0) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final Request<?> request = (Request<?>)arg0;
  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder spanBuilder = tracer.buildSpan(request.method())
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER)
    .withTag(Tags.HTTP_METHOD, request.method())
    .withTag(Tags.HTTP_URL, (request.secure() ? "https://" : "http://") + request.host() + request.uri());

  final SpanContext parent = tracer.extract(Builtin.HTTP_HEADERS, new HttpHeadersExtractAdapter(request.headers()));
  if (parent != null)
    spanBuilder.asChildOf(parent);

  final Span span = spanBuilder.start();
  LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span));
}
 
Example #8
Source File: ThriftProtocolAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void writeFieldStop(final Object protocol) throws TException {
  if (injected.get())
    return;

  final TProtocol tProtocol = (TProtocol)protocol;
  final Span span = spanHolder.get();
  if (span == null)
    return;

  final Map<String,String> map = new HashMap<>();
  GlobalTracer.get().inject(span.context(), Builtin.TEXT_MAP, new TextMapAdapter(map));

  tProtocol.writeFieldBegin(new TField("span", TType.MAP, SPAN_FIELD_ID));
  tProtocol.writeMapBegin(new TMap(TType.STRING, TType.STRING, map.size()));
  for (final Entry<String,String> entry : map.entrySet()) {
    tProtocol.writeString(entry.getKey());
    tProtocol.writeString(entry.getValue());
  }

  tProtocol.writeMapEnd();
  tProtocol.writeFieldEnd();
  injected.set(true);
}
 
Example #9
Source File: Server.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
private void process(Message message) {
  SpanContext context =
      tracer.extract(Builtin.TEXT_MAP_EXTRACT, new TextMapExtractAdapter(message));
  Span span =
      tracer
          .buildSpan("receive")
          .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
          .withTag(Tags.COMPONENT.getKey(), "example-server")
          .asChildOf(context)
          .start();

  try (Scope scope = tracer.activateSpan(span)) {
    // Simulate work.
  } finally {
    span.finish();
  }
}
 
Example #10
Source File: TracingChannelInterceptor.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Message<?> preSendServerSpan(final Message<?> message) {
  final String destination = (String)message.getHeaders().get(SIMP_DESTINATION);
  final SpanBuilder spanBuilder = tracer
    .buildSpan(destination != null ? destination : UNKNOWN_DESTINATION)
    .withTag(Tags.SPAN_KIND.getKey(), spanKind)
    .withTag(Tags.COMPONENT.getKey(), WEBSOCKET);

  final Map<String,List<String>> nativeHeaders = (Map<String,List<String>>)message.getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
  SpanContext spanContext = null;
  if (nativeHeaders != null)
    spanContext = tracer.extract(Builtin.TEXT_MAP, new NativeHeadersExtractAdapter(nativeHeaders));

  if (spanContext == null)
    spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(message.getHeaders()));

  if (spanContext != null)
    spanBuilder.asChildOf(spanContext);

  final Span span = spanBuilder.start();
  return MessageBuilder.fromMessage(message).setHeader(OPENTRACING_SPAN, span).build();
}
 
Example #11
Source File: SpringRabbitMQAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void onMessageEnter(final Object msg) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder builder = tracer
    .buildSpan("onMessage")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER);

  final Message message = (Message)msg;
  if (message.getMessageProperties() != null) {
    final Map<String,Object> headers = message.getMessageProperties().getHeaders();
    final SpanContext spanContext = tracer.extract(Builtin.TEXT_MAP, new HeadersMapExtractAdapter(headers));
    if (spanContext != null)
      builder.addReference(References.FOLLOWS_FROM, spanContext);
  }

  final Span span = builder.start();
  LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span));
}
 
Example #12
Source File: PulsarFunctionsAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void handleMessageEnter(final Object function, final Object contextArg, final Object arg0) {
  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder spanBuilder = tracer
    .buildSpan(getFunctionName(function, contextArg))
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER);

  if (arg0 != null) {
    final Record<?> record = (Record<?>)arg0;
    final SpanContext spanContext = tracer.extract(Builtin.TEXT_MAP, new TextMapExtractAdapter(record.getProperties()));
    if (spanContext != null)
      spanBuilder.addReference(References.FOLLOWS_FROM, spanContext);
  }

  final Span span = spanBuilder.start();
  final Scope scope = tracer.activateSpan(span);

  LocalSpanContext.set(COMPONENT_NAME, span, scope);
}
 
Example #13
Source File: GoogleHttpClientAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void enter(final Object thiz) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final Tracer tracer = GlobalTracer.get();
  HttpRequest request = (HttpRequest)thiz;

  final Span span = tracer
    .buildSpan(request.getRequestMethod())
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.HTTP_METHOD, request.getRequestMethod())
    .withTag(Tags.HTTP_URL, request.getUrl().toString())
    .withTag(Tags.PEER_PORT, getPort(request))
    .withTag(Tags.PEER_HOSTNAME, request.getUrl().getHost()).start();

  final Scope scope = tracer.activateSpan(span);
  tracer.inject(span.context(), Builtin.HTTP_HEADERS, new HttpHeadersInjectAdapter(request.getHeaders()));

  LocalSpanContext.set(COMPONENT_NAME, span, scope);
}
 
Example #14
Source File: Stadium.java    From demo-mesh-arena with Apache License 2.0 5 votes vote down vote up
private void randomBall(RoutingContext ctx) {
  JsonObject json = new JsonObject()
      .put("x", LEFT + rnd.nextInt(WIDTH))
      .put("y", TOP + rnd.nextInt(HEIGHT));

  HttpRequest<Buffer> request = client.put(BALL_PORT, BALL_HOST, "/setPosition");
  TRACER.ifPresent(tracer -> tracer.inject(TracingHandler.serverSpanContext(ctx), Builtin.HTTP_HEADERS, new TracingContext(request.headers())));
  request.sendJson(json, ar -> {
    if (!ar.succeeded()) {
      ar.cause().printStackTrace();
    }
  });
  ctx.response().end();
}
 
Example #15
Source File: OpenTracingTracingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testThatNewInnerSpanIsCreated() throws Exception {
    final JaegerSpanContext spanId = fromRandom();

    final Map<String, List<String>> headers = new HashMap<>();
    tracer.inject(spanId, Builtin.HTTP_HEADERS, new TextMapInjectAdapter(headers));

    final BookStoreService service = createJaxWsService(headers);
    assertThat(service.getBooks().size(), equalTo(2));

    assertThat(REPORTER.getSpans().size(), equalTo(2));
    assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("Get Books"));
    assertThat(REPORTER.getSpans().get(1).getOperationName(), equalTo("POST /BookStore"));
}
 
Example #16
Source File: AbstractOpenTracingProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders,
        URI uri, String method) {

    SpanContext parent = tracer.extract(Builtin.HTTP_HEADERS, 
        new TextMapAdapter(
            requestHeaders
                .entrySet()
                .stream()
                .collect(Collectors.toMap(Map.Entry::getKey, this::getFirstValueOrEmpty))
        ));
    
    Span activeSpan = null;
    Scope scope = null;
    if (parent == null) {
        activeSpan = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).start(); 
        scope = tracer.scopeManager().activate(activeSpan);
    } else {
        activeSpan = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).asChildOf(parent).start();
        scope = tracer.scopeManager().activate(activeSpan);
    }
    
    // Set additional tags
    activeSpan.setTag(Tags.HTTP_METHOD.getKey(), method);
    activeSpan.setTag(Tags.HTTP_URL.getKey(), uri.toString());
    
    // If the service resource is using asynchronous processing mode, the trace
    // scope will be closed in another thread and as such should be detached.
    Span span = null;
    if (isAsyncResponse()) {
       // Do not modify the current context span
        span = activeSpan;
        propagateContinuationSpan(span);
        scope.close();
    } 

    return new TraceScopeHolder<TraceScope>(new TraceScope(activeSpan, scope), span != null);
}
 
Example #17
Source File: WorkItem.java    From batfish with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void setSourceSpan(@Nullable Span activeSpan, Tracer tracer) {
  if (activeSpan == null) {
    return;
  }
  tracer.inject(activeSpan.context(), Builtin.TEXT_MAP, new TextMapAdapter(_spanData));
}
 
Example #18
Source File: Client.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
public void send() throws InterruptedException {
    Message message = new Message();

    Span span = tracer.buildSpan("send")
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
        .withTag(Tags.COMPONENT.getKey(), "example-client")
        .start();
    try (Scope scope = tracer.activateSpan(span)) {
        tracer.inject(span.context(), Builtin.TEXT_MAP_INJECT, new TextMapInjectAdapter(message));
        queue.put(message);
    } finally {
        span.finish();
    }
}
 
Example #19
Source File: Server.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
private void process(Message message) {
    SpanContext context = tracer.extract(Builtin.TEXT_MAP_EXTRACT, new TextMapExtractAdapter(message));
    Span span = tracer.buildSpan("receive")
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
      .withTag(Tags.COMPONENT.getKey(), "example-server")
      .asChildOf(context)
      .start();

    try (Scope scope = tracer.activateSpan(span)) {
    } finally {
        span.finish();
    }
}
 
Example #20
Source File: Stadium.java    From demo-mesh-arena with Apache License 2.0 5 votes vote down vote up
private void resetBall(RoutingContext ctx) {
  JsonObject json = new JsonObject()
      .put("x", LEFT + WIDTH / 2)
      .put("y", TOP + HEIGHT / 2);

  HttpRequest<Buffer> request = client.put(BALL_PORT, BALL_HOST, "/setPosition");
  TRACER.ifPresent(tracer -> tracer.inject(TracingHandler.serverSpanContext(ctx), Builtin.HTTP_HEADERS, new TracingContext(request.headers())));
  request.sendJson(json, ar -> {
    if (!ar.succeeded()) {
      ar.cause().printStackTrace();
    }
  });
}
 
Example #21
Source File: PlayWSAgentIntercept.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static Object executeStart(final Object arg0, final Object arg1) {
  final Request request = (Request)arg0;
  final AsyncHandler<?> asyncHandler = (AsyncHandler<?>)arg1;

  final Tracer tracer = GlobalTracer.get();
  final Span span = tracer.buildSpan(request.getMethod())
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CLIENT)
    .withTag(Tags.HTTP_METHOD, request.getMethod())
    .withTag(Tags.HTTP_URL, request.getUrl())
    .start();

  tracer.inject(span.context(), Builtin.HTTP_HEADERS, new HttpHeadersInjectAdapter(request.getHeaders()));
  return WrapperProxy.wrap(asyncHandler, new TracingAsyncHandler(asyncHandler, span));
}
 
Example #22
Source File: TracingClientChannelOutboundHandlerAdapter.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final ChannelHandlerContext context, final Object message, final ChannelPromise promise) {
  if (!(message instanceof HttpRequest)) {
    context.write(message, promise);
    return;
  }

  final HttpRequest request = (HttpRequest)message;
  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder builder = tracer
    .buildSpan(request.method().name())
    .withTag(Tags.COMPONENT, "netty")
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CLIENT)
    .withTag(Tags.HTTP_METHOD, request.method().name())
    .withTag(Tags.HTTP_URL, request.uri());

  final SpanContext parentContext = tracer.extract(Builtin.HTTP_HEADERS, new NettyExtractAdapter(request.headers()));

  if (parentContext != null)
    builder.asChildOf(parentContext);

  final Span span = builder.start();
  try (final Scope scope = tracer.activateSpan(span)) {
    // AWS calls are often signed, so we can't add headers without breaking
    // the signature.
    if (!request.headers().contains("amz-sdk-invocation-id")) {
      tracer.inject(span.context(), Builtin.HTTP_HEADERS, new NettyInjectAdapter(request.headers()));
    }

    context.channel().attr(TracingClientChannelInboundHandlerAdapter.CLIENT_ATTRIBUTE_KEY).set(span);
    try {
      context.write(message, promise);
    }
    catch (final Throwable t) {
      OpenTracingApiUtil.setErrorTag(span, t);
      span.finish();
      throw t;
    }
  }
}
 
Example #23
Source File: TracingServerChannelInboundHandlerAdapter.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRead(final ChannelHandlerContext handlerContext, final Object message) {
  if (!(message instanceof HttpRequest)) {
    handlerContext.fireChannelRead(message);
    return;
  }

  final HttpRequest request = (HttpRequest)message;
  final Tracer tracer = GlobalTracer.get();

  final SpanBuilder spanBuilder = tracer.buildSpan(request.method().name())
    .withTag(Tags.COMPONENT, "netty")
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER)
    .withTag(Tags.HTTP_METHOD, request.method().name())
    .withTag(Tags.HTTP_URL, request.uri());

  final SpanContext spanContext = tracer.extract(Builtin.HTTP_HEADERS, new NettyExtractAdapter(request.headers()));
  if (spanContext != null)
    spanBuilder.asChildOf(spanContext);

  final Span span = spanBuilder.start();
  try (final Scope scope = tracer.activateSpan(span)) {
    handlerContext.channel().attr(SERVER_ATTRIBUTE_KEY).set(span);

    try {
      handlerContext.fireChannelRead(message);
    }
    catch (final Throwable t) {
      OpenTracingApiUtil.setErrorTag(span, t);
      span.finish();
      throw t;
    }
  }
}
 
Example #24
Source File: AkkaHttpSyncHandler.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
static Span buildSpan(final HttpRequest request) {
  final SpanBuilder spanBuilder = GlobalTracer.get().buildSpan(request.method().value())
    .withTag(Tags.COMPONENT, COMPONENT_NAME_SERVER)
    .withTag(Tags.HTTP_URL, request.getUri().toString())
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER);

  final SpanContext context = GlobalTracer.get().extract(Builtin.HTTP_HEADERS, new HttpHeadersExtractAdapter(request));
  if (context != null)
    spanBuilder.addReference(References.FOLLOWS_FROM, context);

  return spanBuilder.start();
}
 
Example #25
Source File: HttpClientAgentIntercept.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static Object[] enter(final Object arg0, final Object arg1, final Object arg2) {
  final HttpRequest request = arg0 instanceof HttpRequest ? (HttpRequest)arg0 : arg1 instanceof HttpRequest ? (HttpRequest)arg1 : null;
  if (request == null)
    return null;

  if (request.getHeaders("amz-sdk-invocation-id").length > 0) {
    // skip embedded Apache HttpClient in AWS SDK Client, because it breaks
    // request signature and AWS SDK gets traced by the aws-sdk rule
    return null;
  }

  final LocalSpanContext context = LocalSpanContext.get(COMPONENT_NAME);
  if (context != null) {
    context.increment();
    return null;
  }

  final Tracer tracer = GlobalTracer.get();
  final Span span = tracer
    .buildSpan(request.getRequestLine().getMethod())
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
    .withTag(Tags.HTTP_METHOD, request.getRequestLine().getMethod())
    .withTag(Tags.HTTP_URL, request.getRequestLine().getUri()).start();

  for (final ApacheClientSpanDecorator decorator : Configuration.spanDecorators)
    decorator.onRequest(request, arg0 instanceof HttpHost ? (HttpHost)arg0 : null, span);

  LocalSpanContext.set(COMPONENT_NAME, span, null);

  tracer.inject(span.context(), Builtin.HTTP_HEADERS, new HttpHeadersInjectAdapter(request));
  if (arg1 instanceof ResponseHandler)
    return new Object[] {WrapperProxy.wrap(arg1, new TracingResponseHandler<>((ResponseHandler<?>)arg1, span))};

  if (arg2 instanceof ResponseHandler)
    return new Object[] {null, WrapperProxy.wrap(arg2, new TracingResponseHandler<>((ResponseHandler<?>)arg2, span))};

  return null;
}
 
Example #26
Source File: TracingChannelInterceptor.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private Message<?> preSendClientSpan(final Message<?> message) {
  final String destination = (String)message.getHeaders().get(SIMP_DESTINATION);
  final Span span = tracer
    .buildSpan(destination != null ? destination : UNKNOWN_DESTINATION)
    .withTag(Tags.SPAN_KIND.getKey(), spanKind)
    .withTag(Tags.COMPONENT.getKey(), WEBSOCKET).start();
  final MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(message).setHeader(OPENTRACING_SPAN, span);
  tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(messageBuilder));
  return messageBuilder.build();
}
 
Example #27
Source File: HttpURLConnectionAgentIntercept.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void enter(final Object thiz, final boolean connected) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  if (connected)
    return;

  final HttpURLConnection connection = (HttpURLConnection)thiz;
  final Tracer tracer = GlobalTracer.get();
  final SpanContext spanContext = tracer.extract(Builtin.HTTP_HEADERS, new HttpURLConnectionExtractAdapter(connection));

  if (spanContext != null)
    return;

  final Span span = tracer.buildSpan(connection.getRequestMethod())
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.HTTP_METHOD, connection.getRequestMethod())
    .withTag(Tags.HTTP_URL, connection.getURL().toString())
    .withTag(Tags.PEER_PORT, getPort(connection))
    .withTag(Tags.PEER_HOSTNAME, connection.getURL().getHost()).start();

  final Scope scope = tracer.activateSpan(span);
  tracer.inject(span.context(), Builtin.HTTP_HEADERS, new HttpURLConnectionInjectAdapter(connection));

  LocalSpanContext.set(COMPONENT_NAME, span, scope);
}
 
Example #28
Source File: JaegerInitializer.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext sc = servletContextEvent.getServletContext();

    String serviceName = getProperty(sc, JAEGER_SERVICE_NAME);
    if (serviceName == null || serviceName.isEmpty()) {
        logger.warn("No Service Name set. Using default. Please change it.");
        serviceName = "thorntail/unknown";
    }

    Configuration configuration = new Configuration(serviceName)
            .withSampler(
                    new Configuration.SamplerConfiguration()
                            .withType(
                                    getProperty(sc, JAEGER_SAMPLER_TYPE))
                            .withParam(
                                    getPropertyAsNumber(sc, JAEGER_SAMPLER_PARAM))
                            .withManagerHostPort(
                                    getProperty(sc, JAEGER_SAMPLER_MANAGER_HOST_PORT)))
            .withReporter(
                    new ReporterConfiguration()
                            .withLogSpans(
                                    getPropertyAsBoolean(sc, JAEGER_REPORTER_LOG_SPANS))
                            .withSender(
                                    new SenderConfiguration()
                                            .withAuthUsername(getProperty(sc, JAEGER_USER))
                                            .withAuthPassword(getProperty(sc, JAEGER_PASSWORD))
                                            .withAgentHost(getProperty(sc, JAEGER_AGENT_HOST))
                                            .withAgentPort(getPropertyAsInt(sc, JAEGER_AGENT_PORT)))
                            .withFlushInterval(
                                    getPropertyAsInt(sc, JAEGER_REPORTER_FLUSH_INTERVAL))
                            .withMaxQueueSize(
                                    getPropertyAsInt(sc, JAEGER_REPORTER_MAX_QUEUE_SIZE)
                            )
            );

    String remoteEndpoint = getProperty(sc, JAEGER_ENDPOINT);
    if (remoteEndpoint != null && remoteEndpoint.trim().length() > 0) {
        configuration.getReporter()
                .withSender(new SenderConfiguration()
                                    .withEndpoint(remoteEndpoint));
    }

    String enableB3HeaderPropagation = getProperty(sc, "enableB3HeaderPropagation");
    if (enableB3HeaderPropagation != null && Boolean.parseBoolean(enableB3HeaderPropagation)) {
        logger.info("Enabling B3 Header Propagation for Jaeger");
        CodecConfiguration codecConfiguration = new CodecConfiguration();
        codecConfiguration.withCodec(Builtin.HTTP_HEADERS, new B3TextMapCodec.Builder().build());
        codecConfiguration.withCodec(Builtin.TEXT_MAP, new B3TextMapCodec.Builder().build());
        configuration.withCodec(codecConfiguration);
    }

    GlobalTracer.register(configuration.getTracer());
}
 
Example #29
Source File: WorkItem.java    From batfish with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
SpanContext getSourceSpan(Tracer tracer) {
  return tracer.extract(Builtin.TEXT_MAP, new TextMapAdapter(_spanData));
}