Skip to content

Commit

Permalink
Merge branch 'master' into spring-boot-starter
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/src/main/java/com/microsoft/applicationinsights/channel/concrete/inprocess/InProcessTelemetryChannel.java
#	core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionFileSystemOutput.java
#	core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionNetworkOutput.java
#	core/src/test/java/com/microsoft/applicationinsights/internal/channel/inprocess/InProcessTelemetryChannelTest.java
  • Loading branch information
gavlyukovskiy committed Mar 13, 2018
2 parents afe1d0c + 579eb5c commit dcadfc1
Show file tree
Hide file tree
Showing 234 changed files with 7,035 additions and 891 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ $RECYCLE.BIN/
/Backend/OrderService/build
/Backend/OrderService/.idea
Backend/OrderService/OrderService.iml

# VS Code Workspace settings
.vscode/settings.json
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# CHANGELOG

## Version 2.0.1
- Fix issue when dependency start time wasn't being recorded correctly
- Fixed #533 HTTP Dependency Telemetry now matches with .NET SDK
- Introduced public method `httpMethodFinishedWithPath(String identifier, String method, String path, String correlationId, String uri, String target, int result, long delta)`
to support instrumentation of Path of URI in HTTP requests.
- `httpMethodFinished(String identifier, String method, String correlationId, String uri, String target, int result, int delta)` is now marked as deprecated
- Logger Messages now being pushed as custom dimension when reporting exceptions via Loggers. (#400)
- Enhanced Log4j2 appender to support basic parameters including Filters, Layouts and includeException. (#348)
- Fixed performance issue on SDK startup.
- Fixed PageView telemetry data not being reported.
- Fixed Issue #526 (NPE in MapUtil.copy())
- Fixed Issue #513 (Memory leak in SDKShutdownActivity). This fix upgrades our Servlet version from 2.5 to 3.0. The SDK must now be run on an application server supporting Servlet 3.0.

## Version 2.0.0
- Upgraded logback dependency version to 1.2.3
- Improved FixedRateSampling so that it also supports Sampling Percentage set by users programmatically. Fixes [issue #535](https://github.com/Microsoft/ApplicationInsights-Java/issues/535)
- Fault Tolerance improvements: introducing retries and exponential backoff capabilities with disk persistence.
- [Issue #499](https://github.com/Microsoft/ApplicationInsights-Java/pull/499): Fix handling of NaN and +/-Infinity in JSON serializer
- [Issue #506](https://github.com/Microsoft/ApplicationInsights-Java/pull/506): Null Reference Check causing Null Pointer Exception in `TelemetryCorrelationUtils.java`

## Version 2.0.0-BETA
- Updating various dependencies to latest version
- Introducing public class CustomClassWriter in Agent to enable finding common super classes used for Agent instrumentation without loading it
Expand Down
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# ApplicationInsights-Java
# Application Insights for Java
| Build & Unit Tests | Smoke Tests |
:-:|:-:
| ![Build + Unit Tests](https://mseng.visualstudio.com/_apis/public/build/definitions/96a62c4a-58c2-4dbb-94b6-5979ebc7f2af/5311/badge "Build & Unit Tests' Status") | ![Smoke Tests](https://mseng.visualstudio.com/_apis/public/build/definitions/96a62c4a-58c2-4dbb-94b6-5979ebc7f2af/6159/badge "Smoke Tests' Status") |

## Introduction

This is the repository of the Java SDK for [Visual Studio Application Insights](https://acom-prod-uswest-01.azurewebsites.net/documentation/articles/app-insights-overview/). Application Insights is a service that monitors the availability, performance and usage of your application. The SDK sends telemetry about the performance and usage of your app to the Application Insights service where your data can be visualized in the [Azure Portal](https://portal.azure.com). The SDK automatically collects telemetry about HTTP requests, dependencies, and exceptions. You can also use the SDK to send your own events and trace logs.
This is the repository of the Java SDK for [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/). Application Insights is a service that monitors the availability, performance and usage of your application. The SDK sends telemetry about the performance and usage of your app to the Application Insights service where your data can be visualized in the [Azure Portal](https://portal.azure.com). The SDK automatically collects telemetry about HTTP requests, dependencies, and exceptions. You can also use the SDK to send your own events and trace logs.

Please refer to:
For more information please refer to:

* [Get started with Application Insights in a Java web project](https://azure.microsoft.com/documentation/articles/app-insights-java-get-started/)
* [Getting started with Application Insights in a Java web project](https://azure.microsoft.com/documentation/articles/app-insights-java-get-started/)
* [Application Insights overview](https://azure.microsoft.com/services/application-insights/)

The following packages are built in this repository:
Expand All @@ -19,7 +22,7 @@ The following packages are built in this repository:

## To upgrade to the latest SDK

After you upgrade, you'll need to merge back any customizations you made to ApplicationInsights.xml. Take a copy of it to compare with the new file.
After you upgrade, you'll need to merge back any customizations you made to `ApplicationInsights.xml`. Take a copy of it to compare with the new file.

*If you're using Maven or Gradle*

Expand All @@ -28,10 +31,28 @@ After you upgrade, you'll need to merge back any customizations you made to Appl

*Otherwise*

* Download the latest version of [Application Insights Java SDK](https://aka.ms/aijavasdk) and replace the old ones.
* Download the latest version of [Application Insights Java SDK](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-get-started), [scroll down to the getting started section](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-get-started) and follow the instructions to manually download the SDK and replace the old `.jar` files.

Compare the old and new `ApplicationInsights.xml`. Many of the changes you see are because we added and removed modules. Reinstate any customizations that you made.

## Application Insights for Java Roadmap
The Application Insights team have been hard at work to deliver the next wave of features for our Java support and experience. Below is an outline of the features and improvements that are planned for our next several releases, which are targeted to be completed for mid-year 2018.

### Application Insights for Java SDK 2.0
In December [we released the beta version of the Application Insights for Java 2.0 SDK](https://github.com/Microsoft/ApplicationInsights-Java/releases/tag/v2.0.0-BETA). That release introduced support for cross-component telemetry correlation and fixed rate sampling. For the final release, we'll be addressing any reliability issues that are found or reported.

### Documentation Improvements
The Application Insights team believes that documentation is important to the overall successfulness of our users. As such, we strive to continually improve our documentation. The full list of [documentation changes](https://github.com/Microsoft/ApplicationInsights-Java/issues?q=is%3Aissue+is%3Aopen+label%3A%22Documentation+Changes%22) can be found in our [issue tracker](https://github.com/Microsoft/ApplicationInsights-Java/issues). Feel free to [open a new issue](https://github.com/Microsoft/ApplicationInsights-Java/issues/new) to report incorrect or unclear documentation.

### Spring Boot Starter
The Spring Boot framework is wildly popular, and while Application Insights for Java already supports Spring Boot, we'd like to make it easier to get started with. To do that, we're going to be releasing a [Spring Boot Starter](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-starter) in the coming months.

### Adaptive Sampling
While our 2.0 SDK will provide full support for fixed rate sampling, we plan to add support for adaptive sampling. Adaptive sampling provides fine-grained controls over a variable sampling rate when traffic to an application fluctuates and finding a fixed rate to sample with would otherwise be difficult.

### Support for Java 9
The Application Insights for Java SDK currently supports Java 7 and 8. We are working to bring full support for customers who have upgraded their applications to Java 9 as well.


## Microsoft Open Source Code of Conduct

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void premain(String args, Instrumentation inst) {
appendJarsToBootstrapClassLoader(inst);
initializeCodeInjector(inst);
} catch (Throwable throwable) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Agent is NOT activated: failed to load to bootstrap class loader: " + throwable.getMessage());
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Agent is NOT activated: failed to load to bootstrap class loader: %s", throwable.toString());
throwable.printStackTrace();
System.exit(-1);
}
Expand Down Expand Up @@ -100,7 +100,7 @@ private static void initializeCodeInjector(Instrumentation inst) throws Throwabl
}
inst.addTransformer(codeInjector);
} catch (Exception e) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Failed to load the code injector, exception: %s", e.getMessage());
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Failed to load the code injector, exception: %s", e.toString());
throw e;
}
}
Expand All @@ -113,7 +113,7 @@ private static void appendJarsToBootstrapClassLoader(Instrumentation inst) throw
for (File file : agentFolder.listFiles()) {
if (file.getName().indexOf(AGENT_JAR_PREFIX) != -1) {
agentJarName = file.getName();
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO,"Agent jar name is " + agentJarName);
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO,"Agent jar name is %s", agentJarName);
break;
}
}
Expand All @@ -123,7 +123,7 @@ private static void appendJarsToBootstrapClassLoader(Instrumentation inst) throw
throw new RuntimeException("Could not find agent jar");
}

InternalAgentLogger.INSTANCE.info("Found jar: " + agentJarPath + " " + agentJarName);
InternalAgentLogger.INSTANCE.info("Found jar: %s %s", agentJarPath, agentJarName);

URL configurationURL = new URL(agentJarPath + agentJarName);

Expand All @@ -142,7 +142,7 @@ public static String getAgentJarLocation() throws UnsupportedEncodingException {
String urlPath = url.getPath();

if (urlPath.indexOf(AGENT_JAR_PREFIX) != -1) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO,"Agent jar found at " + urlPath);
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO,"Agent jar found at %s", urlPath);
int index = urlPath.lastIndexOf('/');
urlPath = urlPath.substring(0, index + 1);
return urlPath;
Expand All @@ -151,7 +151,7 @@ public static String getAgentJarLocation() throws UnsupportedEncodingException {
}
}
} catch (Throwable throwable) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Error while trying to fetch Jar Location, Exception: " + throwable.getMessage());
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Error while trying to fetch Jar Location, Exception: %s", throwable.toString());
}

String stringPath = AgentImplementation.class.getProtectionDomain().getCodeSource().getLocation().getPath();
Expand Down Expand Up @@ -198,13 +198,13 @@ private static void SetNonWebAppModeIfAskedByConf(String sdkPath) throws Throwab
throw new Exception(errorMessage);
}

InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.TRACE, "Found jar: " + coreJarName);
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.TRACE, "Found jar: %s", coreJarName);

