Skip to content

Commit

Permalink
Instrument new version of postgres - Fix postgresql prepared statemen…
Browse files Browse the repository at this point in the history
…t instrumentation (#846)

* WIP: Fix postgres instrumentation

#749

* Fixes for PG prepared statement signature

* Fixes for PG prepared statement signature

* Use single ctor

* Add note on changes needed to add other pg constructor

* Clean up

* Remove note about unused constructor

* Update changelog

* Update application version

* Update application version to 2.5.0

* Fix version
  • Loading branch information
luigibk authored and dhaval24 committed Mar 15, 2019
1 parent a37e109 commit 00f384f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

# Version 2.4.0 (Unreleased)
- Fixed [#749](https://github.com/Microsoft/ApplicationInsights-Java/issues/749) introduce support for postgresql jdbc4 prepared statements.
- Introduced support for Manual Async and Explicit Multithreading correlation.
- Introduced `setRequestTelemetryContext` API in `WebTelemetryModule` Interface.
- Introduced experimental API's `AIHttpServletListner`, `HttpServerHandler`, `ApplicationInsightsServletExtractor`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
Expand All @@ -41,6 +42,10 @@
* Created by gupele on 8/3/2015.
*/
public final class PreparedStatementClassDataProvider {

public static final String POSTGRESQL_JDBC2_STATEMENT = "org/postgresql/jdbc2/AbstractJdbc2Statement";
public static final String POSTGRESQL_JDBC4_STATEMENT = "org/postgresql/jdbc/PgPreparedStatement";

private final Map<String, ClassInstrumentationData> classesToInstrument;

public PreparedStatementClassDataProvider(Map<String, ClassInstrumentationData> classesToInstrument) {
Expand All @@ -59,8 +64,10 @@ public void add() {
factory = classFactoryForMySql();
doAdd(factory, "com/mysql/jdbc/PreparedStatement");

factory = classFactoryForPostgreSql();
doAdd(factory, "org/postgresql/jdbc2/AbstractJdbc2Statement");
factory = classFactoryForJdbc2PostgreSql();
doAdd(factory, POSTGRESQL_JDBC2_STATEMENT);
factory = classFactoryForJdbc4PostgreSql();
doAdd(factory, POSTGRESQL_JDBC4_STATEMENT);

factory = classFactoryForOracle();
doAdd(factory, "oracle/jdbc/driver/OraclePreparedStatement");
Expand Down Expand Up @@ -218,20 +225,30 @@ public ClassVisitor create(ClassInstrumentationData classInstrumentationData, Cl
return classVisitorFactory;
}

private ClassVisitorFactory classFactoryForPostgreSql() {

ClassVisitorFactory classVisitorFactory = new ClassVisitorFactory() {
private ClassVisitorFactory classFactoryForJdbc2PostgreSql() {
return new ClassVisitorFactory() {
@Override
public ClassVisitor create(ClassInstrumentationData classInstrumentationData, ClassWriter classWriter) {
HashSet<String> ctorSignatures = new HashSet<String>();
Set<String> ctorSignatures = new HashSet<String>();
ctorSignatures.add("(Lorg/postgresql/jdbc2/AbstractJdbc2Connection;Ljava/lang/String;ZII)V");
final PreparedStatementMetaData metaData1 = new PreparedStatementMetaData(ctorSignatures);
metaData1.sqlStringInCtor = 2;
return new PreparedStatementClassVisitor(classInstrumentationData, classWriter, metaData1);
}
};
}

return classVisitorFactory;
private ClassVisitorFactory classFactoryForJdbc4PostgreSql() {
return new ClassVisitorFactory() {
@Override
public ClassVisitor create(ClassInstrumentationData classInstrumentationData, ClassWriter classWriter) {
Set<String> ctorSignatures = new HashSet<String>();
ctorSignatures.add("(Lorg/postgresql/jdbc/PgConnection;Ljava/lang/String;III)V");
final PreparedStatementMetaData metaData1 = new PreparedStatementMetaData(ctorSignatures);
metaData1.sqlStringInCtor = 2;
return new PreparedStatementClassVisitor(classInstrumentationData, classWriter, metaData1);
}
};
}

private ClassVisitorFactory classFactoryForOracle() {
Expand Down

0 comments on commit 00f384f

Please sign in to comment.