Skip to content

Commit

Permalink
Merge pull request #307 from newrelic/feature/external-conn/r2dbc
Browse files Browse the repository at this point in the history
[NR-288604] ExternalConnection reporting for R2DBC driver
  • Loading branch information
IshikaDawda authored Nov 6, 2024
2 parents df126a7 + 43f72a3 commit d392dd4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.r2dbc.h2.client;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.R2DBCVendor;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import org.h2.engine.ConnectionInfo;

@Weave(type = MatchType.ExactClass, originalName = "io.r2dbc.h2.client.SessionClient")
public class SessionClient_Instrumentation {

public SessionClient_Instrumentation(ConnectionInfo connectionInfo, boolean shutdownDatabaseOnClose) {
if (NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(R2DBCVendor.META_CONST_R2DBC_VENDOR, R2DBCVendor.H2);
}
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, connectionInfo.getURL(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), "R2DBC-H2");
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package org.mariadb.r2dbc;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.R2DBCVendor;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import org.mariadb.r2dbc.api.MariadbConnection;
import reactor.core.publisher.Mono;

@Weave(type = MatchType.Interface, originalName = "org.mariadb.r2dbc.MariadbConnectionFactory")
import java.net.SocketAddress;

@Weave(type = MatchType.ExactClass, originalName = "org.mariadb.r2dbc.MariadbConnectionFactory")
public class MariadbConnectionFactory_Instrumentation {

private final SocketAddress endpoint = Weaver.callOriginal();
private final MariadbConnectionConfiguration configuration = Weaver.callOriginal();

public Mono<MariadbConnection> create() {
if (NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(R2DBCVendor.META_CONST_R2DBC_VENDOR, R2DBCVendor.MARIA_DB);
}
NewRelicSecurity.getAgent().recordExternalConnection(configuration.getHost(), configuration.getPort(), endpoint.toString(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), "R2DBC-MARIADB");
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.r2dbc.mssql.client;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.R2DBCVendor;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
Expand All @@ -15,6 +16,7 @@ public static Mono<ReactorNettyClient> connect(ClientConfiguration configuration
if (NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(R2DBCVendor.META_CONST_R2DBC_VENDOR, R2DBCVendor.MSSQL);
}
NewRelicSecurity.getAgent().recordExternalConnection(configuration.getHost(), configuration.getPort(), null, null, ExternalConnectionType.DATABASE_CONNECTION.name(), "R2DBC-MSSQL");
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.miku.r2dbc.mysql.client;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.R2DBCVendor;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
Expand All @@ -15,11 +16,13 @@

@Weave(type = MatchType.Interface, originalName = "dev.miku.r2dbc.mysql.client.Client")
public class Client_Instrumentation {

public static Mono<Client> connect(
MySqlSslConfiguration ssl, SocketAddress address, boolean tcpKeepAlive, boolean tcpNoDelay, ConnectionContext context, @Nullable Duration connectTimeout) {
if (NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(R2DBCVendor.META_CONST_R2DBC_VENDOR, R2DBCVendor.MYSQL);
}
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, address.toString(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), "R2DBC-MYSQL");
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package oracle.r2dbc.impl;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.R2DBCVendor;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.WeaveAllConstructors;
import com.newrelic.api.agent.weaver.Weaver;

import java.sql.SQLException;

@Weave(originalName = "oracle.r2dbc.impl.OracleConnectionImpl")
final class OracleConnectionImpl_Instrumentation {

private final java.sql.Connection jdbcConnection = Weaver.callOriginal();

@WeaveAllConstructors
OracleConnectionImpl_Instrumentation() {
if (NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(R2DBCVendor.META_CONST_R2DBC_VENDOR, R2DBCVendor.ORACLE);
}
try {
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, jdbcConnection.getMetaData().getURL(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), "R2DBC-ORACLE");
} catch (SQLException e) {
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format("Instrumentation library: %s, Error while detecting external connection : %s", "R2DBC-ORACLE", e.getMessage()), e, this.getClass().getName());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.r2dbc.postgresql.client;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ExternalConnectionType;
import com.newrelic.api.agent.security.schema.R2DBCVendor;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
Expand All @@ -10,10 +11,12 @@

@Weave(originalName = "io.r2dbc.postgresql.client.ReactorNettyClient")
public class ReactorNettyClient_Instrumentation {

public static Mono<ReactorNettyClient> connect(SocketAddress socketAddress, ConnectionSettings settings){
if (NewRelicSecurity.isHookProcessingActive() && !NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(R2DBCVendor.META_CONST_R2DBC_VENDOR, R2DBCVendor.POSTGRES);
}
NewRelicSecurity.getAgent().recordExternalConnection(null, -1, socketAddress.toString(), null, ExternalConnectionType.DATABASE_CONNECTION.name(), "R2DBC-POSTGRESQL");
return Weaver.callOriginal();
}
}

0 comments on commit d392dd4

Please sign in to comment.