Skip to content

Commit 44adae0

Browse files
authored
Fail if HTTP status code used in sampling override (#3708)
1 parent d1e8cc7 commit 44adae0

File tree

1 file changed

+11
-0
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.microsoft.applicationinsights.agent.internal.diagnostics.status.StatusFile;
1616
import io.opentelemetry.api.common.AttributeKey;
1717
import io.opentelemetry.api.logs.Severity;
18+
import io.opentelemetry.semconv.HttpAttributes;
1819
import java.io.File;
1920
import java.util.ArrayList;
2021
import java.util.HashMap;
@@ -717,6 +718,16 @@ private void validate() {
717718
"A sampling override configuration has an attribute section with a \"value\" that is missing a \"matchType\".",
718719
"Please provide a \"matchType\" under the attribute section of the sampling override configuration.");
719720
}
721+
String httpStatusCodeKey = HttpAttributes.HTTP_RESPONSE_STATUS_CODE.getKey();
722+
if (httpStatusCodeKey.equals(key)) {
723+
throw new FriendlyException(
724+
"You can't use the \""
725+
+ httpStatusCodeKey
726+
+ "\" attribute for sampling overrides because you can only use the attributes set at the start of a span.",
727+
"Please remove the \""
728+
+ httpStatusCodeKey
729+
+ "\" attribute from the sampling override configuration and look at https://learn.microsoft.com/azure/azure-monitor/app/java-standalone-sampling-overrides for an alternative solution.");
730+
}
720731
if (matchType == MatchType.REGEXP) {
721732
if (isEmpty(value)) {
722733
// TODO add doc and go link, similar to telemetry processors

0 commit comments

Comments
 (0)