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

Merging main to jakarta 8 #930

Merged
merged 24 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3acebd3
Update HttpURLConnection to use reportAsExternal API
jasonjkeller May 17, 2022
9bd6b8d
Merge branch 'main' of github.com:newrelic/newrelic-java-agent into f…
jasonjkeller Jun 1, 2022
f512aa0
Update httpurlconnection instrumentation to use reportAsExternal API
jasonjkeller Jun 16, 2022
457af57
Merge branch 'main' of github.com:newrelic/newrelic-java-agent into f…
jasonjkeller Jun 16, 2022
a78c5b3
Add qualified import
jasonjkeller Jun 16, 2022
9dc22bc
Fix HttpURLConnectionTest
jasonjkeller Jun 17, 2022
64401b9
Fix HttpCommonsTest
jasonjkeller Jun 17, 2022
877847a
Add outbound CAT headers
jasonjkeller Jun 17, 2022
fbdb11d
Correctly add CAT/Distributed tracing headers to outbound request
jasonjkeller Jun 21, 2022
81c521b
Clarify Javadoc comment on deprecated API
jasonjkeller Jun 22, 2022
d879e6b
Add additional client and framework AIT tests to workflows
GDownes Jun 27, 2022
1cfaf03
Add MSSQL R2DBC to workflow
GDownes Jun 27, 2022
dd93667
Fix Play WS client test name in workflow
GDownes Jun 27, 2022
439df1a
Add logging flag for testing
GDownes Jun 28, 2022
ee85263
Remove mssql test
GDownes Jun 29, 2022
2d67103
Merge pull request #893 from newrelic/ait-client-framework
twcrone Jun 29, 2022
898cb87
include debug as env
tbradellis Jun 22, 2022
104212d
refactor DebugFlag
tbradellis Jun 27, 2022
2711d81
clean code
tbradellis Jun 27, 2022
bde9267
delete semicolon
tbradellis Jun 28, 2022
b6e078f
Capping r2dbc-mariadb
meiao Jun 29, 2022
86a28f9
Merge pull request #885 from newrelic/fix-httpurlconnection-inst
jasonjkeller Jul 5, 2022
6e31d96
issue 620 scala illegal access error (#876)
richard-gibson Jul 12, 2022
8e7f437
Merge branch 'main' into jakarta-ee-8-integration
meiao Jul 13, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/AITs-Clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- sttp_2.py
- sttp_3.py
- http4s.py
- play_ws_2_6.py
steps:
- uses: actions/checkout@v2

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/AITs-Frameworks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ jobs:
func_tests:
- akka/akka.py
- akka/akkahttp.py
- cats/cats2.py
- cats/cats3.py
# - ejb/ejb.py
- jaxrs/jaxrs.py
# - jms/jms.py
- lettuce/lettuce.py
- monix/monix.py
# - netty/netty.py
# - play/play2.py
- quartz/quartz.py
# - snap/snap.py
- spring/spring_5_0.py
- spring/spring_webflux.py
- thrift/thrift.py
- zio/zio.py

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/AITs-R2DBC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- oracle.py
- postgres.py
- mysql.py
# - mssql.py
- h2.py
steps:
- uses: actions/checkout@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void makeExternalComponentMetric(TracedMethod method, String host,
// transaction segment name always contains operations; metric name may or may not
String operationsPath = fixOperations(operations);

if(operationsPath == null) {
if (operationsPath == null) {
String metricName = MessageFormat.format(METRIC_NAME, host, library);
method.setMetricNameFormatInfo(metricName, metricName, uri);
} else {
Expand Down Expand Up @@ -89,7 +89,7 @@ public static void makeExternalComponentTrace(boolean isWebTransaction, TracedMe

makeExternalComponentMetric(method, hostName, library, includeOperationInMetric, uri, operations);

if(UNKNOWN_HOST.equals(hostName)) {
if (UNKNOWN_HOST.equals(hostName)) {
return; // NR doesn't add rollup metrics for "UnknownHost"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@

package com.newrelic.agent.instrumentation.pointcuts.net;

import static java.text.MessageFormat.format;
import static org.junit.Assert.assertEquals;
import com.google.common.collect.Sets;
import com.newrelic.agent.AgentHelper;
import com.newrelic.agent.TransactionDataList;
import com.newrelic.agent.metric.MetricName;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.api.agent.Trace;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand All @@ -23,16 +31,8 @@
import java.util.Map;
import java.util.Set;

import com.google.common.collect.Sets;
import com.newrelic.agent.AgentHelper;
import com.newrelic.agent.TransactionDataList;
import com.newrelic.agent.metric.MetricName;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.api.agent.Trace;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static java.text.MessageFormat.format;
import static org.junit.Assert.assertEquals;

public class HttpURLConnectionTest {

Expand Down Expand Up @@ -489,43 +489,68 @@ private void verifyMetrics(String url, String scope, int scopedHttpUrlCount, int
int scopedNetworkIOCount, int unscopedNetworkIOCount) {
Set<String> metrics = AgentHelper.getMetrics();

String httpURLConnectionMetric = "External/{0}/HttpURLConnection";
String httpURLConnectionGetInputStreamMetric = "External/{0}/HttpURLConnection/getInputStream";
String httpURLConnectionGetResponseCodeMetric = "External/{0}/HttpURLConnection/getResponseCode";
String externalHostAllMetric = "External/{0}/all";
String externalAllMetric = "External/all";
String externalAllOtherMetric = "External/allOther";

if (scopedHttpUrlCount > 0 || unscopedHttpUrlCount > 0) {
Assert.assertTrue(metrics.toString(), metrics.contains(format("External/{0}/HttpURLConnection", url)));
Assert.assertTrue(metrics.toString(),
metrics.contains(format(httpURLConnectionMetric, url)) ||
metrics.contains(format(httpURLConnectionGetInputStreamMetric, url)) ||
metrics.contains(format(httpURLConnectionGetResponseCodeMetric, url)));
} else {
Assert.assertFalse(metrics.toString(), metrics.contains(format("External/{0}/HttpURLConnection", url)));
Assert.assertFalse(metrics.toString(),
metrics.contains(format(httpURLConnectionMetric, url)) ||
metrics.contains(format(httpURLConnectionGetInputStreamMetric, url)) ||
metrics.contains(format(httpURLConnectionGetResponseCodeMetric, url)));
}

if (scopedNetworkIOCount > 0 || unscopedNetworkIOCount > 0) {
Assert.assertTrue(metrics.toString(), metrics.contains(format("External/{0}/all", url)));
Assert.assertTrue(metrics.toString(), metrics.contains("External/all"));
Assert.assertTrue(metrics.toString(), metrics.contains("External/allOther"));
Assert.assertTrue(metrics.toString(), metrics.contains(format(externalHostAllMetric, url)));
Assert.assertTrue(metrics.toString(), metrics.contains(externalAllMetric));
Assert.assertTrue(metrics.toString(), metrics.contains(externalAllOtherMetric));
} else {
Assert.assertFalse(metrics.toString(), metrics.contains(format("External/{0}/all", url)));
Assert.assertFalse(metrics.toString(), metrics.contains("External/all"));
Assert.assertFalse(metrics.toString(), metrics.contains("External/allOther"));
Assert.assertFalse(metrics.toString(), metrics.contains(format(externalHostAllMetric, url)));
Assert.assertFalse(metrics.toString(), metrics.contains(externalAllMetric));
Assert.assertFalse(metrics.toString(), metrics.contains(externalAllOtherMetric));
}

Map<String, Integer> scopedMetrics = getMetricCounts(
MetricName.create(format("External/{0}/HttpURLConnection", url), scope),
MetricName.create(format("External/{0}/all", url), scope),
MetricName.create("External/all", scope),
MetricName.create("External/allOther", scope));
MetricName.create(format(httpURLConnectionMetric, url), scope),
MetricName.create(format(httpURLConnectionGetInputStreamMetric, url), scope),
MetricName.create(format(httpURLConnectionGetResponseCodeMetric, url), scope),
MetricName.create(format(externalHostAllMetric, url), scope),
MetricName.create(externalAllMetric, scope),
MetricName.create(externalAllOtherMetric, scope));

Map<String, Integer> unscopedMetrics = getMetricCounts(
MetricName.create(format("External/{0}/HttpURLConnection", url)),
MetricName.create(format("External/{0}/all", url)),
MetricName.create("External/all"),
MetricName.create("External/allOther"));

assertEquals(scopedHttpUrlCount, (int) scopedMetrics.get(format("External/{0}/HttpURLConnection", url)));
assertEquals(scopedNetworkIOCount, (int) scopedMetrics.get(format("External/{0}/all", url)));
assertEquals(scopedNetworkIOCount, (int) scopedMetrics.get("External/all"));
assertEquals(scopedNetworkIOCount, (int) scopedMetrics.get("External/allOther"));

assertEquals(unscopedHttpUrlCount, (int) unscopedMetrics.get(format("External/{0}/HttpURLConnection", url)));
assertEquals(unscopedNetworkIOCount, (int) unscopedMetrics.get(format("External/{0}/all", url)));
assertEquals(unscopedNetworkIOCount, (int) unscopedMetrics.get("External/all"));
assertEquals(unscopedNetworkIOCount, (int) unscopedMetrics.get("External/allOther"));
MetricName.create(format(httpURLConnectionMetric, url)),
MetricName.create(format(httpURLConnectionGetInputStreamMetric, url)),
MetricName.create(format(httpURLConnectionGetResponseCodeMetric, url)),
MetricName.create(format(externalHostAllMetric, url)),
MetricName.create(externalAllMetric),
MetricName.create(externalAllOtherMetric));

int actualHttpURLConnectionScopedMetricCount = scopedMetrics.get(format(httpURLConnectionMetric, url)) +
scopedMetrics.get(format(httpURLConnectionGetInputStreamMetric, url)) +
scopedMetrics.get(format(httpURLConnectionGetResponseCodeMetric, url));

int actualHttpURLConnectionUnscopedMetricCount = unscopedMetrics.get(format(httpURLConnectionMetric, url)) +
unscopedMetrics.get(format(httpURLConnectionGetInputStreamMetric, url)) +
unscopedMetrics.get(format(httpURLConnectionGetResponseCodeMetric, url));

assertEquals(scopedHttpUrlCount, actualHttpURLConnectionScopedMetricCount);
assertEquals(scopedNetworkIOCount, (int) scopedMetrics.get(format(externalHostAllMetric, url)));
assertEquals(scopedNetworkIOCount, (int) scopedMetrics.get(externalAllMetric));
assertEquals(scopedNetworkIOCount, (int) scopedMetrics.get(externalAllOtherMetric));

assertEquals(unscopedHttpUrlCount, actualHttpURLConnectionUnscopedMetricCount);
assertEquals(unscopedNetworkIOCount, (int) unscopedMetrics.get(format(externalHostAllMetric, url)));
assertEquals(unscopedNetworkIOCount, (int) unscopedMetrics.get(externalAllMetric));
assertEquals(unscopedNetworkIOCount, (int) unscopedMetrics.get(externalAllOtherMetric));
}

private Map<String, Integer> getMetricCounts(MetricName... responseTimeMetricNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public void httpURLConnection() throws Exception {
httpURLConnectionTx();

Set<String> metrics = AgentHelper.getMetrics();
assertTrue(metrics.toString(), metrics.contains("External/" + HOST + "/HttpURLConnection"));
assertTrue(metrics.toString(), metrics.contains("External/" + HOST + "/HttpURLConnection/getResponseCode"));

Map<String, Integer> metricCounts = getMetricCounts(
MetricName.create("External/" + HOST + "/HttpURLConnection",
MetricName.create("External/" + HOST + "/HttpURLConnection/getResponseCode",
"OtherTransaction/Custom/test.newrelic.test.agent.HttpCommonsTest/httpURLConnectionTx"));

assertEquals(1, (int) metricCounts.get("External/" + HOST + "/HttpURLConnection"));
assertEquals(1, (int) metricCounts.get("External/" + HOST + "/HttpURLConnection/getResponseCode"));
}

@Trace(dispatcher = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import com.newrelic.agent.instrumentation.InstrumentationType;
import com.newrelic.agent.instrumentation.classmatchers.ScalaTraitMatcher;
import com.newrelic.agent.instrumentation.context.InstrumentationContext;
import com.newrelic.agent.instrumentation.custom.ScalaTraitFinalFieldVisitor;
import com.newrelic.agent.instrumentation.tracing.Annotation;
import com.newrelic.agent.instrumentation.tracing.NoticeSqlVisitor;
import com.newrelic.agent.instrumentation.tracing.TraceClassVisitor;
import com.newrelic.agent.instrumentation.tracing.TraceDetailsBuilder;
import com.newrelic.agent.instrumentation.weaver.ClassWeaverService;
import com.newrelic.agent.instrumentation.weaver.errorhandler.LogAndReturnOriginal;
import com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPostprocessors;
import com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors;
import com.newrelic.agent.instrumentation.weaver.preprocessors.TracedWeaveInstrumentationTracker;
Expand Down Expand Up @@ -137,6 +137,15 @@ public void classWeaved(PackageWeaveResult weaveResult, ClassLoader classloader,
classBytes = weaved;
}

if (classBytes != null && context.isModified() && !context.getScalaFinalFields().isEmpty()) {
ClassReader reader = new ClassReader(classBytes);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
ClassVisitor cv = writer;
cv = new ScalaTraitFinalFieldVisitor(cv, context.getScalaFinalFields());
reader.accept(cv, ClassReader.SKIP_FRAMES);
classBytes = writer.toByteArray();
}

ClassReader reader = new ClassReader(classBytes);
if (weaved == null) {
// process trace annotations for non-weaved code
Expand All @@ -145,8 +154,8 @@ public void classWeaved(PackageWeaveResult weaveResult, ClassLoader classloader,

if (!context.isTracerMatch()) {
if (weaved != null) {
//printClass(className, weaved);
return weaved;
printClass(className, classBytes);
return classBytes;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import com.newrelic.agent.bridge.Transaction;
import com.newrelic.agent.bridge.external.ExternalMetrics;
import com.newrelic.agent.bridge.external.URISupport;
import com.newrelic.api.agent.HttpParameters;

import java.net.HttpURLConnection;
import java.net.URI;

public class MetricState {

private static final String LIBRARY = "HttpURLConnection";
private boolean metricsRecorded;
private boolean recordedANetworkCall;

Expand All @@ -25,8 +27,9 @@ public void nonNetworkPreamble(boolean isConnected, HttpURLConnection connection
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (!isConnected && method.isMetricProducer() && tx != null) {
// This method doesn't have any network I/O so we are explicitly not recording external rollup metrics
makeMetric(connection, method, operation);
tx.getCrossProcessState().processOutboundRequestHeaders(new OutboundWrapper(connection), method);
makeNonRollupExternalMetric(connection, method, operation);
// Add CAT/Distributed tracing headers to this outbound request
method.addOutboundRequestHeaders(new OutboundWrapper(connection));
}
}

Expand All @@ -35,11 +38,12 @@ public void getInputStreamPreamble(boolean isConnected, HttpURLConnection connec
if (method.isMetricProducer() && tx != null) {
if (!recordedANetworkCall) {
this.recordedANetworkCall = true;
makeMetric(connection, method, "getInputStream");
makeNonRollupExternalMetric(connection, method, "getInputStream");
}

if (!isConnected) {
tx.getCrossProcessState().processOutboundRequestHeaders(new OutboundWrapper(connection), method);
// Add CAT/Distributed tracing headers to this outbound request
method.addOutboundRequestHeaders(new OutboundWrapper(connection));
}
}
}
Expand All @@ -48,27 +52,46 @@ public void getResponseCodePreamble(HttpURLConnection connection, TracedMethod m
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (method.isMetricProducer() && tx != null && !recordedANetworkCall) {
this.recordedANetworkCall = true;
makeMetric(connection, method, "getResponseCode");
makeNonRollupExternalMetric(connection, method, "getResponseCode");
}
}

public void getInboundPostamble(HttpURLConnection connection, TracedMethod method) {
public void getInboundPostamble(HttpURLConnection connection, int responseCode, String responseMessage, String requestMethod, TracedMethod method) {
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (method.isMetricProducer() && !metricsRecorded && tx != null) {
this.metricsRecorded = true;
// This conversion is necessary as it strips query parameters from the URI
String uri = URISupport.getURI(connection.getURL());
InboundWrapper inboundWrapper = new InboundWrapper(connection);
tx.getCrossProcessState()
.processInboundResponseHeaders(inboundWrapper, method, connection.getURL().getHost(), uri, true);

// Add CAT/Distributed tracing headers to this outbound request
method.addOutboundRequestHeaders(new OutboundWrapper(connection));

// This will result in External rollup metrics being generated
method.reportAsExternal(HttpParameters
.library(LIBRARY)
.uri(URI.create(uri))
.procedure(requestMethod)
.inboundHeaders(inboundWrapper)
.status(responseCode, responseMessage)
.build());
}
}

private void makeMetric(HttpURLConnection connection, TracedMethod method, String operation) {
/**
* Sets external metric name (i.e. External/{HOST}/HttpURLConnection).
* This does not create rollup metrics such as External/all, External/allWeb, External/allOther, External/{HOST}/all
*
* @param connection HttpURLConnection instance
* @param method TracedMethod instance
* @param operation String representation of operation
*/
private void makeNonRollupExternalMetric(HttpURLConnection connection, TracedMethod method, String operation) {
String uri = URISupport.getURI(connection.getURL());
ExternalMetrics.makeExternalComponentMetric(
method,
connection.getURL().getHost(),
"HttpURLConnection",
LIBRARY,
false,
uri,
operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ protected HttpURLConnection(URL url) {
@Trace(leaf = true)
public void connect() throws IOException {
lazyGetMetricState().nonNetworkPreamble(connected, this, "connect");

Weaver.callOriginal();
}

@Trace(leaf = true)
public synchronized OutputStream getOutputStream() throws IOException {
lazyGetMetricState().nonNetworkPreamble(connected, this, "getOutputStream");

return Weaver.callOriginal();
}

Expand All @@ -71,8 +69,7 @@ public synchronized InputStream getInputStream() throws IOException {
throw e;
}

metricState.getInboundPostamble(this, method);

metricState.getInboundPostamble(this, 0, null, "getInputStream", method);
return inputStream;
}

Expand All @@ -94,8 +91,7 @@ public int getResponseCode() throws Exception {
throw e;
}

metricState.getInboundPostamble(this, method);

metricState.getInboundPostamble(this, responseCodeValue, null, "getResponseCode", method);
return responseCodeValue;
}

Expand Down
Loading