Skip to content

Commit 28aa4fc

Browse files
otelbot[bot]traskCopilot
authored
Review fixes for runtime-telemetry:javaagent (#17031)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trask <218610+trask@users.noreply.github.com>
1 parent f04ee69 commit 28aa4fc

File tree

1 file changed

+11
-31
lines changed
  • instrumentation/runtime-telemetry/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/runtimetelemetry

1 file changed

+11
-31
lines changed

instrumentation/runtime-telemetry/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/runtimetelemetry/JarAnalyzer.java

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import java.net.URL;
3131
import java.security.CodeSource;
3232
import java.security.ProtectionDomain;
33-
import java.util.HashSet;
3433
import java.util.Set;
3534
import java.util.concurrent.BlockingQueue;
35+
import java.util.concurrent.ConcurrentHashMap;
3636
import java.util.concurrent.LinkedBlockingDeque;
3737

3838
/**
@@ -56,7 +56,7 @@ final class JarAnalyzer implements ClassFileTransformer {
5656
AttributeKey.stringKey("package.checksum_algorithm");
5757
static final AttributeKey<String> PACKAGE_PATH = AttributeKey.stringKey("package.path");
5858

59-
private final Set<URI> seenUris = new HashSet<>();
59+
private final Set<URI> seenUris = ConcurrentHashMap.newKeySet();
6060
private final BlockingQueue<URL> toProcess = new LinkedBlockingDeque<>();
6161

6262
private JarAnalyzer(OpenTelemetry openTelemetry, String instrumentationName, int jarsPerSecond) {
@@ -77,14 +77,14 @@ private JarAnalyzer(OpenTelemetry openTelemetry, String instrumentationName, int
7777

7878
/** Create {@link JarAnalyzer} and start the worker thread. */
7979
// TODO can remove instrumentationName parameter in 3.0
80-
public static JarAnalyzer create(
80+
static JarAnalyzer create(
8181
OpenTelemetry openTelemetry, String instrumentationName, int jarsPerSecond) {
8282
return new JarAnalyzer(openTelemetry, instrumentationName, jarsPerSecond);
8383
}
8484

8585
/**
8686
* Identify the archive (JAR or WAR) associated with the {@code protectionDomain} and queue it to
87-
* be processed if its the first time we've seen it.
87+
* be processed if it's the first time we've seen it.
8888
*/
8989
@Override
9090
public byte[] transform(
@@ -152,7 +152,7 @@ private void handle(ProtectionDomain protectionDomain) {
152152
}
153153
}
154154

155-
// Only code locations with .jar and .war extension should make it here
155+
// Only code locations with .jar, .war, and .ear extensions should make it here.
156156
toProcess.add(archiveUrl);
157157
}
158158

@@ -169,7 +169,7 @@ private Worker(Logger logger, BlockingQueue<URL> toProcess, int jarsPerSecond) {
169169
}
170170

171171
/**
172-
* Continuously poll the {@link #toProcess} for archive {@link URL}s, and process each wit
172+
* Continuously poll the {@link #toProcess} for archive {@link URL}s, and process each with
173173
* {@link #processUrl(Logger, URL)}.
174174
*/
175175
@Override
@@ -214,31 +214,11 @@ static void processUrl(Logger logger, URL archiveUrl) {
214214
return;
215215
}
216216
AttributesBuilder builder = Attributes.builder();
217-
218-
String packagePath = jarDetails.packagePath();
219-
if (packagePath != null) {
220-
builder.put(PACKAGE_PATH, packagePath);
221-
}
222-
223-
String packageType = jarDetails.packageType();
224-
if (packageType != null) {
225-
builder.put(PACKAGE_TYPE, packageType);
226-
}
227-
228-
String packageName = jarDetails.packageName();
229-
if (packageName != null) {
230-
builder.put(PACKAGE_NAME, packageName);
231-
}
232-
233-
String packageVersion = jarDetails.version();
234-
if (packageVersion != null) {
235-
builder.put(PACKAGE_VERSION, packageVersion);
236-
}
237-
238-
String packageDescription = jarDetails.packageDescription();
239-
if (packageDescription != null) {
240-
builder.put(PACKAGE_DESCRIPTION, packageDescription);
241-
}
217+
builder.put(PACKAGE_PATH, jarDetails.packagePath());
218+
builder.put(PACKAGE_TYPE, jarDetails.packageType());
219+
builder.put(PACKAGE_NAME, jarDetails.packageName());
220+
builder.put(PACKAGE_VERSION, jarDetails.version());
221+
builder.put(PACKAGE_DESCRIPTION, jarDetails.packageDescription());
242222

243223
String packageChecksum = jarDetails.computeSha1();
244224
builder.put(PACKAGE_CHECKSUM, packageChecksum);

0 commit comments

Comments
 (0)