-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:newrelic/newrelic-java-agent into j…
…ava-23
- Loading branch information
Showing
110 changed files
with
7,349 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<template name="nrAtTrace" value="@com.newrelic.api.agent.Trace" description="@Trace" toReformat="true" toShortenFQNames="true"> | ||
<context> | ||
<option name="JAVA_DECLARATION" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrAtTraceAsync" value="@com.newrelic.api.agent.Trace(async = true)" description="@Trace(async = true)" toReformat="true" toShortenFQNames="true"> | ||
<context> | ||
<option name="JAVA_DECLARATION" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrAtTraceDispatcher" value="@com.newrelic.api.agent.Trace(dispatcher = true)" description="@Trace(dispatcher = true)" toReformat="true" toShortenFQNames="true"> | ||
<context> | ||
<option name="JAVA_DECLARATION" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrAtWeave" value="@com.newrelic.api.agent.weaver.Weave(type = com.newrelic.api.agent.weaver.MatchType.$MATCH_TYPE$, originalName = "$CLASS_NAME$")" description="@Weave(originalName = "java.my.Class", type = Match..." toReformat="true" toShortenFQNames="true"> | ||
<variable name="MATCH_TYPE" expression="enum("ExactClass", "BaseClass", "Interface")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="CLASS_NAME" expression="concat(currentPackage(), ".", fileNameWithoutExtension())" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_DECLARATION" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrCallOriginal" value="com.newrelic.api.agent.weaver.Weaver.callOriginal();" description="Weaver.callOriginal();" toReformat="true" toShortenFQNames="true"> | ||
<context> | ||
<option name="JAVA_EXPRESSION" value="true" /> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrCallOriginalReturn" value="return com.newrelic.api.agent.weaver.Weaver.callOriginal();" description="return Weaver.callOriginal();" toReformat="true" toShortenFQNames="true"> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrHttpParams" value="com.newrelic.api.agent.HttpParameters $PARAMS$ = com.newrelic.api.agent.HttpParameters .library($LIBRARY$) .uri($URI$) .procedure($PROC$) .inboundHeaders($INBOUND_HEADERS$) .status($STATUS_CODE$, $STATUS_TEXT$) .build();" description="HttpParams params = HttpParams.library()...build();" toReformat="true" toShortenFQNames="true"> | ||
<variable name="PARAMS" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="LIBRARY" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="URI" expression="variableOfType("java/net/URI.java")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="PROC" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="INBOUND_HEADERS" expression="" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="STATUS_CODE" expression="variableOfType("int")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="STATUS_TEXT" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrLog" value="com.newrelic.api.agent.NewRelic.getAgent().getLogger().log(java.util.logging.Level.$LEVEL$, "$MSG$");" description="NewRelic.getAgent().getLogger().log(Level..." toReformat="true" toShortenFQNames="true"> | ||
<variable name="LEVEL" expression="enum("SEVERE", "WARNING", "INFO", "FINE", "FINER", "FINEST")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="MSG" expression="" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrMessageConsumeParams" value="com.newrelic.api.agent.MessageConsumeParameters $PARAMS$ = com.newrelic.api.agent.MessageConsumeParameters .library($LIBRARY$, $OTEL_LIBRARY$) .destinationType($DEST_TYPE$) .destinationName($DEST_NAME$) .inboundHeaders($OUTBOUND_HEADERS$) .cloudRegion($REGION$) .cloudAccountId($ACCOUNT_ID$) .build();" description="MessageProducerParams params = MessageProducerParams.builder()..." toReformat="true" toShortenFQNames="true"> | ||
<variable name="PARAMS" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="LIBRARY" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="OTEL_LIBRARY" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="DEST_TYPE" expression="enum("com.newrelic.api.agent.DestinationType.NAMED_QUEUE","com.newrelic.api.agent.DestinationType.TEMP_QUEUE","com.newrelic.api.agent.DestinationType.NAMED_TOPIC","com.newrelic.api.agent.DestinationType.TEMP_TOPIC","com.newrelic.api.agent.DestinationType.EXCHANGE")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="DEST_NAME" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="OUTBOUND_HEADERS" expression="variableOfType("com.newrelic.api.agent.OutboundHeaders")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="REGION" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="ACCOUNT_ID" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrMessageProduceParams" value="com.newrelic.api.agent.MessageProduceParameters $PARAMS$ = com.newrelic.api.agent.MessageProduceParameters .library($LIBRARY$, $OTEL_LIBRARY$) .destinationType($DEST_TYPE$) .destinationName($DEST_NAME$) .outboundHeaders($OUTBOUND_HEADERS$) .cloudRegion($REGION$) .cloudAccountId($ACCOUNT_ID$) .build();" description="MessageProducerParams params = MessageProducerParams.builder()..." toReformat="true" toShortenFQNames="true"> | ||
<variable name="PARAMS" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="LIBRARY" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="OTEL_LIBRARY" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="DEST_TYPE" expression="enum("com.newrelic.api.agent.DestinationType.NAMED_QUEUE","com.newrelic.api.agent.DestinationType.TEMP_QUEUE","com.newrelic.api.agent.DestinationType.NAMED_TOPIC","com.newrelic.api.agent.DestinationType.TEMP_TOPIC","com.newrelic.api.agent.DestinationType.EXCHANGE")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="DEST_NAME" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="OUTBOUND_HEADERS" expression="variableOfType("com.newrelic.api.agent.OutboundHeaders")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="REGION" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="ACCOUNT_ID" expression="variableOfType("java.lang.String")" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrReportAsExternal" value="com.newrelic.api.agent.NewRelic.getAgent().getTracedMethod().reportAsExternal($PARAMS$);" description="NewRelic.getAgent().getTracedMethod().reportAsExternal(params);" toReformat="true" toShortenFQNames="true"> | ||
<variable name="PARAMS" expression="variableOfType("com.newrelic.api.agent.ExternalParameters")" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrSegment" value="com.newrelic.api.agent.Segment $SEGMENT$ = com.newrelic.api.agent.NewRelic.getAgent().getTransaction().startSegment("$CATEGORY$", "$NAME$");" description="Segment segment = NewRelic.getAgent().getTransaction().startSegment();" toReformat="true" toShortenFQNames="true"> | ||
<variable name="SEGMENT" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="CATEGORY" expression="enum("category")" defaultValue="" alwaysStopAt="true" /> | ||
<variable name="NAME" expression="enum("optional name")" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrToken" value="com.newrelic.api.agent.Token $TOKEN$ = com.newrelic.api.agent.NewRelic.getAgent().getTransaction().getToken();" description="Token token = NewRelic.getAgent().getTransaction().getToken();" toReformat="true" toShortenFQNames="true"> | ||
<variable name="TOKEN" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrTracedMethod" value="com.newrelic.api.agent.TracedMethod $TRACER$ = com.newrelic.api.agent.NewRelic.getAgent().getTracedMethod();" description="TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();" toReformat="true" toShortenFQNames="true"> | ||
<variable name="TRACER" expression="suggestVariableName()" defaultValue="tracer" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> | ||
<template name="nrTx" value="com.newrelic.api.agent.Transaction $TRANSACTION$ = com.newrelic.api.agent.NewRelic.getAgent().getTransaction();" description="Transaction transaction = NewRelic.getAgent().getTransaction();" toReformat="true" toShortenFQNames="true"> | ||
<variable name="TRANSACTION" expression="enum("transaction", "tx")" defaultValue="" alwaysStopAt="true" /> | ||
<context> | ||
<option name="JAVA_STATEMENT" value="true" /> | ||
</context> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
instrumentation/aws-java-sdk-kinesis-1.11.106/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation("com.amazonaws:aws-java-sdk-kinesis:1.11.106") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.aws-java-sdk-kinesis-1.11.106' } | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'com.amazonaws:aws-java-sdk-kinesis:[1.11.106,)' | ||
} |
63 changes: 63 additions & 0 deletions
63
...106/src/main/java/com/agent/instrumentation/awsjavasdk2/services/kinesis/KinesisUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.agent.instrumentation.awsjavasdk2.services.kinesis; | ||
|
||
import com.amazonaws.AmazonWebServiceRequest; | ||
import com.amazonaws.handlers.AsyncHandler_Instrumentation; | ||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.CloudParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.TracedMethod; | ||
|
||
import java.util.Map; | ||
|
||
public class KinesisUtil { | ||
|
||
public static final String PLATFORM = "aws_kinesis_data_streams"; | ||
public static final String TRACE_CATEGORY = "Kinesis"; | ||
|
||
public static final Map<AmazonWebServiceRequest, Token> requestTokenMap = AgentBridge.collectionFactory.createConcurrentWeakKeyedMap(); | ||
private KinesisUtil() {} | ||
|
||
public static void setTokenForRequest(AmazonWebServiceRequest request) { | ||
if (AgentBridge.getAgent().getTransaction(false) != null) { | ||
if (request != null) { | ||
Token token = NewRelic.getAgent().getTransaction().getToken(); | ||
requestTokenMap.put(request, token); | ||
} | ||
} | ||
} | ||
|
||
public static void setTraceInformation(String kinesisOperation, AmazonWebServiceRequest request) { | ||
Token token = KinesisUtil.getToken(request); | ||
if (token != null) { | ||
token.linkAndExpire(); | ||
} | ||
KinesisUtil.cleanToken(request); | ||
TracedMethod tracedMethod = NewRelic.getAgent().getTransaction().getTracedMethod(); | ||
KinesisUtil.setTraceDetails(kinesisOperation, tracedMethod); | ||
} | ||
|
||
public static Token getToken(AmazonWebServiceRequest request) { | ||
if (request != null) { | ||
return requestTokenMap.get(request); | ||
} | ||
return null; | ||
} | ||
|
||
public static void cleanToken(AmazonWebServiceRequest request) { | ||
if (request != null) { | ||
requestTokenMap.remove(request); | ||
} | ||
} | ||
|
||
public static void setTraceDetails(String kinesisOperation, TracedMethod tracedMethod) { | ||
tracedMethod.setMetricName(TRACE_CATEGORY, kinesisOperation); | ||
tracedMethod.reportAsExternal(createCloudParams()); | ||
} | ||
|
||
public static CloudParameters createCloudParams() { | ||
// Todo: add arn to cloud parameters | ||
return CloudParameters.provider(PLATFORM).build(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...k-kinesis-1.11.106/src/main/java/com/amazonaws/handlers/AsyncHandler_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* | ||
* * Copyright 2020 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.amazonaws.handlers; | ||
|
||
import com.amazonaws.AmazonWebServiceRequest; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave(originalName ="com.amazonaws.handlers.AsyncHandler", type = MatchType.Interface) | ||
public class AsyncHandler_Instrumentation<REQUEST extends AmazonWebServiceRequest, RESULT> { | ||
|
||
@NewField | ||
public Token token; | ||
|
||
@Trace(async = true) | ||
public void onError(Exception exception) { | ||
if (token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace(async = true) | ||
public void onSuccess(REQUEST request, RESULT result) { | ||
if (token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
} |
Oops, something went wrong.