Java Code Examples for io.opentracing.contrib.jdbc.parser.URLParser

The following examples show how to use io.opentracing.contrib.jdbc.parser.URLParser. These examples are extracted from open source projects. 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 Project: java-jdbc   Source File:    License: Apache License 2.0 5 votes vote down vote up
public Connection connect(String url, Properties info) throws SQLException {
  // if there is no url, we have problems
  if (url == null) {
    throw new SQLException("url is required");

  final Set<String> ignoreStatements;
  final boolean withActiveSpanOnly;
  if (interceptorMode) {
    withActiveSpanOnly = TracingDriver.withActiveSpanOnly;
    ignoreStatements = TracingDriver.ignoreStatements;
  } else if (acceptsURL(url)) {
    withActiveSpanOnly = url.contains(WITH_ACTIVE_SPAN_ONLY);
    ignoreStatements = extractIgnoredStatements(url);
  } else {
    return null;

  url = extractRealUrl(url);

  // find the real driver for the URL
  final Driver wrappedDriver = findDriver(url);

  final Tracer currentTracer = getTracer();
  final ConnectionInfo connectionInfo = URLParser.parser(url);
  final Span span = buildSpan("AcquireConnection", "", connectionInfo, withActiveSpanOnly,
      Collections.<String>emptySet(), currentTracer);
  final Connection connection;
  try (Scope ignored = currentTracer.activateSpan(span)) {
    connection = wrappedDriver.connect(url, info);
  } finally {

  return WrapperProxy
      .wrap(connection, new TracingConnection(connection, connectionInfo, withActiveSpanOnly,
          ignoreStatements, currentTracer));
Example 2
Source Project: java-spring-cloud   Source File:    License: Apache License 2.0 5 votes vote down vote up
 * Intercepts calls to {@link DataSource#getConnection()} (and related), wrapping the outcome in a
 * {@link TracingConnection} proxy
 * @param pjp the intercepted join point
 * @return a new {@link TracingConnection} proxy wrapping the result of the joint point
 * @throws Throwable in case of wrong JDBC URL
@Around("execution(java.sql.Connection *.getConnection(..)) && target(javax.sql.DataSource)")
public Object getConnection(final ProceedingJoinPoint pjp) throws Throwable {
  Connection conn = (Connection) pjp.proceed();
  if (WrapperProxy.isWrapper(conn, TracingConnection.class)) {
    return conn;
  String url = conn.getMetaData().getURL();
  ConnectionInfo connectionInfo = URLParser.parse(url);
  return WrapperProxy.wrap(conn, new TracingConnection(conn, connectionInfo,
      withActiveSpanOnly, ignoredStatements, GlobalTracer.get()));
Example 3
Source Project: che   Source File:    License: Eclipse Public License 2.0 5 votes vote down vote up
public TracingDataSource(DataSource delegate) {
  this.delegate = delegate;
  try (Connection connection = delegate.getConnection()) {
    connectionInfo = URLParser.parser(connection.getMetaData().getURL());
        "URL {} connectionInfo {}",
  } catch (SQLException e) {
    throw new RuntimeException(e);