Java Code Examples for io.opentracing.Span#setOperationName()

The following examples show how to use io.opentracing.Span#setOperationName() . 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: OpenTracingFilter.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Override
public Response filter(DocumentFilterContext filterRequestContext, DocumentFilterChain chain) {
	Span span = tracer.activeSpan();

	if (span != null) {
		String spanName = toSpanName(filterRequestContext);

		LOGGER.debug("setting span name {} on {}", spanName, span);
		span.setOperationName(spanName);
	}
	else {
		LOGGER.debug("no span active");
	}

	return chain.doFilter(filterRequestContext);
}
 
Example 2
Source File: TracingService.java    From nakadi with MIT License 5 votes vote down vote up
public static Span extractSpan(final HttpServletRequest request, final String operation) {
    final Span span = (Span) request.getAttribute("span");
    if (span != null) {
        return span.setOperationName(operation);
    }
    return GlobalTracer.get().buildSpan("default_Span").start();
}
 
Example 3
Source File: MockSpanTest.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetOperationNameAfterFinish() {
    MockTracer tracer = new MockTracer();
    Span span = tracer.buildSpan("foo").start();
    span.finish();

    try {
        span.setOperationName("bar");
        Assert.fail();
    } catch (RuntimeException ex) {
    }
    Assert.assertEquals(1, tracer.finishedSpans().get(0).generatedErrors().size());
}
 
Example 4
Source File: RewritableSpanBuilder.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public Span start() {
  final Span span = target.start();
  if (this.span != null && this.span.target == span)
    return this.span;

  if (log != null)
    for (final Map<String,Object> fields : log)
      span.log(fields);

  if (operationName != null)
    span.setOperationName(operationName);

  return this.span = newRewritableSpan(span);
}
 
Example 5
Source File: WebFluxSpanDecorator.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private void addWebFluxTags(final ServerWebExchange exchange, final Span span) {
  final Object handler = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
  if (handler == null) {
    return;
  }

  final Map<String, Object> logs = new HashMap<>(4);
  logs.put("event", "handle");

  final Object pattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
  final String patternAsString = pattern == null ? null : pattern.toString();
  if (pattern != null) {
    logs.put("handler", patternAsString);
  }

  if (handler instanceof HandlerMethod) {
    final HandlerMethod handlerMethod = (HandlerMethod) handler;
    final String methodName = handlerMethod.getMethod().getName();
    logs.put("handler.method_name", handlerMethod.getMethod().getName());
    span.setOperationName(methodName);
    logs.put("handler.class_simple_name", handlerMethod.getBeanType().getSimpleName());
  } else {
    if (pattern != null) {
      span.setOperationName(patternAsString);
    }
    logs.put("handler.class_simple_name", handler.getClass().getSimpleName());
  }
  span.log(logs);
}
 
Example 6
Source File: HandlerInterceptorSpanDecorator.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public void onPreHandle(HttpServletRequest httpServletRequest, Object handler, Span span) {
  String metaData = HandlerUtils.methodName(handler);
  if (metaData != null) {
    span.setOperationName(metaData);
  }
}
 
Example 7
Source File: OpenTracing0_33_BraveSpanTest.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
@Test public void afterFinish_dataIgnored() {
  Span span = tracer.buildSpan("foo").start();
  span.finish();
  spans.clear();

  span.setOperationName("bar");
  span.setTag("hello", "monster");
  span.log("alarming");
  span.finish();

  assertThat(spans)
      .isEmpty();
}
 
