Skip to content

Commit 9c32923

Browse files
Copilottrask
andcommitted
Update aws-xray module to follow style guide - static imports and final classes
Co-authored-by: trask <[email protected]>
1 parent b2b7241 commit 9c32923

12 files changed

+84
-84
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* #setAttributesKeysToPropagate} are not invoked, the builder defaults to using specific {@link
2020
* AwsAttributeKeys} as propagation targets.
2121
*/
22-
public class AttributePropagatingSpanProcessorBuilder {
22+
public final class AttributePropagatingSpanProcessorBuilder {
2323

2424
private AttributeKey<String> spanNamePropagationKey = AwsAttributeKeys.AWS_LOCAL_OPERATION;
2525
private List<AttributeKey<String>> attributesKeysToPropagate =

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
}

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

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

66
package io.opentelemetry.contrib.awsxray;
77

8+
import static io.opentelemetry.api.common.AttributeKey.longKey;
9+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
810
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_BUCKET_NAME;
911
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_LOCAL_OPERATION;
1012
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_LOCAL_SERVICE;
@@ -16,6 +18,7 @@
1618
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_STREAM_NAME;
1719
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_TABLE_NAME;
1820
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
21+
import static java.util.logging.Level.FINEST;
1922

2023
import io.opentelemetry.api.common.AttributeKey;
2124
import io.opentelemetry.api.common.Attributes;
@@ -27,7 +30,6 @@
2730
import java.net.MalformedURLException;
2831
import java.net.URL;
2932
import java.util.Optional;
30-
import java.util.logging.Level;
3133
import java.util.logging.Logger;
3234

3335
/**
@@ -54,36 +56,31 @@ final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
5456
private static final String UNKNOWN_REMOTE_OPERATION = "UnknownRemoteOperation";
5557

5658
// copied from DbIncubatingAttributes
57-
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
58-
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
59+
private static final AttributeKey<String> DB_OPERATION = stringKey("db.operation");
60+
private static final AttributeKey<String> DB_SYSTEM = stringKey("db.system");
5961
// copied from FaasIncubatingAttributes
60-
private static final AttributeKey<String> FAAS_INVOKED_NAME =
61-
AttributeKey.stringKey("faas.invoked_name");
62-
private static final AttributeKey<String> FAAS_TRIGGER = AttributeKey.stringKey("faas.trigger");
62+
private static final AttributeKey<String> FAAS_INVOKED_NAME = stringKey("faas.invoked_name");
63+
private static final AttributeKey<String> FAAS_TRIGGER = stringKey("faas.trigger");
6364
// copied from GraphqlIncubatingAttributes
6465
private static final AttributeKey<String> GRAPHQL_OPERATION_TYPE =
65-
AttributeKey.stringKey("graphql.operation.type");
66+
stringKey("graphql.operation.type");
6667
// copied from HttpIncubatingAttributes
67-
private static final AttributeKey<String> HTTP_METHOD = AttributeKey.stringKey("http.method");
68-
private static final AttributeKey<String> HTTP_TARGET = AttributeKey.stringKey("http.target");
69-
private static final AttributeKey<String> HTTP_URL = AttributeKey.stringKey("http.url");
68+
private static final AttributeKey<String> HTTP_METHOD = stringKey("http.method");
69+
private static final AttributeKey<String> HTTP_TARGET = stringKey("http.target");
70+
private static final AttributeKey<String> HTTP_URL = stringKey("http.url");
7071
// copied from MessagingIncubatingAttributes
71-
private static final AttributeKey<String> MESSAGING_OPERATION =
72-
AttributeKey.stringKey("messaging.operation");
73-
private static final AttributeKey<String> MESSAGING_SYSTEM =
74-
AttributeKey.stringKey("messaging.system");
72+
private static final AttributeKey<String> MESSAGING_OPERATION = stringKey("messaging.operation");
73+
private static final AttributeKey<String> MESSAGING_SYSTEM = stringKey("messaging.system");
7574
// copied from NetIncubatingAttributes
76-
private static final AttributeKey<String> NET_PEER_NAME = AttributeKey.stringKey("net.peer.name");
77-
private static final AttributeKey<Long> NET_PEER_PORT = AttributeKey.longKey("net.peer.port");
78-
private static final AttributeKey<String> NET_SOCK_PEER_ADDR =
79-
AttributeKey.stringKey("net.sock.peer.addr");
80-
private static final AttributeKey<Long> NET_SOCK_PEER_PORT =
81-
AttributeKey.longKey("net.sock.peer.port");
75+
private static final AttributeKey<String> NET_PEER_NAME = stringKey("net.peer.name");
76+
private static final AttributeKey<Long> NET_PEER_PORT = longKey("net.peer.port");
77+
private static final AttributeKey<String> NET_SOCK_PEER_ADDR = stringKey("net.sock.peer.addr");
78+
private static final AttributeKey<Long> NET_SOCK_PEER_PORT = longKey("net.sock.peer.port");
8279
// copied from PeerIncubatingAttributes
83-
private static final AttributeKey<String> PEER_SERVICE = AttributeKey.stringKey("peer.service");
80+
private static final AttributeKey<String> PEER_SERVICE = stringKey("peer.service");
8481
// copied from RpcIncubatingAttributes
85-
private static final AttributeKey<String> RPC_METHOD = AttributeKey.stringKey("rpc.method");
86-
private static final AttributeKey<String> RPC_SERVICE = AttributeKey.stringKey("rpc.service");
82+
private static final AttributeKey<String> RPC_METHOD = stringKey("rpc.method");
83+
private static final AttributeKey<String> RPC_SERVICE = stringKey("rpc.service");
8784

8885
@Override
8986
public Attributes generateMetricAttributesFromSpan(SpanData span, Resource resource) {
@@ -307,7 +304,7 @@ private static String generateRemoteOperation(SpanData span) {
307304
remoteOperation = extractApiPathValue(url.getPath());
308305
}
309306
} catch (MalformedURLException e) {
310-
logger.log(Level.FINEST, "invalid http.url attribute: ", httpUrl);
307+
logger.log(FINEST, "invalid http.url attribute: ", httpUrl);
311308
}
312309
}
313310
if (isKeyPresent(span, HTTP_METHOD)) {
@@ -387,6 +384,6 @@ private static void logUnknownAttribute(AttributeKey<String> attributeKey, SpanD
387384
String[] params = {
388385
attributeKey.getKey(), span.getKind().name(), span.getSpanContext().getSpanId()
389386
};
390-
logger.log(Level.FINEST, "No valid {0} value found for {1} span {2}", params);
387+
logger.log(FINEST, "No valid {0} value found for {1} span {2}", params);
391388
}
392389
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* attributes.
3131
*/
3232
@Immutable
33-
public class AwsMetricAttributesSpanExporter implements SpanExporter {
33+
public final class AwsMetricAttributesSpanExporter implements SpanExporter {
3434

3535
private final SpanExporter delegate;
3636
private final MetricAttributeGenerator generator;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import io.opentelemetry.sdk.resources.Resource;
1212
import io.opentelemetry.sdk.trace.export.SpanExporter;
1313

14-
public class AwsMetricAttributesSpanExporterBuilder {
14+
public final class AwsMetricAttributesSpanExporterBuilder {
1515

1616
// Defaults
1717
private static final MetricAttributeGenerator DEFAULT_GENERATOR =

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

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

66
package io.opentelemetry.contrib.awsxray;
77

8+
import static io.opentelemetry.api.common.AttributeKey.longKey;
9+
810
import io.opentelemetry.api.common.AttributeKey;
911
import io.opentelemetry.api.common.Attributes;
1012
import io.opentelemetry.api.metrics.DoubleHistogram;
@@ -40,8 +42,7 @@
4042
@Immutable
4143
public final class AwsSpanMetricsProcessor implements SpanProcessor {
4244

43-
private static final AttributeKey<Long> HTTP_STATUS_CODE =
44-
AttributeKey.longKey("http.status_code");
45+
private static final AttributeKey<Long> HTTP_STATUS_CODE = longKey("http.status_code");
4546

4647
private static final double NANOS_TO_MILLIS = 1_000_000.0;
4748

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

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

66
package io.opentelemetry.contrib.awsxray;
77

8+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
9+
import static java.util.concurrent.TimeUnit.SECONDS;
10+
import static java.util.function.Function.identity;
11+
import static java.util.logging.Level.FINE;
12+
import static java.util.stream.Collectors.toList;
13+
import static java.util.stream.Collectors.toMap;
14+
import static java.util.stream.Collectors.toSet;
15+
816
import io.opentelemetry.api.common.Attributes;
917
import io.opentelemetry.api.trace.SpanKind;
1018
import io.opentelemetry.context.Context;
@@ -29,17 +37,13 @@
2937
import java.util.concurrent.ScheduledExecutorService;
3038
import java.util.concurrent.ScheduledFuture;
3139
import java.util.concurrent.ThreadLocalRandom;
32-
import java.util.concurrent.TimeUnit;
33-
import java.util.function.Function;
34-
import java.util.logging.Level;
3540
import java.util.logging.Logger;
36-
import java.util.stream.Collectors;
3741
import javax.annotation.Nullable;
3842

3943
/** Remote sampler that gets sampling configuration from AWS X-Ray. */
4044
public final class AwsXrayRemoteSampler implements Sampler, Closeable {
4145

42-
static final long DEFAULT_TARGET_INTERVAL_NANOS = TimeUnit.SECONDS.toNanos(10);
46+
static final long DEFAULT_TARGET_INTERVAL_NANOS = SECONDS.toNanos(10);
4347

4448
private static final Logger logger = Logger.getLogger(AwsXrayRemoteSampler.class.getName());
4549

@@ -134,26 +138,25 @@ private void getAndUpdateSampler() {
134138
initialSampler,
135139
response.getSamplingRules().stream()
136140
.map(SamplingRuleRecord::getRule)
137-
.collect(Collectors.toList())));
141+
.collect(toList())));
138142

139143
previousRulesResponse = response;
140144
ScheduledFuture<?> existingFetchTargetsFuture = fetchTargetsFuture;
141145
if (existingFetchTargetsFuture != null) {
142146
existingFetchTargetsFuture.cancel(false);
143147
}
144148
fetchTargetsFuture =
145-
executor.schedule(
146-
this::fetchTargets, DEFAULT_TARGET_INTERVAL_NANOS, TimeUnit.NANOSECONDS);
149+
executor.schedule(this::fetchTargets, DEFAULT_TARGET_INTERVAL_NANOS, NANOSECONDS);
147150
}
148151
} catch (Throwable t) {
149-
logger.log(Level.FINE, "Failed to update sampler", t);
152+
logger.log(FINE, "Failed to update sampler", t);
150153
}
151154
scheduleSamplerUpdate();
152155
}
153156

154157
private void scheduleSamplerUpdate() {
155158
long delay = pollingIntervalNanos + jitterNanos.next();
156-
pollFuture = executor.schedule(this::getAndUpdateSampler, delay, TimeUnit.NANOSECONDS);
159+
pollFuture = executor.schedule(this::getAndUpdateSampler, delay, NANOSECONDS);
157160
}
158161

159162
/**
@@ -168,7 +171,7 @@ Duration getNextSamplerUpdateScheduledDuration() {
168171
if (pollFuture == null) {
169172
return null;
170173
}
171-
return Duration.ofNanos(pollFuture.getDelay(TimeUnit.NANOSECONDS));
174+
return Duration.ofNanos(pollFuture.getDelay(NANOSECONDS));
172175
}
173176

174177
private void fetchTargets() {
@@ -181,28 +184,25 @@ private void fetchTargets() {
181184
Date now = Date.from(Instant.ofEpochSecond(0, clock.now()));
182185
List<SamplingStatisticsDocument> statistics = xrayRulesSampler.snapshot(now);
183186
Set<String> requestedTargetRuleNames =
184-
statistics.stream()
185-
.map(SamplingStatisticsDocument::getRuleName)
186-
.collect(Collectors.toSet());
187+
statistics.stream().map(SamplingStatisticsDocument::getRuleName).collect(toSet());
187188

188189
GetSamplingTargetsResponse response =
189190
client.getSamplingTargets(GetSamplingTargetsRequest.create(statistics));
190191
Map<String, SamplingTargetDocument> targets =
191192
response.getDocuments().stream()
192-
.collect(Collectors.toMap(SamplingTargetDocument::getRuleName, Function.identity()));
193+
.collect(toMap(SamplingTargetDocument::getRuleName, identity()));
193194
updateInternalSamplers(xrayRulesSampler.withTargets(targets, requestedTargetRuleNames, now));
194195
} catch (Throwable t) {
195196
// Might be a transient API failure, try again after a default interval.
196197
fetchTargetsFuture =
197-
executor.schedule(
198-
this::fetchTargets, DEFAULT_TARGET_INTERVAL_NANOS, TimeUnit.NANOSECONDS);
198+
executor.schedule(this::fetchTargets, DEFAULT_TARGET_INTERVAL_NANOS, NANOSECONDS);
199199
return;
200200
}
201201

202202
long nextTargetFetchIntervalNanos =
203203
xrayRulesSampler.nextTargetFetchTimeNanos() - clock.nanoTime();
204204
fetchTargetsFuture =
205-
executor.schedule(this::fetchTargets, nextTargetFetchIntervalNanos, TimeUnit.NANOSECONDS);
205+
executor.schedule(this::fetchTargets, nextTargetFetchIntervalNanos, NANOSECONDS);
206206
}
207207

208208
@Override

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

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

88
import static java.util.Objects.requireNonNull;
9+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
10+
import static java.util.concurrent.TimeUnit.SECONDS;
911

1012
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1113
import io.opentelemetry.sdk.common.Clock;
@@ -26,7 +28,7 @@ public final class AwsXrayRemoteSamplerBuilder {
2628
private Clock clock = Clock.getDefault();
2729
private String endpoint = DEFAULT_ENDPOINT;
2830
@Nullable private Sampler initialSampler;
29-
private long pollingIntervalNanos = TimeUnit.SECONDS.toNanos(DEFAULT_POLLING_INTERVAL_SECS);
31+
private long pollingIntervalNanos = SECONDS.toNanos(DEFAULT_POLLING_INTERVAL_SECS);
3032

3133
AwsXrayRemoteSamplerBuilder(Resource resource) {
3234
this.resource = resource;
@@ -51,7 +53,7 @@ public AwsXrayRemoteSamplerBuilder setEndpoint(String endpoint) {
5153
@CanIgnoreReturnValue
5254
public AwsXrayRemoteSamplerBuilder setPollingInterval(Duration delay) {
5355
requireNonNull(delay, "delay");
54-
return setPollingInterval(delay.toNanos(), TimeUnit.NANOSECONDS);
56+
return setPollingInterval(delay.toNanos(), NANOSECONDS);
5557
}
5658

5759
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Map;
1616

1717
@AutoService(ConfigurableSamplerProvider.class)
18-
public class AwsXrayRemoteSamplerProvider implements ConfigurableSamplerProvider {
18+
public final class AwsXrayRemoteSamplerProvider implements ConfigurableSamplerProvider {
1919

2020
@Override
2121
public Sampler createSampler(ConfigProperties config) {

0 commit comments

Comments
 (0)