opentracing-contrib / java-jdbc

OpenTracing Instrumentation for JDBC
Apache License 2.0
82 stars 56 forks source link

In interceptor mode, TracingDriver#acceptsURL should accept URLs without "tracing:" #68

Closed yisheng-liang closed 4 years ago

yisheng-liang commented 4 years ago

Interceptor mode may not work in some cases. For instance, if another wrapper driver calls Driver#acceptsURL for each registered driver in order to find an underlying driver, it won't see TracingDriver unless the JDBC URL has been rewritten to have the jdbc:tracing: prefix.

Simple fix is to change TracingDriver#acceptsURL to be:

  @Override
  public boolean acceptsURL(String url) throws SQLException {
    return url != null && (
        url.startsWith(getUrlPrefix()) || 
        (interceptorMode && url.startsWith("jdbc:"))
    );
  }
malafeev commented 4 years ago

that's not so simple. acceptsURL(...) is used in TracingDriver.connect(...): https://github.com/opentracing-contrib/java-jdbc/blob/master/src/main/java/io/opentracing/contrib/jdbc/TracingDriver.java#L153

this if statement also should be modified to explicitly accept urls only with "jdbc:tracing:"

yisheng-liang commented 4 years ago

We could modify TracingDriver#connect such that it doesn't try to parse the url if interceptorMode is true. Just need to move around those if branches like this:

if (interceptorMode) {
    withActiveSpanOnly = TracingDriver.withActiveSpanOnly;
    ignoreStatements = TracingDriver.ignoreStatements;
} else if (acceptsURL(url)) {
    withActiveSpanOnly = url.contains(WITH_ACTIVE_SPAN_ONLY);
    ignoreStatements = extractIgnoredStatements(url);
    url = extractRealUrl(url);
} else {
    return null;
}

I think this makes sense. Since in interceptor mode, the driver is supposed to be able to intercept JDBC operations without the need of modifying JDBC URLs, so it should not even try to find traceWithActiveSpanOnly or ignoreForTracing from the URLs.

malafeev commented 4 years ago

@yisheng-liang would you like to submit PR?

yisheng-liang commented 4 years ago

Are you going to cut a new release soon? Releases were cut in January quite often but nothing in February.

malafeev commented 4 years ago

0.2.9 is released