Skip to content

Commit

Permalink
Merge pull request #304 from newrelic/feature/external-conn/jtds
Browse files Browse the repository at this point in the history
[NR-288603] Report external connections for JDBC, JTDS based Databases
  • Loading branch information
IshikaDawda authored Nov 6, 2024
2 parents 13201d9 + a05c217 commit df126a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package java.sql;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.JdbcHelper;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

import java.util.Properties;

@Weave(originalName = "java.sql.Driver", type = MatchType.Interface)
public class Driver_Instrumentation {

public Connection connect(String url, Properties info) throws SQLException {
Connection connection = Weaver.callOriginal();
if (connection != null && connection.getMetaData() != null) {
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, connection.getMetaData().getURL(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), JdbcHelper.JDBC_GENERIC);
}
return connection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.JdbcHelper;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.JDBCVendor;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -31,6 +32,7 @@ public abstract class DataSource_Weaved {
private void postHookProcessing(Connection connection) {
try {
String vendor;
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, connection.getMetaData().getURL(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), JdbcHelper.JDBC_GENERIC);
if(NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
vendor = NewRelicSecurity.getAgent().getSecurityMetaData().getCustomAttribute(JDBCVendor.META_CONST_JDBC_VENDOR, String.class);
if(vendor == null || vendor.trim().isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.JdbcHelper;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.JDBCVendor;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -25,6 +26,7 @@ public class Driver_Instrumentation {
private void postHookProcessing(Connection connection) {
try {
String vendor;
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, connection.getMetaData().getURL(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), JdbcHelper.JDBC_JTDS_GENERIC);
if(NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
vendor = NewRelicSecurity.getAgent().getSecurityMetaData().getCustomAttribute(JDBCVendor.META_CONST_JDBC_VENDOR, String.class);
if(vendor == null || vendor.trim().isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.JdbcHelper;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.JDBCVendor;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -23,6 +24,7 @@ public abstract class JtdsDataSource_Instrumentation {
private void postHookProcessing(Connection connection) {
try {
String vendor;
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, connection.getMetaData().getURL(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), JdbcHelper.JDBC_JTDS_GENERIC);
if(NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
vendor = NewRelicSecurity.getAgent().getSecurityMetaData().getCustomAttribute(JDBCVendor.META_CONST_JDBC_VENDOR, String.class);
if(vendor == null || vendor.trim().isEmpty()){
Expand Down

0 comments on commit df126a7

Please sign in to comment.