Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fixing forever loop if something is in illegal state. … #405

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fcdd087
- Fixing potentially for ever loop if something is in illegal state. …
andresol Aug 7, 2017
2281a85
Increasing version number to 1.0.10
Dmitry-Matveev Aug 15, 2017
d7d800d
Merge pull request #408 from Microsoft/dmitmatv_110
Dmitry-Matveev Aug 15, 2017
1e28bc3
Adding ThirdPartyNotices.txt
Dmitry-Matveev Aug 15, 2017
958eee5
Addressing comments in TPN.txt
Dmitry-Matveev Aug 15, 2017
21d4b1f
Merge pull request #409 from Microsoft/dmitmatv_TPN
Dmitry-Matveev Aug 15, 2017
d7959b6
fixes custom timestamp bug
adnanyaqoobvirk Aug 19, 2017
6483a3c
Add second environment variable to configure ikey
c-w Aug 21, 2017
27ad0a3
Fix header markdown for rendering on Github
c-w Aug 21, 2017
83bb635
Add changelog entry for new environment variable
c-w Aug 21, 2017
28dec6f
Merge pull request #413 from c-w/feature/second-ikey-envvar
Dmitry-Matveev Aug 21, 2017
e9118ac
adds custom telemetry timestamp test
adnanyaqoobvirk Aug 22, 2017
39f473b
Merge pull request #412 from adnanyaqoobvirk/master
Dmitry-Matveev Aug 22, 2017
a0e8f43
Update ChangeLog
Dmitry-Matveev Aug 22, 2017
2559a4c
Just shutting down the transmissing when a illegal state exception oc…
andresol Aug 23, 2017
46fdca0
Merge pull request #414 from Microsoft/dmitmatv_changelog110
Dmitry-Matveev Aug 23, 2017
4dcc3e7
If a IllegalStateException occurs, we need to suspend. App will most …
andresol Aug 24, 2017
2aa19f9
Reverting remove null check in setSampleRate()
dhaval24 Aug 24, 2017
2fcfc95
fixing duration write method
dhaval24 Aug 24, 2017
7d02375
Updating readme for fixing telemetry pushing issue
dhaval24 Aug 24, 2017
70eb0d2
update null check location
dhaval24 Aug 24, 2017
8e221cf
Merge branch 'dhaval/RevertSetSampleRateNullCheck' of https://github.…
dhaval24 Aug 24, 2017
420ace2
Merge pull request #415 from Microsoft/dhaval/RevertSetSampleRateNull…
Dmitry-Matveev Aug 29, 2017
ca0a6a7
Delay retrying to send telemetry if an exception is hit
leantk Sep 7, 2017
cab4ab2
Fixing custom event sending bug
dhaval24 Sep 10, 2017
1f0805a
adding test case for sanitization
dhaval24 Sep 10, 2017
46fc0e4
Fixing reliability issue with JedisMethodVisitor. (#423)
grlima Sep 12, 2017
cc310f7
adding missing escape character \' and missing test
dhaval24 Sep 12, 2017
bad01c5
fixing previous commit test case
dhaval24 Sep 12, 2017
1fd87c2
resolving merge conflict
dhaval24 Sep 12, 2017
7beafc5
Merge branch 'master' into dhdoshi/sanitizeJSON
dhaval24 Sep 12, 2017
1f60a64
Adding truncate methods removing unnecessary test as following covers…
dhaval24 Sep 13, 2017
819f72a
reducing scope to package-private, fixing corner case and generalizin…
dhaval24 Sep 13, 2017
f33c220
Making CHANGELOG.md more human friendly
dhaval24 Sep 14, 2017
0de2fc2
Merge pull request #421 from Microsoft/dhdoshi/sanitizeJSON
dhaval24 Sep 14, 2017
0c99bb6
Changed back to default backoff time.
andresol Sep 15, 2017
af83baf
Updated changelog
leantk Sep 15, 2017
cbdef0c
Merge pull request #420 from leantk/users/leantk/backoff
dhaval24 Sep 15, 2017
59ff210
- Fixing potentially for ever loop if something is in illegal state. …
andresol Aug 7, 2017
23b273e
If a IllegalStateException occurs, we need to suspend. App will most …
andresol Aug 24, 2017
aeb8c38
Merge remote-tracking branch 'origin/master'
andresol Sep 18, 2017
322f477
Removing unused parameter.
andresol Sep 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#CHANGELOG
# CHANGELOG

## Version 1.0.10
- Fixed issue #403 (Exceeding property length invalidates custom event)
- Fixed issue #401 (Custom key and property sanitized)
- Fixed Request Telemetry Sending bug with new schema.
- Fixed reliability issue with Jedis client dependency collector
- Fixed Request Telemetry Sending bug with new schema
- Schema updated to the latest version. Changes in internal namespace `core/src/main/java/com/microsoft/applicationinsights/internal/schemav2`.
- Class `SendableData` in internal namespace deleted.
- Class `com.microsoft.applicationinsights.telemetry.BaseSampleSourceTelemetry` takes generic class qualifier `Domain` instead of `SendableData`.
- Class `com.microsoft.applicationinsights.telemetry.BaseTelemetry` takes generic class qualifier `Domain` instead of `SendableData`.
- Methods `getExceptionHandledAt` and `setExceptionHandledAt` of `ExceptionTelemetry` marked obsolete and do not do anything.
- Obsolete methods of `RemoteDependencyTelemetry`: `getCount`, `setCount`, `getMin`, `setMin`, `getMax`, `setMax`, `getStdDev`, `setStdDev`, `getDependencyKind`, `setDependencyKind`, `getAsync`, `setAsync`, `getDependencySource`, `setDependencySource`.
- Obsolete methods of `RequestTelemetry`: `getHttpMethod`, `setHttpMethod`.
- Add option to configure instrumentation key via `APPINSIGHTS_INSTRUMENTATIONKEY` environment variable for consistency with other SDKs.
- Fix the issue where `track(...)` of `TelemetryClient` class was overwriting the provided telemetry timestamp.
- Changed the policy on failed sent requests to delay retrying for 5 minutes instead of immediately retrying.

## Version 1.0.9
- Fix the issue of infinite retry and connection drain on certificate error by updating the version of http client packaged with the SDK.
Expand Down
607 changes: 607 additions & 0 deletions ThirdPartyNotices.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public DefaultMethodVisitor(MethodInstrumentationDecision decision,
protected void byteCodeForMethodExit(int opcode) {

Object[] args = null;
String methodSignature = FINISH_METHOD_DEFAULT_SIGNATURE;
String methodSignature = getOnExitMethodDefaultSignature();
switch (translateExitCode(opcode)) {
case EXIT_WITH_EXCEPTION:
args = new Object[] { getMethodName(), duplicateTopStackToTempVariable(Type.getType(Throwable.class)) };
methodSignature = FINISH_METHOD_EXCEPTION_SIGNATURE;
methodSignature = getOnExitMethodExceptionSignature();
break;

case EXIT_WITH_RETURN_VALUE:
Expand All @@ -103,7 +103,7 @@ protected void byteCodeForMethodExit(int opcode) {
}

if (args != null) {
activateEnumMethod(ImplementationsCoordinator.class, FINISH_DETECT_METHOD_NAME, methodSignature, args);
activateEnumMethod(ImplementationsCoordinator.class, getOnExitMethodName(), methodSignature, args);
}
}

Expand Down Expand Up @@ -143,8 +143,28 @@ protected void onMethodEnter() {

activateEnumMethod(
ImplementationsCoordinator.class,
START_DETECT_METHOD_NAME,
START_DETECT_METHOD_SIGNATURE,
getOnEnterMethodName(),
getOnEnterMethodSignature(),
getMethodName());
}

protected String getOnEnterMethodName() {
return START_DETECT_METHOD_NAME;
}

protected String getOnEnterMethodSignature() {
return START_DETECT_METHOD_SIGNATURE;
}

protected String getOnExitMethodName() {
return FINISH_DETECT_METHOD_NAME;
}

protected String getOnExitMethodDefaultSignature() {
return FINISH_METHOD_DEFAULT_SIGNATURE;
}

protected String getOnExitMethodExceptionSignature() {
return FINISH_METHOD_EXCEPTION_SIGNATURE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public JedisClassDataProvider(Map<String, ClassInstrumentationData> classesToIns
public void add() {
try {
ClassInstrumentationData data =
new ClassInstrumentationData(JEDIS_CLASS_NAME, InstrumentedClassType.OTHER)
new ClassInstrumentationData(JEDIS_CLASS_NAME, InstrumentedClassType.Redis)
.setReportCaughtExceptions(false)
.setReportExecutionTime(true);
MethodVisitorFactory methodVisitorFactory = new MethodVisitorFactory() {
@Override
public MethodVisitor create(MethodInstrumentationDecision decision, int access, String desc, String owner, String methodName, MethodVisitor methodVisitor, ClassToMethodTransformationData additionalData) {
return new JedisMethodVisitor(access, desc, JEDIS_CLASS_NAME, methodName, methodVisitor, additionalData);
return new JedisMethodVisitorV2(access, desc, JEDIS_CLASS_NAME, methodName, methodVisitor, additionalData);
}
};
data.addAllMethods(false, true, methodVisitorFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;


/**
* Created by gupele on 8/6/2015.
* @deprecated Replaced with JedisMethodVisitorV2
*/
@Deprecated
final class JedisMethodVisitor extends DefaultMethodVisitor {
private final static String FINISH_DETECT_METHOD_NAME = "methodFinished";
private final static String FINISH_METHOD_DEFAULT_SIGNATURE = "(Ljava/lang/String;J[Ljava/lang/Object;Ljava/lang/Throwable;)V";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* ApplicationInsights-Java
* Copyright (c) Microsoft Corporation
* All rights reserved.
*
* MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the ""Software""), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package com.microsoft.applicationinsights.agent.internal.agent.redis;

import com.microsoft.applicationinsights.agent.internal.agent.DefaultMethodVisitor;
import com.microsoft.applicationinsights.agent.internal.agent.ClassToMethodTransformationData;

import org.objectweb.asm.MethodVisitor;

/**
* The class is responsible for instrumenting Jedis client methods.
*/
final class JedisMethodVisitorV2 extends DefaultMethodVisitor {
private final static String ON_ENTER_METHOD_NAME = "jedisMethodStarted";
private final static String ON_ENTER_METHOD_SIGNATURE = "(Ljava/lang/String;)V";

public JedisMethodVisitorV2(int access,
String desc,
String owner,
String methodName,
MethodVisitor methodVisitor,
ClassToMethodTransformationData additionalData) {
super(false, true, 0, access, desc, owner, methodName, methodVisitor, additionalData);
}

@Override
protected String getOnEnterMethodName() {
return ON_ENTER_METHOD_NAME;
}

@Override
protected String getOnEnterMethodSignature() {
return ON_ENTER_METHOD_SIGNATURE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public interface AgentNotificationsHandler {
*/
void preparedStatementExecuteBatchMethodStarted(String classAndMethodNames, PreparedStatement statement, String sqlStatement, int batchCounter);

/**
* Called before methods in the Jedis client class are executed.
* @param classAndMethodNames The name of the class and method separated by '.'
*/
void jedisMethodStarted(String classAndMethodNames);

/**
* A 'regular' method enter. Non HTTP/SQL method
* @param classAndMethodNames The name of the class and method separated by '.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
public enum InstrumentedClassType {
SQL,
HTTP,
OTHER
OTHER,
Redis
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ public void sqlStatementMethodStarted(String name, Statement statement, String s
}
}

@Override
public void jedisMethodStarted(String name) {
try {
AgentNotificationsHandler implementation = getImplementation();
if (implementation != null) {
implementation.jedisMethodStarted(name);
}
} catch (Throwable t) {
}
}

@Override
public void methodStarted(String name) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ public void track(Telemetry telemetry) {
return;
}

telemetry.setTimestamp(new Date());
if (telemetry.getTimestamp() == null) {
telemetry.setTimestamp(new Date());
}

TelemetryContext ctx = this.getContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ public void httpMethodFinished(String identifier, String method, String uri, int
telemetryClient.track(telemetry);
}

@Override
public void jedisMethodStarted(String name) {
int index = name.lastIndexOf('#');
if (index != -1) {
name = name.substring(0, index);
}

startMethod(InstrumentedClassType.Redis.toString(), name, new String[]{});
}

@Override
public void methodStarted(String name) {
int index = name.lastIndexOf('#');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public boolean send(Transmission transmission) {

HttpResponse response = null;
HttpPost request = null;
boolean shouldBackoff = false;
try {
request = createTransmissionPostRequest(transmission);
httpClient.enhanceRequest(request);
Expand All @@ -160,32 +161,35 @@ public boolean send(Transmission transmission) {
}
} catch (ConnectionPoolTimeoutException e) {
InternalLogger.INSTANCE.error("Failed to send, connection pool timeout exception");
shouldBackoff = true;
} catch (SocketException e) {
InternalLogger.INSTANCE.error("Failed to send, socket timeout exception");
// backoff retry if no connection is found
if (e instanceof ConnectException) {
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
}
shouldBackoff = true;
} catch (UnknownHostException e) {
InternalLogger.INSTANCE.error("Failed to send, wrong host address or cannot reach address due to network issues, exception: %s", e.getMessage());
// backoff retry if host unknown
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
shouldBackoff = true;
} catch (IOException ioe) {
InternalLogger.INSTANCE.error("Failed to send, exception: %s", ioe.getMessage());
// backoff retry if no connection is found
if (ioe instanceof ConnectTimeoutException) {
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
}
shouldBackoff = true;
} catch (IllegalStateException e) {
InternalLogger.INSTANCE.error("Failed to send, illegal state exception: %s", e.getMessage());
shouldBackoff = true;
} catch (Exception e) {
InternalLogger.INSTANCE.error("Failed to send, unexpected exception: %s", e.getMessage());
shouldBackoff = true;
} catch (Throwable t) {
InternalLogger.INSTANCE.error("Failed to send, unexpected error: %s", t.getMessage());
shouldBackoff = true;
}
finally {
if (request != null) {
request.releaseConnection();
}
httpClient.dispose(response);
// backoff before trying again
if (shouldBackoff) {
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public enum TelemetryConfigurationFactory {
private String performanceCountersSection = DEFAULT_PERFORMANCE_MODULES_PACKAGE;

final static String EXTERNAL_PROPERTY_IKEY_NAME = "APPLICATION_INSIGHTS_IKEY";
final static String EXTERNAL_PROPERTY_IKEY_NAME_SECONDARY = "APPINSIGHTS_INSTRUMENTATIONKEY";

private AppInsightsConfigurationBuilder builder = new JaxbAppInsightsConfigurationBuilder();

Expand Down Expand Up @@ -208,28 +209,39 @@ private void setTelemetryProcessors(ApplicationInsightsXmlConfiguration appConfi

/**
* Setting an instrumentation key:
* First we try the system property '-DAPPLICATION_INSIGHTS_IKEY=i_key'
* Next we will try the environment variable 'APPLICATION_INSIGHTS_IKEY',
* First we try the system property '-DAPPLICATION_INSIGHTS_IKEY=i_key' or '-DAPPINSIGHTS_INSTRUMENTATIONKEY=i_key'
* Next we will try the environment variable 'APPLICATION_INSIGHTS_IKEY' or 'APPINSIGHTS_INSTRUMENTATIONKEY'
* Next we will try to fetch the i-key from the ApplicationInsights.xml
* @param userConfiguration The configuration that was represents the user's configuration in ApplicationInsights.xml.
* @param configuration The configuration class.
*/
private void setInstrumentationKey(ApplicationInsightsXmlConfiguration userConfiguration, TelemetryConfiguration configuration) {
try {
// First, check whether an i-key was provided as a java system property i.e. '-DAPPLICATION_INSIGHTS_IKEY=i_key'
String ikey = System.getProperty(EXTERNAL_PROPERTY_IKEY_NAME);
String ikey;

// First, check whether an i-key was provided as a java system property i.e. '-DAPPLICATION_INSIGHTS_IKEY=i_key', or '-DAPPINSIGHTS_INSTRUMENTATIONKEY=i_key'
ikey = System.getProperty(EXTERNAL_PROPERTY_IKEY_NAME);
if (!Strings.isNullOrEmpty(ikey)) {
configuration.setInstrumentationKey(ikey);
return;
}
ikey = System.getProperty(EXTERNAL_PROPERTY_IKEY_NAME_SECONDARY);
if (!Strings.isNullOrEmpty(ikey)) {
configuration.setInstrumentationKey(ikey);
return;
}

// Second, try to find the i-key as an environment variable 'APPLICATION_INSIGHTS_IKEY'
// Second, try to find the i-key as an environment variable 'APPLICATION_INSIGHTS_IKEY' or 'APPINSIGHTS_INSTRUMENTATIONKEY'
ikey = System.getenv(EXTERNAL_PROPERTY_IKEY_NAME);
if (!Strings.isNullOrEmpty(ikey)) {
configuration.setInstrumentationKey(ikey);
return;
}
ikey = System.getenv(EXTERNAL_PROPERTY_IKEY_NAME_SECONDARY);
if (!Strings.isNullOrEmpty(ikey)) {
configuration.setInstrumentationKey(ikey);
return;
}

// Else, try to find the i-key in ApplicationInsights.xml
if (userConfiguration != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public double getSampleRate() {
* Sets the SampleRate property.
*/
public void setSampleRate(double value) {
this.sampleRate = value;
this.sampleRate = value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public void reset() {
@Override
protected void setSampleRate(Envelope envelope) {
Double currentSP = getSamplingPercentage();
envelope.setSampleRate(currentSP);
if (currentSP != null) {
envelope.setSampleRate(currentSP);
}
}
}
Loading