Skip to content

Commit e2a6b73

Browse files
committed
spotless
1 parent fad55ad commit e2a6b73

File tree

12 files changed

+235
-191
lines changed

12 files changed

+235
-191
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionConfig.java

+45-38
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.microsoft.applicationinsights.agent.internal.keytransaction;
25

36
import com.azure.json.JsonReader;
@@ -26,25 +29,26 @@ List<Criterion> getEndCriteria() {
2629
}
2730

2831
public static KeyTransactionConfig fromJson(JsonReader jsonReader) throws IOException {
29-
return jsonReader.readObject((reader) -> {
30-
KeyTransactionConfig deserializedValue = new KeyTransactionConfig();
31-
32-
while (reader.nextToken() != JsonToken.END_OBJECT) {
33-
String fieldName = reader.getFieldName();
34-
reader.nextToken();
35-
if ("Name".equals(fieldName)) {
36-
deserializedValue.name = reader.getString();
37-
} else if ("StartCriteria".equals(fieldName)) {
38-
deserializedValue.startCriteria = reader.readArray(Criterion::fromJson);
39-
} else if ("EndCriteria".equals(fieldName)) {
40-
deserializedValue.endCriteria = reader.readArray(Criterion::fromJson);
41-
} else {
42-
reader.skipChildren();
43-
}
44-
}
32+
return jsonReader.readObject(
33+
(reader) -> {
34+
KeyTransactionConfig deserializedValue = new KeyTransactionConfig();
35+
36+
while (reader.nextToken() != JsonToken.END_OBJECT) {
37+
String fieldName = reader.getFieldName();
38+
reader.nextToken();
39+
if ("Name".equals(fieldName)) {
40+
deserializedValue.name = reader.getString();
41+
} else if ("StartCriteria".equals(fieldName)) {
42+
deserializedValue.startCriteria = reader.readArray(Criterion::fromJson);
43+
} else if ("EndCriteria".equals(fieldName)) {
44+
deserializedValue.endCriteria = reader.readArray(Criterion::fromJson);
45+
} else {
46+
reader.skipChildren();
47+
}
48+
}
4549

46-
return deserializedValue;
47-
});
50+
return deserializedValue;
51+
});
4852
}
4953

5054
public static boolean matches(Attributes attributes, List<Criterion> criteria) {
@@ -98,30 +102,33 @@ Operator getOperator() {
98102
}
99103

100104
public static Criterion fromJson(JsonReader jsonReader) throws IOException {
101-
return jsonReader.readObject((reader) -> {
102-
Criterion deserializedValue = new Criterion();
103-
104-
while (reader.nextToken() != JsonToken.END_OBJECT) {
105-
String fieldName = reader.getFieldName();
106-
reader.nextToken();
107-
if ("Field".equals(fieldName)) {
108-
deserializedValue.field = AttributeKey.stringKey(reader.getString());
109-
} else if ("Operator".equals(fieldName)) {
110-
deserializedValue.operator = Operator.from(reader.getString());
111-
} else if ("Value".equals(fieldName)) {
112-
deserializedValue.value = reader.getString();
113-
} else {
114-
reader.skipChildren();
115-
}
116-
}
117-
118-
return deserializedValue;
119-
});
105+
return jsonReader.readObject(
106+
(reader) -> {
107+
Criterion deserializedValue = new Criterion();
108+
109+
while (reader.nextToken() != JsonToken.END_OBJECT) {
110+
String fieldName = reader.getFieldName();
111+
reader.nextToken();
112+
if ("Field".equals(fieldName)) {
113+
deserializedValue.field = AttributeKey.stringKey(reader.getString());
114+
} else if ("Operator".equals(fieldName)) {
115+
deserializedValue.operator = Operator.from(reader.getString());
116+
} else if ("Value".equals(fieldName)) {
117+
deserializedValue.value = reader.getString();
118+
} else {
119+
reader.skipChildren();
120+
}
121+
}
122+
123+
return deserializedValue;
124+
});
120125
}
121126
}
122127

