Skip to content

Commit 712ad7c

Browse files
authored
"Applying" potential Copilot code review rules (open-telemetry#2182)
1 parent 088e72d commit 712ad7c

File tree

59 files changed

+324
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+324
-287
lines changed

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/BeanstalkResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.SERVICE_INSTANCE_ID;
1313
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.SERVICE_NAMESPACE;
1414
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_VERSION;
15+
import static java.util.logging.Level.WARNING;
1516

1617
import com.fasterxml.jackson.core.JsonFactory;
1718
import com.fasterxml.jackson.core.JsonParser;
@@ -22,7 +23,6 @@
2223
import io.opentelemetry.semconv.SchemaUrls;
2324
import java.io.File;
2425
import java.io.IOException;
25-
import java.util.logging.Level;
2626
import java.util.logging.Logger;
2727

2828
/**
@@ -65,7 +65,7 @@ static Resource buildResource(String configPath) {
6565
parser.nextToken();
6666

6767
if (!parser.isExpectedStartObjectToken()) {
68-
logger.log(Level.WARNING, "Invalid Beanstalk config: ", configPath);
68+
logger.log(WARNING, "Invalid Beanstalk config: ", configPath);
6969
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
7070
}
7171

@@ -87,7 +87,7 @@ static Resource buildResource(String configPath) {
8787
}
8888
}
8989
} catch (IOException e) {
90-
logger.log(Level.WARNING, "Could not parse Beanstalk config.", e);
90+
logger.log(WARNING, "Could not parse Beanstalk config.", e);
9191
return Resource.empty();
9292
}
9393

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/DockerHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import static java.util.logging.Level.WARNING;
9+
810
import java.io.BufferedReader;
911
import java.io.FileNotFoundException;
1012
import java.io.FileReader;
1113
import java.io.IOException;
12-
import java.util.logging.Level;
1314
import java.util.logging.Logger;
1415

1516
class DockerHelper {
@@ -44,9 +45,9 @@ public String getContainerId() {
4445
}
4546
}
4647
} catch (FileNotFoundException e) {
47-
logger.log(Level.WARNING, "Failed to read container id, cgroup file does not exist.");
48+
logger.log(WARNING, "Failed to read container id, cgroup file does not exist.");
4849
} catch (IOException e) {
49-
logger.log(Level.WARNING, "Unable to read container id: " + e.getMessage());
50+
logger.log(WARNING, "Unable to read container id: " + e.getMessage());
5051
}
5152

5253
return "";

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/Ec2Resource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.HOST_IMAGE_ID;
1616
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.HOST_NAME;
1717
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.HOST_TYPE;
18+
import static java.util.logging.Level.WARNING;
1819

1920
import com.fasterxml.jackson.core.JsonFactory;
2021
import com.fasterxml.jackson.core.JsonParser;
@@ -28,7 +29,6 @@
2829
import java.net.URL;
2930
import java.util.HashMap;
3031
import java.util.Map;
31-
import java.util.logging.Level;
3232
import java.util.logging.Logger;
3333

3434
/**
@@ -125,7 +125,7 @@ static Resource buildResource(String endpoint) {
125125
}
126126
}
127127
} catch (IOException e) {
128-
logger.log(Level.WARNING, "Could not parse identity document, resource not filled.", e);
128+
logger.log(WARNING, "Could not parse identity document, resource not filled.", e);
129129
return Resource.empty();
130130
}
131131

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/EcsResource.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CONTAINER_NAME;
2727
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudPlatformIncubatingValues.AWS_ECS;
2828
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudProviderIncubatingValues.AWS;
29+
import static java.util.Collections.emptyMap;
30+
import static java.util.Collections.singletonList;
31+
import static java.util.logging.Level.WARNING;
2932

3033
import com.fasterxml.jackson.core.JsonFactory;
3134
import com.fasterxml.jackson.core.JsonParser;
@@ -35,11 +38,9 @@
3538
import io.opentelemetry.sdk.resources.Resource;
3639
import io.opentelemetry.semconv.SchemaUrls;
3740
import java.io.IOException;
38-
import java.util.Collections;
3941
import java.util.Locale;
4042
import java.util.Map;
4143
import java.util.Optional;
42-
import java.util.logging.Level;
4344
import java.util.logging.Logger;
4445
import java.util.regex.Matcher;
4546
import java.util.regex.Pattern;
@@ -88,7 +89,7 @@ static Resource buildResource(Map<String, String> sysEnv, SimpleHttpClient httpC
8889

8990
static void fetchMetadata(
9091
SimpleHttpClient httpClient, String url, AttributesBuilder attrBuilders) {
91-
String json = httpClient.fetchString("GET", url, Collections.emptyMap(), null);
92+
String json = httpClient.fetchString("GET", url, emptyMap(), null);
9293
if (json.isEmpty()) {
9394
return;
9495
}
@@ -103,17 +104,17 @@ static void fetchMetadata(
103104
.getLogGroupArn()
104105
.ifPresent(
105106
logGroupArn -> {
106-
attrBuilders.put(AWS_LOG_GROUP_ARNS, Collections.singletonList(logGroupArn));
107+
attrBuilders.put(AWS_LOG_GROUP_ARNS, singletonList(logGroupArn));
107108
});
108109

109110
logArnBuilder
110111
.getLogStreamArn()
111112
.ifPresent(
112113
logStreamArn -> {
113-
attrBuilders.put(AWS_LOG_STREAM_ARNS, Collections.singletonList(logStreamArn));
114+
attrBuilders.put(AWS_LOG_STREAM_ARNS, singletonList(logStreamArn));
114115
});
115116
} catch (IOException e) {
116-
logger.log(Level.WARNING, "Can't get ECS metadata", e);
117+
logger.log(WARNING, "Can't get ECS metadata", e);
117118
}
118119
}
119120

@@ -156,7 +157,7 @@ static void parseResponse(
156157
JsonParser parser, AttributesBuilder attrBuilders, LogArnBuilder logArnBuilder)
157158
throws IOException {
158159
if (!parser.isExpectedStartObjectToken()) {
159-
logger.log(Level.WARNING, "Couldn't parse ECS metadata, invalid JSON");
160+
logger.log(WARNING, "Couldn't parse ECS metadata, invalid JSON");
160161
return;
161162
}
162163

@@ -339,7 +340,7 @@ static DockerImage parse(@Nullable String image) {
339340
}
340341
Matcher matcher = imagePattern.matcher(image);
341342
if (!matcher.matches()) {
342-
logger.log(Level.WARNING, "Couldn't parse image '" + image + "'");
343+
logger.log(WARNING, "Couldn't parse image '" + image + "'");
343344
return null;
344345
}
345346
String repository = matcher.group("repository");

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/EksResource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS;
1212
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudProviderIncubatingValues.AWS;
1313
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.K8S_CLUSTER_NAME;
14+
import static java.util.logging.Level.FINE;
15+
import static java.util.logging.Level.WARNING;
1416

1517
import com.fasterxml.jackson.core.JsonFactory;
1618
import com.fasterxml.jackson.core.JsonParser;
@@ -26,7 +28,6 @@
2628
import java.nio.file.Paths;
2729
import java.util.HashMap;
2830
import java.util.Map;
29-
import java.util.logging.Level;
3031
import java.util.logging.Logger;
3132

3233
/**
@@ -91,7 +92,7 @@ static Resource buildResource(
9192
private static boolean isEks(
9293
String k8sTokenPath, String k8sKeystorePath, SimpleHttpClient httpClient) {
9394
if (!isK8s(k8sTokenPath, k8sKeystorePath)) {
94-
logger.log(Level.FINE, "Not running on k8s.");
95+
logger.log(FINE, "Not running on k8s.");
9596
return false;
9697
}
9798

@@ -145,7 +146,7 @@ private static String getClusterName(SimpleHttpClient httpClient) {
145146
}
146147
}
147148
} catch (IOException e) {
148-
logger.log(Level.WARNING, "Can't get cluster name on EKS.", e);
149+
logger.log(WARNING, "Can't get cluster name on EKS.", e);
149150
}
150151
return "";
151152
}
@@ -156,7 +157,7 @@ private static String getK8sCredHeader() {
156157
new String(Files.readAllBytes(Paths.get(K8S_TOKEN_PATH)), StandardCharsets.UTF_8);
157158
return "Bearer " + content;
158159
} catch (IOException e) {
159-
logger.log(Level.WARNING, "Unable to load K8s client token.", e);
160+
logger.log(WARNING, "Unable to load K8s client token.", e);
160161
}
161162
return "";
162163
}

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/SimpleHttpClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import static java.util.logging.Level.FINE;
9+
import static java.util.logging.Level.WARNING;
10+
811
import java.io.FileInputStream;
912
import java.io.IOException;
1013
import java.security.KeyStore;
@@ -13,7 +16,6 @@
1316
import java.time.Duration;
1417
import java.util.Collection;
1518
import java.util.Map;
16-
import java.util.logging.Level;
1719
import java.util.logging.Logger;
1820
import javax.annotation.Nullable;
1921
import javax.net.ssl.SSLContext;
@@ -72,7 +74,7 @@ public String fetchString(
7274
int responseCode = response.code();
7375
if (responseCode != 200) {
7476
logger.log(
75-
Level.FINE,
77+
FINE,
7678
"Error response from "
7779
+ urlStr
7880
+ " code ("
@@ -84,7 +86,7 @@ public String fetchString(
8486
ResponseBody body = response.body();
8587
return body != null ? body.string() : "";
8688
} catch (IOException e) {
87-
logger.log(Level.FINE, "SimpleHttpClient fetch string failed.", e);
89+
logger.log(FINE, "SimpleHttpClient fetch string failed.", e);
8890
}
8991

9092
return "";
@@ -101,7 +103,7 @@ private static X509TrustManager buildTrustManager(@Nullable KeyStore keyStore) {
101103
tmf.init(keyStore);
102104
return (X509TrustManager) tmf.getTrustManagers()[0];
103105
} catch (Exception e) {
104-
logger.log(Level.WARNING, "Build SslSocketFactory for K8s restful client exception.", e);
106+
logger.log(WARNING, "Build SslSocketFactory for K8s restful client exception.", e);
105107
return null;
106108
}
107109
}
@@ -117,7 +119,7 @@ private static SSLSocketFactory buildSslSocketFactory(@Nullable TrustManager tru
117119
return context.getSocketFactory();
118120

119121
} catch (Exception e) {
120-
logger.log(Level.WARNING, "Build SslSocketFactory for K8s restful client exception.", e);
122+
logger.log(WARNING, "Build SslSocketFactory for K8s restful client exception.", e);
121123
}
122124
return null;
123125
}
@@ -138,7 +140,7 @@ private static KeyStore getKeystoreForTrustedCert(String certPath) {
138140
}
139141
return trustStore;
140142
} catch (Exception e) {
141-
logger.log(Level.WARNING, "Cannot load KeyStore from " + certPath);
143+
logger.log(WARNING, "Cannot load KeyStore from " + certPath);
142144
return null;
143145
}
144146
}

aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayLambdaPropagator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
package io.opentelemetry.contrib.awsxray.propagator;
77

8+
import static java.util.Collections.singletonMap;
9+
810
import io.opentelemetry.api.trace.Span;
911
import io.opentelemetry.context.Context;
1012
import io.opentelemetry.context.propagation.TextMapGetter;
1113
import io.opentelemetry.context.propagation.TextMapPropagator;
1214
import io.opentelemetry.context.propagation.TextMapSetter;
13-
import java.util.Collections;
1415
import java.util.List;
1516
import java.util.Map;
1617
import java.util.Set;
@@ -75,7 +76,7 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
7576
}
7677
return xrayPropagator.extract(
7778
xrayContext,
78-
Collections.singletonMap(AwsXrayPropagator.TRACE_HEADER_KEY, traceHeader),
79+
singletonMap(AwsXrayPropagator.TRACE_HEADER_KEY, traceHeader),
7980
MapGetter.INSTANCE);
8081
}
8182

aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.contrib.awsxray.propagator;
77

88
import static io.opentelemetry.api.internal.OtelEncodingUtils.isValidBase16String;
9+
import static java.util.Collections.singletonList;
910

1011
import io.opentelemetry.api.baggage.Baggage;
1112
import io.opentelemetry.api.baggage.BaggageBuilder;
@@ -20,7 +21,6 @@
2021
import io.opentelemetry.context.propagation.TextMapGetter;
2122
import io.opentelemetry.context.propagation.TextMapPropagator;
2223
import io.opentelemetry.context.propagation.TextMapSetter;
23-
import java.util.Collections;
2424
import java.util.List;
2525
import java.util.Set;
2626
import java.util.logging.Logger;
@@ -80,7 +80,7 @@ public final class AwsXrayPropagator implements TextMapPropagator {
8080
private static final String INVALID_LINEAGE = "-1:11111111:0";
8181
private static final int NUM_OF_LINEAGE_DELIMITERS = 2;
8282

83-
private static final List<String> FIELDS = Collections.singletonList(TRACE_HEADER_KEY);
83+
private static final List<String> FIELDS = singletonList(TRACE_HEADER_KEY);
8484

8585
private static final AwsXrayPropagator INSTANCE = new AwsXrayPropagator();
8686

aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsAttributeKeys.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,34 @@
55

66
package io.opentelemetry.contrib.awsxray;
77

8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
810
import io.opentelemetry.api.common.AttributeKey;
911

1012
/** Utility class holding attribute keys with special meaning to AWS components */
1113
final class AwsAttributeKeys {
1214

1315
private AwsAttributeKeys() {}
1416

15-
static final AttributeKey<String> AWS_SPAN_KIND = AttributeKey.stringKey("aws.span.kind");
17+
static final AttributeKey<String> AWS_SPAN_KIND = stringKey("aws.span.kind");
1618

17-
static final AttributeKey<String> AWS_LOCAL_SERVICE = AttributeKey.stringKey("aws.local.service");
19+
static final AttributeKey<String> AWS_LOCAL_SERVICE = stringKey("aws.local.service");
1820

19-
static final AttributeKey<String> AWS_LOCAL_OPERATION =
20-
AttributeKey.stringKey("aws.local.operation");
21+
static final AttributeKey<String> AWS_LOCAL_OPERATION = stringKey("aws.local.operation");
2122

22-
static final AttributeKey<String> AWS_REMOTE_SERVICE =
23-
AttributeKey.stringKey("aws.remote.service");
23+
static final AttributeKey<String> AWS_REMOTE_SERVICE = stringKey("aws.remote.service");
2424

25-
static final AttributeKey<String> AWS_REMOTE_OPERATION =
26-
AttributeKey.stringKey("aws.remote.operation");
25+
static final AttributeKey<String> AWS_REMOTE_OPERATION = stringKey("aws.remote.operation");
2726

28-
static final AttributeKey<String> AWS_REMOTE_TARGET = AttributeKey.stringKey("aws.remote.target");
27+
static final AttributeKey<String> AWS_REMOTE_TARGET = stringKey("aws.remote.target");
2928

3029
// use the same AWS Resource attribute name defined by OTel java auto-instr for aws_sdk_v_1_1
3130
// TODO: all AWS specific attributes should be defined in semconv package and reused cross all
3231
// otel packages. Related sim -
3332
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/8710
3433

35-
static final AttributeKey<String> AWS_BUCKET_NAME = AttributeKey.stringKey("aws.bucket.name");
36-
static final AttributeKey<String> AWS_QUEUE_NAME = AttributeKey.stringKey("aws.queue.name");
37-
static final AttributeKey<String> AWS_STREAM_NAME = AttributeKey.stringKey("aws.stream.name");
38-
static final AttributeKey<String> AWS_TABLE_NAME = AttributeKey.stringKey("aws.table.name");
34+
static final AttributeKey<String> AWS_BUCKET_NAME = stringKey("aws.bucket.name");
35+
static final AttributeKey<String> AWS_QUEUE_NAME = stringKey("aws.queue.name");
36+
static final AttributeKey<String> AWS_STREAM_NAME = stringKey("aws.stream.name");
37+
static final AttributeKey<String> AWS_TABLE_NAME = stringKey("aws.table.name");
3938
}

0 commit comments

Comments
 (0)