1919import io .opentracing .Span ;
2020import io .opentracing .Tracer ;
2121import io .opentracing .contrib .common .WrapperProxy ;
22+ import io .opentracing .contrib .jdbc .parser .URLParser ;
2223import java .io .PrintWriter ;
24+ import java .lang .reflect .Method ;
2325import java .sql .Connection ;
2426import java .sql .SQLException ;
2527import java .sql .SQLFeatureNotSupportedException ;
@@ -40,7 +42,7 @@ public class TracingDataSource implements DataSource, AutoCloseable {
4042
4143 public TracingDataSource (final Tracer tracer ,
4244 final DataSource underlying ) {
43- this (tracer , underlying , ConnectionInfo . UNKNOWN_CONNECTION_INFO , DEFAULT_WITH_ACTIVE_SPAN_ONLY ,
45+ this (tracer , underlying , null , DEFAULT_WITH_ACTIVE_SPAN_ONLY ,
4446 DEFAULT_IGNORED_STATEMENTS );
4547 }
4648
@@ -51,7 +53,25 @@ public TracingDataSource(final Tracer tracer,
5153 final Set <String > ignoreStatements ) {
5254 this .tracer = tracer ;
5355 this .underlying = underlying ;
54- this .connectionInfo = connectionInfo ;
56+ ConnectionInfo info = connectionInfo ;
57+ if (info == null ) {
58+ try {
59+ Method method ;
60+ try {
61+ method = underlying .getClass ().getMethod ("getJdbcUrl" );
62+ } catch (NoSuchMethodException e ) {
63+ try {
64+ method = underlying .getClass ().getMethod ("getUrl" );
65+ } catch (NoSuchMethodException nsme ) {
66+ method = null ;
67+ }
68+ }
69+ info = URLParser .parse ((String ) method .invoke (underlying ));
70+ } catch (Exception ignored ) {
71+ info = ConnectionInfo .UNKNOWN_CONNECTION_INFO ;
72+ }
73+ }
74+ this .connectionInfo = info ;
5575 this .withActiveSpanOnly = withActiveSpanOnly ;
5676 this .ignoreStatements = ignoreStatements ;
5777 }
@@ -140,4 +160,4 @@ public void close() throws Exception {
140160 ((AutoCloseable ) underlying ).close ();
141161 }
142162 }
143- }
163+ }
0 commit comments