123128
public enum Operator {
124-
EQUALS, STARTSWITH, CONTAINS;
129+
EQUALS,
130+
STARTSWITH,
131+
CONTAINS;
125132

126133
private static Operator from(String value) {
127134
switch (value) {

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionConfigSupplier.java

+57-53
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.microsoft.applicationinsights.agent.internal.keytransaction;
25

36
import static java.util.stream.Collectors.toList;
@@ -39,59 +42,60 @@ public void set(List<KeyTransactionConfig> configs) {
3942
private static List<KeyTransactionConfig> hardcodedDemo() {
4043
List<KeyTransactionConfig> configs;
4144
try {
42-
configs = NewResponse.fromJson(JsonProviders.createReader(
43-
"{\n"
44-
+ " \"itemsReceived\": 13,\n"
45-
+ " \"itemsAccepted\": 13,\n"
46-
+ " \"appId\": null,\n"
47-
+ " \"errors\": [],\n"
48-
+ " \"sdkConfiguration\": [\n"
49-
+ " {\n"
50-
+ " \"Key\": \"Transaction\",\n"
51-
+ " \"Value\": {\n"
52-
+ " \"Name\": \"EarthOrbit\",\n"
53-
+ " \"StartCriteria\": [\n"
54-
+ " {\n"
55-
+ " \"Field\": \"url.path\",\n"
56-
+ " \"Operator\": \"==\",\n"
57-
+ " \"Value\": \"/earth\"\n"
58-
+ " }\n"
59-
+ " ],\n"
60-
+ " \"EndCriteria\": []\n"
61-
+ " }\n"
62-
+ " },\n"
63-
+ " {\n"
64-
+ " \"Key\": \"Transaction\",\n"
65-
+ " \"Value\": {\n"
66-
+ " \"Name\": \"MarsMission\",\n"
67-
+ " \"StartCriteria\": [\n"
68-
+ " {\n"
69-
+ " \"Field\": \"url.path\",\n"
70-
+ " \"Operator\": \"==\",\n"
71-
+ " \"Value\": \"/mars\"\n"
72-
+ " }\n"
73-
+ " ],\n"
74-
+ " \"EndCriteria\": [\n"
75-
+ " {\n"
76-
+ " \"Field\": \"messaging.operation\",\n"
77-
+ " \"Operator\": \"==\",\n"
78-
+ " \"Value\": \"process\"\n"
79-
+ " },\n"
80-
+ " {\n"
81-
+ " \"Field\": \"messaging.destination.name\",\n"
82-
+ " \"Operator\": \"==\",\n"
83-
+ " \"Value\": \"space\"\n"
84-
+ " }\n"
85-
+ " ]\n"
86-
+ " }\n"
87-
+ " }\n"
88-
+ " ]\n"
89-
+ "}\n"
90-
))
91-
.getSdkConfigurations()
92-
.stream()
93-
.map(SdkConfiguration::getValue)
94-
.collect(toList());
45+
configs =
46+
NewResponse.fromJson(
47+
JsonProviders.createReader(
48+
"{\n"
49+
+ " \"itemsReceived\": 13,\n"
50+
+ " \"itemsAccepted\": 13,\n"
51+
+ " \"appId\": null,\n"
52+
+ " \"errors\": [],\n"
53+
+ " \"sdkConfiguration\": [\n"
54+
+ " {\n"
55+
+ " \"Key\": \"Transaction\",\n"
56+
+ " \"Value\": {\n"
57+
+ " \"Name\": \"EarthOrbit\",\n"
58+
+ " \"StartCriteria\": [\n"
59+
+ " {\n"
60+
+ " \"Field\": \"url.path\",\n"
61+
+ " \"Operator\": \"==\",\n"
62+
+ " \"Value\": \"/earth\"\n"
63+
+ " }\n"
64+
+ " ],\n"
65+
+ " \"EndCriteria\": []\n"
66+
+ " }\n"
67+
+ " },\n"
68+
+ " {\n"
69+
+ " \"Key\": \"Transaction\",\n"
70+
+ " \"Value\": {\n"
71+
+ " \"Name\": \"MarsMission\",\n"
72+
+ " \"StartCriteria\": [\n"
73+
+ " {\n"
74+
+ " \"Field\": \"url.path\",\n"
75+
+ " \"Operator\": \"==\",\n"
76+
+ " \"Value\": \"/mars\"\n"
77+
+ " }\n"
78+
+ " ],\n"
79+
+ " \"EndCriteria\": [\n"
80+
+ " {\n"
81+
+ " \"Field\": \"messaging.operation\",\n"
82+
+ " \"Operator\": \"==\",\n"
83+
+ " \"Value\": \"process\"\n"
84+
+ " },\n"
85+
+ " {\n"
86+
+ " \"Field\": \"messaging.destination.name\",\n"
87+
+ " \"Operator\": \"==\",\n"
88+
+ " \"Value\": \"space\"\n"
89+
+ " }\n"
90+
+ " ]\n"
91+
+ " }\n"
92+
+ " }\n"
93+
+ " ]\n"
94+
+ "}\n"))
95+
.getSdkConfigurations()
96+
.stream()
97+
.map(SdkConfiguration::getValue)
98+
.collect(toList());
9599
} catch (IOException e) {
96100
throw new IllegalStateException(e);
97101
}

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionSampler.java

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/*
2-
* Copyright The OpenTelemetry Authors
3-
* SPDX-License-Identifier: Apache-2.0
4-
*/
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
53

64
package com.microsoft.applicationinsights.agent.internal.keytransaction;
75

@@ -33,8 +31,8 @@ private KeyTransactionSampler(Supplier<List<KeyTransactionConfig>> configs, Samp
3331
this.fallback = fallback;
3432
}
3533

36-
public static KeyTransactionSampler create(Supplier<List<KeyTransactionConfig>> configs,
37-
Sampler fallback) {
34+
public static KeyTransactionSampler create(
35+
Supplier<List<KeyTransactionConfig>> configs, Sampler fallback) {
3836
return new KeyTransactionSampler(configs, fallback);
3937
}
4038

@@ -56,16 +54,16 @@ public SamplingResult shouldSample(
5654
List<KeyTransactionConfig> configs = this.configs.get();
5755

5856
Set<String> existingKeyTransactions =
59-
KeyTransactionTraceState.getKeyTransactionStartTimes(spanContext.getTraceState())
60-
.keySet();
57+
KeyTransactionTraceState.getKeyTransactionStartTimes(spanContext.getTraceState()).keySet();
6158

6259
List<String> startKeyTransactions = new ArrayList<>();
6360
List<String> endKeyTransactions = new ArrayList<>();
6461
for (KeyTransactionConfig config : configs) {
6562

6663
if (existingKeyTransactions.contains(config.getName())) {
6764
// consider ending it
68-
if (!config.getEndCriteria().isEmpty() && KeyTransactionConfig.matches(attributes, config.getEndCriteria())) {
65+
if (!config.getEndCriteria().isEmpty()
66+
&& KeyTransactionConfig.matches(attributes, config.getEndCriteria())) {
6967
endKeyTransactions.add(config.getName());
7068
}
7169
} else {
@@ -83,11 +81,11 @@ public SamplingResult shouldSample(
8381

8482
// always delegate to fallback sampler to give it a chance to also modify trace state
8583
// or capture additional attributes
86-
SamplingResult result = fallback.shouldSample(parentContext, traceId, name, spanKind,
87-
attributes, parentLinks);
84+
SamplingResult result =
85+
fallback.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);
8886

89-
return new TransactionSamplingResult(existingKeyTransactions, startKeyTransactions,
90-
endKeyTransactions, result);
87+
return new TransactionSamplingResult(
88+
existingKeyTransactions, startKeyTransactions, endKeyTransactions, result);
9189
}
9290

9391
@Override
@@ -107,8 +105,10 @@ private static class TransactionSamplingResult implements SamplingResult {
107105
private final Collection<String> endKeyTransactions;
108106
private final SamplingResult delegate;
109107

110-
private TransactionSamplingResult(Collection<String> existingKeyTransactions,
111-
Collection<String> startKeyTransactions, Collection<String> endKeyTransactions,
108+
private TransactionSamplingResult(
109+
Collection<String> existingKeyTransactions,
110+
Collection<String> startKeyTransactions,
111+
Collection<String> endKeyTransactions,
112112
SamplingResult delegate) {
113113

114114
this.existingKeyTransactions = existingKeyTransactions;
@@ -158,9 +158,10 @@ public TraceState getUpdatedTraceState(TraceState parentTraceState) {
158158
// may not match span start time exactly
159159
long startTime = System.currentTimeMillis();
160160

161-
String newValue = startKeyTransactions.stream()
162-
.map(name -> name + ":" + startTime)
163-
.collect(Collectors.joining(";"));
161+
String newValue =
162+
startKeyTransactions.stream()
163+
.map(name -> name + ":" + startTime)
164+
.collect(Collectors.joining(";"));
164165

165166
String existingValue = updatedTraceState.get(KeyTransactionTraceState.TRACE_STATE_KEY);
166167

0 commit comments

Comments
 (0)