opentracing-contrib / java-jdbc

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

Invoking by code to change slowQueryThresholdMs #107

Closed avifro-dev closed 3 years ago

avifro-dev commented 3 years ago

It's well documented that it's possible to change slowQueryThresholdMs value by code, as it's public static variable. For example as in the below example: io.opentracing.contrib.jdbc.JdbcTracingUtils.slowQueryThresholdMs = 100 Unfortunately, the class containing this static variable has a package scope (JdbcTracingUtils), so I'm afraid it's not possible to do so. The only way of setting this value is just via setting environment variable, but didn't find any way to do it dynamically. Maybe I'm missing here something?

trajano commented 3 years ago

The class JdbcTracingUtils is not public so you can't change it easily.

Until this is resolved, here's the workaround

    final Field slowQueryThresholdMs = Class.forName("io.opentracing.contrib.jdbc.JdbcTracingUtils").getField("slowQueryThresholdMs");
    slowQueryThresholdMs.setAccessible(true);
    slowQueryThresholdMs.set(null, 100);