/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. * * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before tracing. */ @Override public void onBeforeAnyExecute(StatementInformation info) { String sql = includeParameterValues ? info.getSqlWithValues() : info.getSql(); // don't start a span unless there is SQL as we cannot choose a relevant name without it if (sql == null || sql.isEmpty()) return; // Gets the next span (and places it in scope) so code between here and postProcess can read it Span span = ThreadLocalSpan.CURRENT_TRACER.next(); if (span == null || span.isNoop()) return; span.kind(Span.Kind.CLIENT).name(sql.substring(0, sql.indexOf(' '))); span.tag("sql.query", sql); parseServerIpAndPort(info.getConnectionInformation().getConnection(), span); span.start(); }
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return StatementWrapper.wrap(delegate.createStatement(resultSetType, resultSetConcurrency), new StatementInformation(connectionInformation), jdbcEventListener); }
@Override public void onBeforeAnyAddBatch(StatementInformation statementInformation) { if (P6OutageOptions.getActiveInstance().getOutageDetection()) { P6OutageDetector.INSTANCE.registerInvocation(this, System.nanoTime(), "batch", statementInformation.getSqlWithValues(), statementInformation.getStatementQuery(), statementInformation.getConnectionInformation().getUrl()); } }
@Override public void addBatch(String sql) throws SQLException { if (statementInformation.getStatementQuery() == null) { statementInformation.setStatementQuery(sql); } else { statementInformation.setStatementQuery(sql + LINE_SEPARATOR + statementInformation.getStatementQuery()); } SQLException e = null; long start = System.nanoTime(); try { eventListener.onBeforeAddBatch(statementInformation, sql); delegate.addBatch(sql); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterAddBatch(statementInformation, System.nanoTime() - start, sql, e); } }
private String getSql(StatementInformation statementInformation) { return StringUtils.hasText(statementInformation.getSqlWithValues()) ? statementInformation.getSqlWithValues() : statementInformation.getSql(); }
@Override public String getSqlWithValues() { return getSql(); }
/** {@inheritDoc} */ @Override public ConnectionInformation getConnectionInformation() { return this.statementInformation.getConnectionInformation(); } }
@Override public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { statementInformation.setStatementQuery(sql); SQLException e = null; long start = System.nanoTime(); try { eventListener.onBeforeExecute(statementInformation, sql); return delegate.execute(sql, autoGeneratedKeys); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterExecute(statementInformation, System.nanoTime() - start, sql, e); } }
@Override public void onAfterExecuteQuery(StatementInformation statementInformation, long timeElapsedNanos, String sql, SQLException e) { statementInformation.incrementTimeElapsed(timeElapsedNanos); }
public ResultSetInformation(final StatementInformation statementInformation) { this.statementInformation = statementInformation; this.query = statementInformation.getStatementQuery(); }
@Override public void onBeforeAnyExecute(StatementInformation statementInformation) { assertThat("sql of statementInformation", statementInformation.getSql(), is(notNullValue())); } }, //
/** {@inheritDoc} */ @Override public ConnectionInformation getConnectionInformation() { return this.statementInformation.getConnectionInformation(); } }
@Override public boolean execute(String sql, int[] columnIndexes) throws SQLException { statementInformation.setStatementQuery(sql); SQLException e = null; long start = System.nanoTime(); try { eventListener.onBeforeExecute(statementInformation, sql); return delegate.execute(sql, columnIndexes); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterExecute(statementInformation, System.nanoTime() - start, sql, e); } }
@Override public void onAfterExecuteBatch(StatementInformation statementInformation, long timeElapsedNanos, int[] updateCounts, SQLException e) { statementInformation.incrementTimeElapsed(timeElapsedNanos); }
@Override public void addBatch(String sql) throws SQLException { if (statementInformation.getStatementQuery() == null) { statementInformation.setStatementQuery(sql); } else { statementInformation.setStatementQuery(sql + LINE_SEPARATOR + statementInformation.getStatementQuery()); } SQLException e = null; long start = System.nanoTime(); try { eventListener.onBeforeAddBatch(statementInformation, sql); delegate.addBatch(sql); } catch (SQLException sqle) { e = sqle; throw e; } finally { eventListener.onAfterAddBatch(statementInformation, System.nanoTime() - start, sql, e); } }
@Override public String getSql() { return getStatementQuery(); }
@Override public void onAfterAnyExecute(StatementInformation statementInformation, long timeElapsedNanos, SQLException e) { final Scope activeScope = tracingPlugin.getTracer().scopeManager().active(); if (activeScope != null) { final Span span = activeScope.span(); if (statementInformation.getConnectionInformation().getDataSource() instanceof DataSource && jdbcPlugin.isCollectSql()) { MetaData metaData = dataSourceUrlMap.get(statementInformation.getConnectionInformation().getDataSource()); Tags.PEER_SERVICE.set(span, metaData.serviceName); span.setTag("db.type", metaData.productName); span.setTag("db.user", metaData.userName); if (StringUtils.isNotEmpty(statementInformation.getSql())) { String sql = getSql(statementInformation.getSql(), statementInformation.getSqlWithValues()); Profiler.addIOCall(sql, timeElapsedNanos); span.setTag(AbstractExternalRequest.EXTERNAL_REQUEST_METHOD, getMethod(sql)); span.setTag(DB_STATEMENT, sql); } } tracingPlugin.getRequestMonitor().monitorStop(); } }
@Override public void onBeforeAnyExecute(StatementInformation statementInformation) { if (P6OutageOptions.getActiveInstance().getOutageDetection()) { P6OutageDetector.INSTANCE.registerInvocation(this, System.nanoTime(), "statement", statementInformation.getSqlWithValues(), statementInformation.getStatementQuery(), statementInformation.getConnectionInformation().getUrl()); } }
@Override public String getSqlWithValues() { return getSql(); }
@Override public void onBeforeAnyExecute(StatementInformation statementInformation) { String dataSourceName = dataSourceNameResolver.resolveDataSourceName(statementInformation.getConnectionInformation().getDataSource()); strategy.beforeQuery(statementInformation.getConnectionInformation(), statementInformation, dataSourceName); }