scopes:
tracemaintestReportmethod:
type:
name: com.org.test.controller.controllerTest
tracesubMethod: (sub method from other class invoked from 'testReport' main method)
type:
name: com.org.test.util.InputData
methods:
- name: getId
- name: setStatus
rules:
tracemaintestReportmethod:
tracing:
start-span: true
scopes:
tracemaintestReportmethod: true
tracesubMethod: true
Hi @JonasKunz , I tried to implemet JDBC tracing for MSSQL prepared statement by referring the HSQL db conf in demo app.
getting below exception. Database name gettting printed in trace but not SQL queries.
below is my instrumentation config
inspectit:
instrumentation:
data:
db_name: {down-propagation: NONE, is-tag: false}
sql: {down-propagation: NONE, is-tag: false}
servicegraph_is_entry: {down-propagation: NONE, is-tag: false}
scopes:
mssqldb_prepared_statement_execute:
type:
name: com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement
methods:
- name: execute
matcher-mode: STARTS_WITH
rules:
mssql_get_prep_statement_sql:
scopes:
mssqldb_prepared_statement_execute: true
tracing:
attributes:
database: db_name
sql: sql
entry:
db_name:
action: get_jdbc_statement_connection_name
sql:
action: mssql_prepared_statement_get_sql
actions:
mssql_prepared_statement_get_sql:
imports:
- com.microsoft.sqlserver.jdbc
- java.lang.reflect
input:
_this: SQLServerPreparedStatement
_class: Class
value-body: |
Field sqlField = _class.getDeclaredField("sql");
sqlField.setAccessible(true);
return sqlField.get(_this);
get_jdbc_statement_connection_name:
imports:
- java.sql
input:
_this: Statement
value-body: |
if(!_this.isClosed()) {
Connection con = _this.getConnection();
String url = con.getMetaData().getURL();
int semiColonIndex = url.indexOf(';');
if(semiColonIndex != -1) {
url = url.substring(0,semiColonIndex);
}
int questionIndex = url.indexOf('?');
if(questionIndex != -1) {
url = url.substring(0,questionIndex);
When I execute with this configuration only DB name is getting logged in trace.
Encountering below exception.
2020-02-13 23:13:08,894 ERROR 81787820 --- [] [Bean#0_Worker-1] r.i.o.c.instrumentation.hook.MethodHook : Entry action Action 'mssql_prepared_statement_get_sql' for call 'sql' executed for method com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery threw an exception and from now on is disabled!
java.lang.NoSuchFieldException: sql
at java.lang.Class.getDeclaredField(Class.java:2070)
at com.sun.proxy.inspectitGen
KaTeX parse error: Can't use function '$' in math mode at position 1: $̲557729609728220…: $5577296097282200557.executeImpl(GenericActionTemplate.java)
at com.sun.proxy.inspectitGen
$5577296097282200557.execute(GenericActionTemplate.java:24)Can you please help me with this.! Thanks
mssql_prepared_statement_get_sql
tries to lookup an sql
private field of the given SQLServerPreparedStatement class. This field doesn't exist, therefore you get the NoSuchFieldException
. Have a look at the source code:sqlCommand
.
data:
db_name: {down-propagation: NONE, is-tag: false}
sql: {down-propagation: NONE, is-tag: false}
servicegraph_is_entry: {down-propagation: NONE, is-tag: false}
scopes:
oracle_prepared_statement_execute:
type:
name: oracle.jdbc.OraclePreparedStatement
methods:
- name: execute
matcher-mode: STARTS_WITH
rules:
# Extract the sql and add it to the trace
oracle_get_prep_statement_sql:
scopes:
oracle_prepared_statement_execute: true
tracing:
attributes:
database: db_name
sql: sql
entry:
db_name:
action: get_jdbc_statement_connection_name
sql:
action: oracle_prepared_statement_get_sql
# We also trace JDBC calls including their target database
servicegraph_record_jdbc_calls:
tracing:
start-span: true
attributes:
database: db_name
start-span-conditions:
only-if-true: servicegraph_is_entry
entry:
db_name:
action: get_jdbc_statement_connection_name
actions:
oracle_prepared_statement_get_sql:
imports:
- oracle.jdbc
- java.lang.reflect
input:
_this: OraclePreparedStatement
_class: Class
value-body:
Field sqlField = _class.getDeclaredField("sql");
sqlField.setAccessible(true);
return sqlField.get(_this);
Unfortunately, here the problem is the same: With OpenCensus / OpenTelemetry / OpenTracing, a span needs to know whether or not it shall be sampled at thepoint in time when it is started.
Why is this necessary?
When a span is started, it makes itself the parent of all following spans. Therefore it already needs to know at this point, if it should make itself the parent of following spans or not.
Hi, im trying to trace an application with ocelot. I need the FQN of each method being called and for this purpose I use the following action
get_method_fqn:
input:
_methodName: String
_class: Class
value: "new StringBuilder(_class.getName()).append('.').append(_methodName).toString()"
However, this does not seem to register constructor calls. Is there a way to trace object creation / constructor calls?
Hi Kevin, yes, this is possible, but this is not defined in the actions but under the scopes. There you can define if it is a constructor method: with the attribute "is-constructor: true" (see also https://inspectit.github.io/inspectit-ocelot/docs/instrumentation/scopes#method-matcher).
What does the scope you defined look like?
Hi Patrick, thanks for replying. The scope I'm using looks like this:
instrumentation:
scopes:
allClasses:
type:
name: net.ex
matcher-mode: STARTS_WITH_IGNORE_CASE
# methods:
# - is-constructor: true
This works fine als long as the last two lines are commented out. If I include them, no spans are received at all.
Hi Kevin,
your configuration is correct, if the last two lines are commented out, this means that only constructors are instrumented. That no spans arrive may be because the constructors are not called. By the way, the constructors in your configuration are instrumented even if the last two lines are commented, because the scope is on all methods of the class.
Alternatively, it is possible that the span is overlooked accidentally. For this I have a small example from the Petclinic-Demo*: