Skip to content

Commit 377bd98

Browse files
authored
GA sampling overrides (#3463)
1 parent 4b256b8 commit 377bd98

File tree

15 files changed

+205
-225
lines changed

15 files changed

+205
-225
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public static class Sampling {
166166

167167
// this config option only existed in one BETA release (3.4.0-BETA)
168168
@Deprecated @Nullable public Double limitPerSecond;
169+
170+
public List<SamplingOverride> overrides = new ArrayList<>();
169171
}
170172

171173
public static class SamplingPreview {
@@ -192,7 +194,7 @@ public static class SamplingPreview {
192194
// future goal: make parentBased sampling the default if item count is received via tracestate
193195
public boolean parentBased;
194196

195-
public List<SamplingOverride> overrides = new ArrayList<>();
197+
@Deprecated public List<SamplingOverride> overrides = new ArrayList<>();
196198
}
197199

198200
public static class JmxMetric {

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ private static void logConfigurationWarnings(Configuration config) {
194194
+ " and it is now enabled by default,"
195195
+ " so no need to enable it under preview configuration");
196196
}
197-
for (SamplingOverride override : config.preview.sampling.overrides) {
197+
198+
if (!config.preview.sampling.overrides.isEmpty()) {
199+
configurationLogger.warn(
200+
"\"Sampling overrides\" is no longer in preview and it has been GA since 3.5.0 GA,");
201+
config.sampling.overrides = config.preview.sampling.overrides;
202+
}
203+
for (SamplingOverride override : config.sampling.overrides) {
198204
if (override.telemetryKind != null) {
199205
configurationLogger.warn(
200206
"Sampling overrides \"telemetryKind\" has been deprecated,"
@@ -258,7 +264,7 @@ private static void overlayConfiguration(
258264
Path agentJarPath, RpConfiguration rpConfiguration, Configuration config) throws IOException {
259265
overlayFromEnv(config, agentJarPath.getParent());
260266
config.sampling.percentage = roundToNearest(config.sampling.percentage, true);
261-
for (SamplingOverride override : config.preview.sampling.overrides) {
267+
for (SamplingOverride override : config.sampling.overrides) {
262268
supportSamplingOverridesOldSemConv(override);
263269
override.percentage = roundToNearest(override.percentage, true);
264270
}
@@ -345,7 +351,7 @@ private static String mapAttributeKey(String oldAttributeKey) {
345351
// HTTP client span attributes
346352
// http.url is handled via LazyHttpUrl
347353
if (oldAttributeKey.equals(SemanticAttributes.HTTP_RESEND_COUNT.getKey())) {
348-
result = "http.request.resend_count"; // TODO (heya) use upstream SemanticAttributes when it
354+
result = SemanticAttributes.HTTP_REQUEST_RESEND_COUNT.getKey();
349355
// becomes available.
350356
} else if (oldAttributeKey.equals(SemanticAttributes.NET_PEER_NAME.getKey())) {
351357
result = SemanticAttributes.SERVER_ADDRESS.getKey();
@@ -393,7 +399,7 @@ private static void logWarningIfUsingInternalAttributes(Configuration config) {
393399
}
394400
}
395401
}
396-
for (SamplingOverride override : config.preview.sampling.overrides) {
402+
for (SamplingOverride override : config.sampling.overrides) {
397403
for (Configuration.SamplingOverrideAttribute attribute : override.attributes) {
398404
logWarningIfUsingInternalAttributes(attribute.key);
399405
}

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/etw/EtwAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void start() {
4545
this.etwProvider.writeEvent(event);
4646
} catch (LinkageError | ApplicationInsightsEtwException e) {
4747
String message = "EtwProvider failed to initialize.";
48-
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME).error(message, e);
48+
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME).debug(message, e);
4949
addError(message, e);
5050

5151
StatusFile.putValue("EtwProviderInitialized", "false");

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/RuntimeConfigurator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ private static RuntimeConfiguration captureInitialConfig(Configuration initialCo
6767
runtimeConfig.sampling.requestsPerSecond = initialConfig.sampling.requestsPerSecond;
6868
runtimeConfig.samplingPreview.parentBased = initialConfig.preview.sampling.parentBased;
6969
// TODO (trask) make deep copies? (not needed currently)
70-
runtimeConfig.samplingPreview.overrides =
71-
new ArrayList<>(initialConfig.preview.sampling.overrides);
70+
runtimeConfig.sampling.overrides = new ArrayList<>(initialConfig.sampling.overrides);
7271

7372
runtimeConfig.propagationDisabled = initialConfig.preview.disablePropagation;
7473
runtimeConfig.additionalPropagators =
@@ -94,7 +93,7 @@ private static RuntimeConfiguration copy(RuntimeConfiguration config) {
9493
copy.sampling.requestsPerSecond = config.sampling.requestsPerSecond;
9594
copy.samplingPreview.parentBased = config.samplingPreview.parentBased;
9695
// TODO (trask) make deep copies? (not needed currently)
97-
copy.samplingPreview.overrides = new ArrayList<>(config.samplingPreview.overrides);
96+
copy.sampling.overrides = new ArrayList<>(config.sampling.overrides);
9897

9998
copy.propagationDisabled = config.propagationDisabled;
10099
copy.additionalPropagators = new ArrayList<>(config.additionalPropagators);

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ private static LogRecordExporter createLogExporter(
644644
telemetryClient::populateDefaults);
645645

646646
List<Configuration.SamplingOverride> logSamplingOverrides =
647-
configuration.preview.sampling.overrides.stream()
647+
configuration.sampling.overrides.stream()
648648
.filter(override -> override.telemetryType == SamplingTelemetryType.TRACE)
649649
.collect(Collectors.toList());
650650
List<Configuration.SamplingOverride> exceptionSamplingOverrides =
651-
configuration.preview.sampling.overrides.stream()
651+
configuration.sampling.overrides.stream()
652652
.filter(override -> override.telemetryType == SamplingTelemetryType.EXCEPTION)
653653
.collect(Collectors.toList());
654654

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/Samplers.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class Samplers {
1313

1414
public static Sampler getSampler(
1515
Configuration.Sampling sampling, Configuration.SamplingPreview samplingPreview) {
16-
1716
Sampler sampler;
1817
if (sampling.requestsPerSecond != null) {
1918
SamplingPercentage requestSamplingPercentage =
@@ -28,11 +27,11 @@ public static Sampler getSampler(
2827
}
2928

3029
List<SamplingOverride> requestSamplingOverrides =
31-
samplingPreview.overrides.stream()
30+
sampling.overrides.stream()
3231
.filter(SamplingOverride::isForRequestTelemetry)
3332
.collect(Collectors.toList());
3433
List<SamplingOverride> dependencySamplingOverrides =
35-
samplingPreview.overrides.stream()
34+
sampling.overrides.stream()
3635
.filter(SamplingOverride::isForDependencyTelemetry)
3736
.collect(Collectors.toList());
3837

licenses/more-licenses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# agent
33
## Dependency License Report
4-
_2024-02-23 20:42:45 PST_
4+
_2024-02-26 11:03:42 PST_
55
## Apache License, Version 2.0
66

77
**1** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-annotations` **Version:** `2.16.1`

smoke-tests/apps/HttpHeaders/src/smokeTest/resources/applicationinsights.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
"instance": "testroleinstance"
55
},
66
"sampling": {
7-
"percentage": 100
7+
"percentage": 100,
8+
"overrides": [
9+
{
10+
"attributes": [
11+
{
12+
"key": "http.request.header.abc-def",
13+
"value": "nope",
14+
"matchType": "strict"
15+
}
16+
],
17+
"percentage": 0
18+
}
19+
]
820
},
921
"preview": {
1022
"captureHttpServerHeaders": {
@@ -22,20 +34,6 @@
2234
"responseHeaders": [
2335
"date"
2436
]
25-
},
26-
"sampling": {
27-
"overrides": [
28-
{
29-
"attributes": [
30-
{
31-
"key": "http.request.header.abc-def",
32-
"value": "nope",
33-
"matchType": "strict"
34-
}
35-
],
36-
"percentage": 0
37-
}
38-
]
3937
}
4038
}
4139
}

smoke-tests/apps/SamplingOverrides/src/smokeTest/resources/applicationinsights-exception-with-sampling-overrides.json

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,24 @@
44
"instance": "testroleinstance"
55
},
66
"sampling": {
7-
"percentage": 100
8-
},
9-
"preview": {
10-
"sampling": {
11-
"overrides": [
12-
{
13-
"telemetryType": "exception",
14-
"attributes": [
15-
{
16-
"key": "exception.message",
17-
"value": "this is an expected exception",
18-
"matchType": "strict"
19-
},
20-
{
21-
"key": "exception.type",
22-
"value": "java.lang.RuntimeException",
23-
"matchType": "strict"
24-
}
25-
],
26-
"percentage": 0
27-
}
28-
]
29-
}
7+
"percentage": 100,
8+
"overrides": [
9+
{
10+
"telemetryType": "exception",
11+
"attributes": [
12+
{
13+
"key": "exception.message",
14+
"value": "this is an expected exception",
15+
"matchType": "strict"
16+
},
17+
{
18+
"key": "exception.type",
19+
"value": "java.lang.RuntimeException",
20+
"matchType": "strict"
21+
}
22+
],
23+
"percentage": 0
24+
}
25+
]
3026
}
3127
}

smoke-tests/apps/SamplingOverrides/src/smokeTest/resources/applicationinsights-thread-name.json

Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,67 @@
55
"instance": "testroleinstance"
66
},
77
"sampling": {
8-
"percentage": 50
9-
},
10-
"preview": {
11-
"sampling": {
12-
"overrides": [
13-
{
14-
"telemetryType": "request",
15-
"attributes": [
16-
{
17-
"key": "thread.name",
18-
"value": "http-nio-.*",
19-
"matchType": "regexp"
20-
},
21-
{
22-
"key": "http.target",
23-
"value": "/SamplingOverrides/health-check",
24-
"matchType": "strict"
25-
}
26-
],
27-
"percentage": 100
28-
},
29-
{
30-
"telemetryType": "request",
31-
"attributes": [
32-
{
33-
"key": "thread.name",
34-
"value": "http-nio-.*",
35-
"matchType": "regexp"
36-
},
37-
{
38-
"key": "http.target",
39-
"value": "/SamplingOverrides/",
40-
"matchType": "strict"
41-
}
42-
],
43-
"percentage": 100
44-
},
45-
{
46-
"telemetryType": "request",
47-
"attributes": [
48-
{
49-
"key": "thread.name",
50-
"value": "http-nio-.*",
51-
"matchType": "regexp"
52-
},
53-
{
54-
"key": "http.target",
55-
"value": "/SamplingOverrides/thread-name",
56-
"matchType": "strict"
57-
}
58-
],
59-
"percentage": 0
60-
},
61-
{
62-
"telemetryType": "trace",
63-
"attributes": [
64-
{
65-
"key": "thread.name",
66-
"value": "http-nio-.*",
67-
"matchType": "regexp"
68-
}
69-
],
70-
"percentage": 0
71-
}
72-
]
73-
}
8+
"percentage": 50,
9+
"overrides": [
10+
{
11+
"telemetryType": "request",
12+
"attributes": [
13+
{
14+
"key": "thread.name",
15+
"value": "http-nio-.*",
16+
"matchType": "regexp"
17+
},
18+
{
19+
"key": "http.target",
20+
"value": "/SamplingOverrides/health-check",
21+
"matchType": "strict"
22+
}
23+
],
24+
"percentage": 100
25+
},
26+
{
27+
"telemetryType": "request",
28+
"attributes": [
29+
{
30+
"key": "thread.name",
31+
"value": "http-nio-.*",
32+
"matchType": "regexp"
33+
},
34+
{
35+
"key": "http.target",
36+
"value": "/SamplingOverrides/",
37+
"matchType": "strict"
38+
}
39+
],
40+
"percentage": 100
41+
},
42+
{
43+
"telemetryType": "request",
44+
"attributes": [
45+
{
46+
"key": "thread.name",
47+
"value": "http-nio-.*",
48+
"matchType": "regexp"
49+
},
50+
{
51+
"key": "http.target",
52+
"value": "/SamplingOverrides/thread-name",
53+
"matchType": "strict"
54+
}
55+
],
56+
"percentage": 0
57+
},
58+
{
59+
"telemetryType": "trace",
60+
"attributes": [
61+
{
62+
"key": "thread.name",
63+
"value": "http-nio-.*",
64+
"matchType": "regexp"
65+
}
66+
],
67+
"percentage": 0
68+
}
69+
]
7470
}
7571
}

0 commit comments

Comments
 (0)