/** * 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(); }
/** {@inheritDoc} */ @Override public ConnectionInformation getConnectionInformation() { return this.statementInformation.getConnectionInformation(); } }
@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 onBeforeAnyAddBatch(StatementInformation statementInformation) { if (P6OutageOptions.getActiveInstance().getOutageDetection()) { P6OutageDetector.INSTANCE.registerInvocation(this, System.nanoTime(), "batch", statementInformation.getSqlWithValues(), statementInformation.getStatementQuery(), statementInformation.getConnectionInformation().getUrl()); } }
@Override public void onBeforeAnyExecute(StatementInformation statementInformation) { if (P6OutageOptions.getActiveInstance().getOutageDetection()) { P6OutageDetector.INSTANCE.registerInvocation(this, System.nanoTime(), "statement", statementInformation.getSqlWithValues(), statementInformation.getStatementQuery(), statementInformation.getConnectionInformation().getUrl()); } }
/** {@inheritDoc} */ @Override public ConnectionInformation getConnectionInformation() { return this.statementInformation.getConnectionInformation(); } }
@Override public void onBeforeAnyExecute(StatementInformation statementInformation) { String dataSourceName = dataSourceNameResolver.resolveDataSourceName(statementInformation.getConnectionInformation().getDataSource()); strategy.beforeQuery(statementInformation.getConnectionInformation(), statementInformation, dataSourceName); }
@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 onBeforeAnyExecute(StatementInformation statementInformation) { if (P6OutageOptions.getActiveInstance().getOutageDetection()) { P6OutageDetector.INSTANCE.registerInvocation(this, System.nanoTime(), "statement", statementInformation.getSqlWithValues(), statementInformation.getStatementQuery(), statementInformation.getConnectionInformation().getUrl()); } }
@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(); } }