Skip to content

Commit

Permalink
GA sampling overrides (#3463)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyams committed Feb 26, 2024
1 parent 4b256b8 commit 377bd98
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public static class Sampling {

// this config option only existed in one BETA release (3.4.0-BETA)
@Deprecated @Nullable public Double limitPerSecond;

public List<SamplingOverride> overrides = new ArrayList<>();
}

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

public List<SamplingOverride> overrides = new ArrayList<>();
@Deprecated public List<SamplingOverride> overrides = new ArrayList<>();
}

public static class JmxMetric {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ private static void logConfigurationWarnings(Configuration config) {
+ " and it is now enabled by default,"
+ " so no need to enable it under preview configuration");
}
for (SamplingOverride override : config.preview.sampling.overrides) {

if (!config.preview.sampling.overrides.isEmpty()) {
configurationLogger.warn(
"\"Sampling overrides\" is no longer in preview and it has been GA since 3.5.0 GA,");
config.sampling.overrides = config.preview.sampling.overrides;
}
for (SamplingOverride override : config.sampling.overrides) {
if (override.telemetryKind != null) {
configurationLogger.warn(
"Sampling overrides \"telemetryKind\" has been deprecated,"
Expand Down Expand Up @@ -258,7 +264,7 @@ private static void overlayConfiguration(
Path agentJarPath, RpConfiguration rpConfiguration, Configuration config) throws IOException {
overlayFromEnv(config, agentJarPath.getParent());
config.sampling.percentage = roundToNearest(config.sampling.percentage, true);
for (SamplingOverride override : config.preview.sampling.overrides) {
for (SamplingOverride override : config.sampling.overrides) {
supportSamplingOverridesOldSemConv(override);
override.percentage = roundToNearest(override.percentage, true);
}
Expand Down Expand Up @@ -345,7 +351,7 @@ private static String mapAttributeKey(String oldAttributeKey) {
// HTTP client span attributes
// http.url is handled via LazyHttpUrl
if (oldAttributeKey.equals(SemanticAttributes.HTTP_RESEND_COUNT.getKey())) {
result = "http.request.resend_count"; // TODO (heya) use upstream SemanticAttributes when it
result = SemanticAttributes.HTTP_REQUEST_RESEND_COUNT.getKey();
// becomes available.
} else if (oldAttributeKey.equals(SemanticAttributes.NET_PEER_NAME.getKey())) {
result = SemanticAttributes.SERVER_ADDRESS.getKey();
Expand Down Expand Up @@ -393,7 +399,7 @@ private static void logWarningIfUsingInternalAttributes(Configuration config) {
}
}
}
for (SamplingOverride override : config.preview.sampling.overrides) {
for (SamplingOverride override : config.sampling.overrides) {
for (Configuration.SamplingOverrideAttribute attribute : override.attributes) {
logWarningIfUsingInternalAttributes(attribute.key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void start() {
this.etwProvider.writeEvent(event);
} catch (LinkageError | ApplicationInsightsEtwException e) {
String message = "EtwProvider failed to initialize.";
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME).error(message, e);
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME).debug(message, e);
addError(message, e);

StatusFile.putValue("EtwProviderInitialized", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ private static RuntimeConfiguration captureInitialConfig(Configuration initialCo
runtimeConfig.sampling.requestsPerSecond = initialConfig.sampling.requestsPerSecond;
runtimeConfig.samplingPreview.parentBased = initialConfig.preview.sampling.parentBased;
// TODO (trask) make deep copies? (not needed currently)
runtimeConfig.samplingPreview.overrides =
new ArrayList<>(initialConfig.preview.sampling.overrides);
runtimeConfig.sampling.overrides = new ArrayList<>(initialConfig.sampling.overrides);

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

copy.propagationDisabled = config.propagationDisabled;
copy.additionalPropagators = new ArrayList<>(config.additionalPropagators);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ private static LogRecordExporter createLogExporter(
telemetryClient::populateDefaults);

List<Configuration.SamplingOverride> logSamplingOverrides =
configuration.preview.sampling.overrides.stream()
configuration.sampling.overrides.stream()
.filter(override -> override.telemetryType == SamplingTelemetryType.TRACE)
.collect(Collectors.toList());
List<Configuration.SamplingOverride> exceptionSamplingOverrides =
configuration.preview.sampling.overrides.stream()
configuration.sampling.overrides.stream()
.filter(override -> override.telemetryType == SamplingTelemetryType.EXCEPTION)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class Samplers {

public static Sampler getSampler(
Configuration.Sampling sampling, Configuration.SamplingPreview samplingPreview) {

Sampler sampler;
if (sampling.requestsPerSecond != null) {
SamplingPercentage requestSamplingPercentage =
Expand All @@ -28,11 +27,11 @@ public static Sampler getSampler(
}

List<SamplingOverride> requestSamplingOverrides =
samplingPreview.overrides.stream()
sampling.overrides.stream()
.filter(SamplingOverride::isForRequestTelemetry)
.collect(Collectors.toList());
List<SamplingOverride> dependencySamplingOverrides =
samplingPreview.overrides.stream()
sampling.overrides.stream()
.filter(SamplingOverride::isForDependencyTelemetry)
.collect(Collectors.toList());

Expand Down
2 changes: 1 addition & 1 deletion licenses/more-licenses.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# agent
## Dependency License Report
_2024-02-23 20:42:45 PST_
_2024-02-26 11:03:42 PST_
## Apache License, Version 2.0

**1** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-annotations` **Version:** `2.16.1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
"instance": "testroleinstance"
},
"sampling": {
"percentage": 100
"percentage": 100,
"overrides": [
{
"attributes": [
{
"key": "http.request.header.abc-def",
"value": "nope",
"matchType": "strict"
}
],
"percentage": 0
}
]
},
"preview": {
"captureHttpServerHeaders": {
Expand All @@ -22,20 +34,6 @@
"responseHeaders": [
"date"
]
},
"sampling": {
"overrides": [
{
"attributes": [
{
"key": "http.request.header.abc-def",
"value": "nope",
"matchType": "strict"
}
],
"percentage": 0
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@
"instance": "testroleinstance"
},
"sampling": {
"percentage": 100
},
"preview": {
"sampling": {
"overrides": [
{
"telemetryType": "exception",
"attributes": [
{
"key": "exception.message",
"value": "this is an expected exception",
"matchType": "strict"
},
{
"key": "exception.type",
"value": "java.lang.RuntimeException",
"matchType": "strict"
}
],
"percentage": 0
}
]
}
"percentage": 100,
"overrides": [
{
"telemetryType": "exception",
"attributes": [
{
"key": "exception.message",
"value": "this is an expected exception",
"matchType": "strict"
},
{
"key": "exception.type",
"value": "java.lang.RuntimeException",
"matchType": "strict"
}
],
"percentage": 0
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,67 @@
"instance": "testroleinstance"
},
"sampling": {
"percentage": 50
},
"preview": {
"sampling": {
"overrides": [
{
"telemetryType": "request",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
},
{
"key": "http.target",
"value": "/SamplingOverrides/health-check",
"matchType": "strict"
}
],
"percentage": 100
},
{
"telemetryType": "request",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
},
{
"key": "http.target",
"value": "/SamplingOverrides/",
"matchType": "strict"
}
],
"percentage": 100
},
{
"telemetryType": "request",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
},
{
"key": "http.target",
"value": "/SamplingOverrides/thread-name",
"matchType": "strict"
}
],
"percentage": 0
},
{
"telemetryType": "trace",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
}
],
"percentage": 0
}
]
}
"percentage": 50,
"overrides": [
{
"telemetryType": "request",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
},
{
"key": "http.target",
"value": "/SamplingOverrides/health-check",
"matchType": "strict"
}
],
"percentage": 100
},
{
"telemetryType": "request",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
},
{
"key": "http.target",
"value": "/SamplingOverrides/",
"matchType": "strict"
}
],
"percentage": 100
},
{
"telemetryType": "request",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
},
{
"key": "http.target",
"value": "/SamplingOverrides/thread-name",
"matchType": "strict"
}
],
"percentage": 0
},
{
"telemetryType": "trace",
"attributes": [
{
"key": "thread.name",
"value": "http-nio-.*",
"matchType": "regexp"
}
],
"percentage": 0
}
]
}
}
Loading

0 comments on commit 377bd98

Please sign in to comment.