brave.propagation.ThreadLocalSpan Java Examples
The following examples show how to use
brave.propagation.ThreadLocalSpan.
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: TracingChannelInterceptor.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
TracingChannelInterceptor(Tracing tracing, Propagation.Setter<MessageHeaderAccessor, String> setter, Propagation.Getter<MessageHeaderAccessor, String> getter) { this.tracing = tracing; this.tracer = tracing.tracer(); this.threadLocalSpan = ThreadLocalSpan.create(this.tracer); this.injector = tracing.propagation().injector(setter); this.extractor = tracing.propagation().extractor(getter); this.integrationObjectSupportPresent = ClassUtils.isPresent( "org.springframework.integration.context.IntegrationObjectSupport", null); this.hasDirectChannelClass = ClassUtils .isPresent("org.springframework.integration.channel.DirectChannel", null); this.directWithAttributesChannelClass = ClassUtils .isPresent(STREAM_DIRECT_CHANNEL, null) ? ClassUtils.resolveClassName(STREAM_DIRECT_CHANNEL, null) : null; }
Example #2
Source File: TracingStatementInterceptor.java From brave with Apache License 2.0 | 6 votes |
/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. * * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before * tracing. */ @Override public <T extends Resultset> T preProcess(String sql, Statement interceptedStatement) { // Gets the next span (and places it in scope) so code between here and postProcess can read it Span span = ThreadLocalSpan.CURRENT_TRACER.next(); if (span == null || span.isNoop()) return null; // When running a prepared statement, sql will be null and we must fetch the sql from the statement itself if (interceptedStatement instanceof PreparedStatement) { sql = ((PreparedStatement) interceptedStatement).getPreparedSql(); } int spaceIndex = sql.indexOf(' '); // Allow span names of single-word statements like COMMIT span.kind(CLIENT).name(spaceIndex == -1 ? sql : sql.substring(0, spaceIndex)); span.tag("sql.query", sql); parseServerIpAndPort(connection, span); span.start(); return null; }
Example #3
Source File: TracingStatementInterceptor.java From brave with Apache License 2.0 | 6 votes |
/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. * * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before * tracing. */ @Override public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) { // Gets the next span (and places it in scope) so code between here and postProcess can read it Span span = ThreadLocalSpan.CURRENT_TRACER.next(); if (span == null || span.isNoop()) return null; // When running a prepared statement, sql will be null and we must fetch the sql from the statement itself if (interceptedStatement instanceof PreparedStatement) { sql = ((PreparedStatement) interceptedStatement).getPreparedSql(); } int spaceIndex = sql.indexOf(' '); // Allow span names of single-word statements like COMMIT span.kind(CLIENT).name(spaceIndex == -1 ? sql : sql.substring(0, spaceIndex)); span.tag("sql.query", sql); parseServerIpAndPort(connection, span); span.start(); return null; }
Example #4
Source File: ZipkinHttpClientImpl.java From ratpack-zipkin with Apache License 2.0 | 5 votes |
@Inject public ZipkinHttpClientImpl(final HttpClient delegate, final HttpTracing httpTracing) { this.delegate = delegate; this.threadLocalSpan = ThreadLocalSpan.create(httpTracing.tracing().tracer()); this.currentTraceContext = httpTracing.tracing().currentTraceContext(); this.nextThreadLocalSpan = new NextSpan(threadLocalSpan, httpTracing.clientSampler()); this.handler = HttpClientHandler.create(httpTracing, ADAPTER); this.injector = httpTracing.tracing().propagation().injector(MutableHeaders::set); }
Example #5
Source File: TracingJdbcEventListener.java From brave with Apache License 2.0 | 5 votes |
/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. * * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before * tracing. */ @Override public void onBeforeAnyExecute(StatementInformation info) { String sql = includeParameterValues ? info.getSqlWithValues() : info.getSql(); if (!isLoggable(sql)) return; // Gets the next span (and places it in scope) so code between here and postProcess can read it Span span = ThreadLocalSpan.CURRENT_TRACER.next(); if (span == null || span.isNoop()) return; int spaceIndex = sql.indexOf(' '); // Allow span names of single-word statements like COMMIT span.kind(CLIENT).name(spaceIndex == -1 ? sql : sql.substring(0, spaceIndex)); span.tag("sql.query", sql); parseServerIpAndPort(info.getConnectionInformation().getConnection(), span); span.start(); }
Example #6
Source File: TracingJdbcEventListener.java From brave with Apache License 2.0 | 5 votes |
@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.error(e); span.tag("error", Integer.toString(e.getErrorCode())); } span.finish(); }
Example #7
Source File: TracingStatementInterceptor.java From brave with Apache License 2.0 | 5 votes |
@Override public <T extends Resultset> T postProcess(String sql, Statement interceptedStatement, T originalResultSet, int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, Exception error) { Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return null; span.error(error); if (error instanceof SQLException) { span.tag("error", Integer.toString(((SQLException) error).getErrorCode())); } span.finish(); return null; }
Example #8
Source File: TracingExceptionInterceptor.java From brave with Apache License 2.0 | 5 votes |
/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. The span will already have been created in {@link * TracingQueryInterceptor}. * * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before * tracing. */ @Override public Exception interceptException(Exception e) { Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return null; span.error(e); if (e instanceof SQLException) { span.tag("error", Integer.toString(((SQLException) e).getErrorCode())); } span.finish(); return null; }
Example #9
Source File: TracingQueryInterceptor.java From brave with Apache License 2.0 | 5 votes |
/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. * * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before * tracing. */ @Override public <T extends Resultset> T preProcess(Supplier<String> sqlSupplier, Query interceptedQuery) { // Gets the next span (and places it in scope) so code between here and postProcess can read it Span span = ThreadLocalSpan.CURRENT_TRACER.next(); if (span == null || span.isNoop()) return null; String sql = sqlSupplier.get(); int spaceIndex = sql.indexOf(' '); // Allow span names of single-word statements like COMMIT span.kind(CLIENT).name(spaceIndex == -1 ? sql : sql.substring(0, spaceIndex)); span.tag("sql.query", sql); parseServerIpAndPort(connection, span); span.start(); return null; }
Example #10
Source File: TracingQueryInterceptor.java From brave with Apache License 2.0 | 5 votes |
@Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { if (interceptingExceptions && originalResultSet == null) { // Error case, the span will be finished in TracingExceptionInterceptor. return null; } Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return null; span.finish(); return null; }
Example #11
Source File: TracingStatementInterceptor.java From brave with Apache License 2.0 | 5 votes |
@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.error(statementException); span.tag("error", Integer.toString(statementException.getErrorCode())); } span.finish(); return null; }
Example #12
Source File: ZipkinHttpClientImpl.java From ratpack-zipkin with Apache License 2.0 | 4 votes |
NextSpan(ThreadLocalSpan span, HttpSampler sampler) { this.span = span; this.sampler = sampler; }
Example #13
Source File: TraceMongoCommandListener.java From brave with Apache License 2.0 | 4 votes |
TraceMongoCommandListener(MongoDBTracing mongoDBTracing) { this(ThreadLocalSpan.create(mongoDBTracing.tracing.tracer())); }
Example #14
Source File: TraceMongoCommandListener.java From brave with Apache License 2.0 | 4 votes |
TraceMongoCommandListener(ThreadLocalSpan threadLocalSpan) { this.threadLocalSpan = threadLocalSpan; }