Example 8
Source File: ServerTracingFilter.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ContainerRequestContext requestContext) {
    // return in case filter if registered twice
    if (requestContext.getProperty(PROPERTY_NAME) != null || matchesSkipPattern(requestContext)) {
        return;
    }

    if (tracer != null) {

        SpanContext parentSpanContext = parentSpanContext(requestContext);
        Span span = tracer.buildSpan(operationNameProvider.operationName(requestContext))
                .ignoreActiveSpan()
                .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
                .asChildOf(parentSpanContext)
                .start();

        if (spanDecorators != null) {
            for (ServerSpanDecorator decorator: spanDecorators) {
                decorator.decorateRequest(requestContext, span);
            }
        }

        // override operation name set by @Traced
        if (this.operationName != null) {
            span.setOperationName(operationName);
        }

        if (log.isLoggable(Level.FINEST)) {
            log.finest("Creating server span: " + operationName);
        }

        requestContext.setProperty(PROPERTY_NAME, new SpanWrapper(span, tracer.activateSpan(span)));
    }
}
 
Example 9
Source File: OpenTracingBridgeTest.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Test
void testOperationsAfterFinish() {
    final Span span = apmTracer.buildSpan("test").start();

    span.finish();

    assertThat(reporter.getTransactions()).hasSize(1);

    // subsequent calls have undefined behavior but should not throw exceptions
    span.setOperationName("");
    span.setTag("foo", "bar");
    span.setBaggageItem("foo", "bar");
    span.getBaggageItem("foo");
    span.log("foo");
}
 
Example 10
Source File: WebFluxSpanDecorator.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
private void addWebFluxTags(final ServerWebExchange exchange, final Span span) {
    final Object handler = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
    if (handler == null) {
        return;
    }

    final Map<String, Object> logs = new HashMap<>(4);
    logs.put("event", "handle");

    final Object pattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    final String patternAsString = pattern == null ? null : pattern.toString();
    if (pattern != null) {
        logs.put("handler", patternAsString);
    }

    if (handler instanceof HandlerMethod) {
        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        final String methodName = handlerMethod.getMethod().getName();
        logs.put("handler.method_name", handlerMethod.getMethod().getName());
        span.setOperationName(methodName);
        logs.put("handler.class_simple_name", handlerMethod.getBeanType().getSimpleName());
    } else {
        if (pattern != null) {
            span.setOperationName(patternAsString);
        }
        logs.put("handler.class_simple_name", handler.getClass().getSimpleName());
    }
    span.log(logs);
}
 
Example 11
Source File: HandlerInterceptorSpanDecorator.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Override
public void onPreHandle(HttpServletRequest httpServletRequest, Object handler, Span span) {
    String metaData = HandlerUtils.methodName(handler);
    if (metaData != null) {
        span.setOperationName(metaData);
    }
}
 
Example 12
Source File: SpanDecorator.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onResponse(Connection connection, Response response, Span span) {
	span.setOperationName("Response: " + response.code());
}
 
Example 13
Source File: ClientSpanDecorator.java    From java-jaxrs with Apache License 2.0 4 votes vote down vote up
@Override
public void decorateRequest(ClientRequestContext clientRequestContext, Span span) {
    span.setOperationName(URIUtils.path(clientRequestContext.getUri()));
}
 
Example 14
Source File: SpanDecorator.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onError(Throwable throwable, Span span) {
	span.setOperationName("Error: " + throwable.getMessage());
}
 
Example 15
Source File: SpanDecorator.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onRequest(Request request, Span span) {
	span.setOperationName("Call: " + request.url().toString());
}
 
Example 16
Source File: CustomizedRabbitMqSpanDecorator.java    From java-spring-rabbitmq with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(MessageProperties messageProperties, Span span) {
  super.onReceive(messageProperties, span);
  span.setOperationName(OVERRIDDEN_OPERATION_NAME_FOR_RECEIVING);
}
 
Example 17
Source File: CustomizedRabbitMqSpanDecorator.java    From java-spring-rabbitmq with Apache License 2.0 4 votes vote down vote up
@Override
public void onSend(MessageProperties messageProperties, String exchange, String routingKey, Span span) {
  super.onSend(messageProperties, exchange, routingKey, span);
  span.setOperationName(OVERRIDDEN_OPERATION_NAME_FOR_SENDING);
}