@Override public BraveSpan tag(String key, String value) { span.tag(key, value); return this; }
static void maybeTag(Span span, String tag, String value) { if (value != null) span.tag(tag, value); } }
@Async public void background() throws InterruptedException { int millis = this.random.nextInt(1000); Thread.sleep(millis); this.tracer.currentSpan().tag("background-sleep-millis", String.valueOf(millis)); }
@RequestMapping("/start") public String start() throws InterruptedException { log.info("start"); int millis = this.random.nextInt(1000); log.info(String.format("Sleeping for [%d] millis", millis)); Thread.sleep(millis); this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis)); String s = this.restTemplate .getForObject("http://localhost:" + this.port + "/call", String.class); return "start/" + s; }
@Async public void background() throws InterruptedException { log.info("background"); int millis = this.random.nextInt(1000); Thread.sleep(millis); this.tracer.currentSpan().tag("background-sleep-millis", String.valueOf(millis)); }
@RequestMapping("/hi2") public String hi2() throws InterruptedException { log.info("hi2"); int millis = this.random.nextInt(1000); Thread.sleep(millis); this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis)); return "hi2"; }
private void addClassMethodTag(Object handler, Span span) { if (handler instanceof HandlerMethod) { String methodName = ((HandlerMethod) handler).getMethod().getName(); span.tag(MVC_CONTROLLER_METHOD_KEY, methodName); if (log.isDebugEnabled()) { log.debug("Adding a method tag with value [" + methodName + "] to a span " + span); } } }
@Override public String call() throws Exception { int millis = SampleController.this.random.nextInt(1000); Thread.sleep(millis); Span currentSpan = SampleController.this.tracer.currentSpan(); currentSpan.tag("callable-sleep-millis", String.valueOf(millis)); return "async hi: " + currentSpan; } };
static void onError(Throwable error, Span span) { span.error(error); if (error instanceof RpcException) { span.tag("dubbo.error_code", Integer.toString(((RpcException) error).getCode())); } }
@Override public void onAfterAnyExecute(StatementInformation info, long elapsed, SQLException e) { Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return; if (e != null) { span.tag("error", Integer.toString(e.getErrorCode())); } span.finish(); }
@Override public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection, int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) { Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return null; if (statementException != null) { span.tag("error", Integer.toString(statementException.getErrorCode())); } span.finish(); return null; }
@RequestMapping("/traced") public String traced() throws InterruptedException { Span span = this.tracer.nextSpan().name("http:customTraceEndpoint").start(); int millis = this.random.nextInt(1000); log.info(String.format("Sleeping for [%d] millis", millis)); Thread.sleep(millis); this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis)); String s = this.restTemplate .getForObject("http://localhost:" + this.port + "/call", String.class); span.finish(); return "traced/" + s; }
@Override public <T extends Resultset> T postProcess(String sql, Statement interceptedStatement, T originalResultSet, int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, Exception statementException) { Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return null; if (statementException instanceof SQLException) { span.tag("error", Integer.toString(((SQLException) statementException).getErrorCode())); } span.finish(); return null; }
private void addResponseTagsForSpanWithoutParent(ServerWebExchange exchange, ServerHttpResponse response, Span span) { if (spanWithoutParent(exchange) && response.getStatusCode() != null && span != null) { span.tag(STATUS_CODE_KEY, String.valueOf(response.getStatusCode().value())); } }
@Override protected R getFallback() { Span span = this.span.get(); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) { span.tag(FALLBACK_METHOD_NAME_KEY, getFallbackMethodName()); return doGetFallback(); } finally { span.finish(); this.span.set(null); } }
@Override public void onTimeout(AsyncEvent e) { if (complete) return; span.tag("error", String.format("Timed out after %sms", e.getAsyncContext().getTimeout())); handler.handleSend(adaptResponse(e), null, span); complete = true; }
void setConsumerSpan(String topic, Span span) { span.name("poll").kind(Span.Kind.CONSUMER).tag(KafkaTags.KAFKA_TOPIC_TAG, topic); if (remoteServiceName != null) span.remoteServiceName(remoteServiceName); } }