JarFile jarFile = null;
try {
jarFile = new JarFile(coreJarName);
} catch (IOException e) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Could not load jar: " + coreJarName);
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Could not load jar: %s", coreJarName);
throw e;
}
Enumeration<JarEntry> e = jarFile.entries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CodeInjector(AgentConfiguration agentConfiguration) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "Agent is up");
} catch (Throwable throwable) {
throwable.printStackTrace();
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "Agent is NOT activated: failed to initialize CodeInjector: '%s'", throwable.getMessage());
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.INFO, "Agent is NOT activated: failed to initialize CodeInjector: '%s'", throwable.toString());
}
}

Expand All @@ -81,7 +81,7 @@ public byte[] transform(
return byteCodeTransformer.transform(originalBuffer, className, loader);
} catch (Throwable throwable) {
throwable.printStackTrace();
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Failed to instrument '%s', exception: '%s': ", className, throwable.getMessage());
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Failed to instrument '%s', exception: '%s': ", className, throwable.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public DefaultByteCodeTransformer getAndRemove(String className) {
ClassInstrumentationData newClassInstrumentationData = new ClassInstrumentationData(className, classInstrumentationData.getClassType(), classInstrumentationData.getClassVisitorFactory());
newClassInstrumentationData.setMethodInstrumentationInfo(classInstrumentationData.getMethodInstrumentationInfo());
classInstrumentationData = newClassInstrumentationData;
InternalAgentLogger.INSTANCE.trace("Adding " + classInstrumentationData.getFullPackageName());
InternalAgentLogger.INSTANCE.trace("Adding %s", classInstrumentationData.getFullPackageName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
*/
public final class HttpClientMethodVisitor extends AbstractHttpMethodVisitor {

private final static String FINISH_DETECT_METHOD_NAME = "httpMethodFinished";
private final static String FINISH_METHOD_RETURN_SIGNATURE = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IJ)V";
private final static String FINISH_DETECT_METHOD_NAME = "httpMethodFinishedWithPath";
private final static String FINISH_METHOD_RETURN_SIGNATURE = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IJ)V";

public HttpClientMethodVisitor(int access,
String desc,
Expand All @@ -50,6 +50,8 @@ public HttpClientMethodVisitor(int access,
private int childIdLocal;
private int correlationContextLocal;
private int appCorrelationId;
private int target;
private int path;

@Override
public void onMethodEnter() {
Expand Down Expand Up @@ -87,21 +89,37 @@ public void onMethodEnter() {
mv.visitLdcInsn("Request-Context");
mv.visitVarInsn(ALOAD, appCorrelationId);
mv.visitMethodInsn(INVOKEINTERFACE, "org/apache/http/HttpRequest", "addHeader", "(Ljava/lang/String;Ljava/lang/String;)V", true);


//Load HttpUriRequest instance into Local Array. Contains information of Path and Host
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEINTERFACE, "org/apache/http/HttpRequest", "getRequestLine", "()Lorg/apache/http/RequestLine;", true);
int requestLineLocal = this.newLocal(Type.getType(Object.class));
mv.visitVarInsn(ASTORE, requestLineLocal);
mv.visitMethodInsn(INVOKEINTERFACE, "org/apache/http/client/methods/HttpUriRequest", "getURI", "()Ljava/net/URI;", true);
int uri = this.newLocal(Type.getType(Object.class));
mv.visitVarInsn(ASTORE, uri);

mv.visitVarInsn(ALOAD, requestLineLocal);
mv.visitMethodInsn(INVOKEINTERFACE, "org/apache/http/RequestLine", "getMethod", "()Ljava/lang/String;", true);
//Get Method Name from HttpUriLRequest interface object
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEINTERFACE, "org/apache/http/client/methods/HttpUriRequest", "getMethod", "()Ljava/lang/String;", true);
methodLocal = this.newLocal(Type.getType(Object.class));
mv.visitVarInsn(ASTORE, methodLocal);

mv.visitVarInsn(ALOAD, requestLineLocal);
mv.visitMethodInsn(INVOKEINTERFACE, "org/apache/http/RequestLine", "getUri", "()Ljava/lang/String;", true);
//Use HttpUriRequest instance loaded to retrieve the target(aka host name) from java.net.URI class
mv.visitVarInsn(ALOAD, uri);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/net/URI", "getHost", "()Ljava/lang/String;", false);
target = this.newLocal(Type.getType(Object.class));
mv.visitVarInsn(ASTORE, target);

//Get the URL String from URI object
mv.visitVarInsn(ALOAD, uri);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/net/URI", "toString", "()Ljava/lang/String;", false);
uriLocal = this.newLocal(Type.getType(Object.class));
mv.visitVarInsn(ASTORE, uriLocal);

//Use HttpUriRequest instance loaded to retrieve the path(relative URL) from java.net.URI class
mv.visitVarInsn(ALOAD, uri);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/net/URI", "getPath", "()Ljava/lang/String;", false);
path = this.newLocal(Type.getType(Object.class));
mv.visitVarInsn(ASTORE, path);

}

protected TempVar duplicateTopStackToTempVariable(Type typeOfTopElementInStack) {
Expand Down Expand Up @@ -157,11 +175,13 @@ protected void byteCodeForMethodExit(int opcode) {
mv.visitVarInsn(ASTORE, targetLocal);

mv.visitFieldInsn(Opcodes.GETSTATIC, internalName, "INSTANCE", "L" + internalName + ";");

mv.visitLdcInsn(getMethodName());
mv.visitVarInsn(ALOAD, methodLocal);
mv.visitVarInsn(ALOAD, path); //load path parameter
mv.visitVarInsn(ALOAD, childIdLocal);
mv.visitVarInsn(ALOAD, uriLocal);
mv.visitVarInsn(ALOAD, targetLocal);
mv.visitVarInsn(ALOAD, targetLocal); //using derived target
mv.visitVarInsn(ILOAD, statusCodeLocal);
mv.visitVarInsn(LLOAD, deltaInNS);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, internalName, FINISH_DETECT_METHOD_NAME, FINISH_METHOD_RETURN_SIGNATURE, false);
Expand All @@ -175,9 +195,10 @@ protected void byteCodeForMethodExit(int opcode) {
mv.visitFieldInsn(Opcodes.GETSTATIC, internalName, "INSTANCE", "L" + internalName + ";");
mv.visitLdcInsn(getMethodName());
mv.visitVarInsn(ALOAD, methodLocal);
mv.visitVarInsn(ALOAD, path); //load path parameter
mv.visitVarInsn(ALOAD, childIdLocal);
mv.visitVarInsn(ALOAD, uriLocal);
mv.visitInsn(ACONST_NULL);
mv.visitVarInsn(ALOAD, target); //using the derived target from java.net.URI
mv.visitVarInsn(ILOAD, statusCodeLocal);
mv.visitVarInsn(LLOAD, deltaInNS);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, internalName, FINISH_DETECT_METHOD_NAME, FINISH_METHOD_RETURN_SIGNATURE, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public MethodVisitor create(MethodInstrumentationDecision decision, int access,

classesToInstrument.put(RUNTIME_EXCEPTION_CLASS_NAME, data);
} catch (Throwable t) {
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Failed to load instrumentation for Jedis: '%s':'%s'", t.getClass().getName(), t.getMessage());
InternalAgentLogger.INSTANCE.logAlways(InternalAgentLogger.LoggingLevel.ERROR, "Failed to load instrumentation for Jedis: '%s'", t.toString());
}
}
}
Loading

0 comments on commit dcadfc1

Please sign in to comment.