Skip to content

Commit 49cc5d6

Browse files
authored
Add metric filtering capability (#1728)
* Add metric filtering capability * Change enums to uppercase * Spotbugs
1 parent 8c4d65e commit 49cc5d6

File tree

19 files changed

+508
-212
lines changed

19 files changed

+508
-212
lines changed

agent/agent-tooling/spotbugs.exclude.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@
9999
</Match>
100100
<Match>
101101
<Bug pattern="NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD" />
102-
<Class name="com.microsoft.applicationinsights.agent.internal.processors.SpanProcessor" />
103-
<Method name="create" />
102+
<Or>
103+
<And>
104+
<Class name="com.microsoft.applicationinsights.agent.internal.processors.SpanProcessor" />
105+
<Method name="create" />
106+
</And>
107+
<And>
108+
<Class name="com.microsoft.applicationinsights.agent.internal.wasbootstrap.configuration.Configuration$ProcessorIncludeExclude" />
109+
</And>
110+
</Or>
104111
</Match>
105112
</FindBugsFilter>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.net.URI;
6767
import java.util.ArrayList;
6868
import java.util.concurrent.CountDownLatch;
69+
import java.util.stream.Collectors;
6970

7071
import static java.util.concurrent.TimeUnit.MINUTES;
7172
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -154,6 +155,10 @@ private static void start(Instrumentation instrumentation) {
154155
TelemetryConfigurationFactory.INSTANCE.initialize(configuration, buildXmlConfiguration(config));
155156
configuration.getContextInitializers().add(new SdkVersionContextInitializer());
156157
configuration.getContextInitializers().add(new ResourceAttributesContextInitializer(config.customDimensions));
158+
configuration.setMetricFilters(config.preview.processors.stream()
159+
.filter(processor -> processor.type == Configuration.ProcessorType.METRIC_FILTER)
160+
.map(Configuration.ProcessorConfig::toMetricFilter)
161+
.collect(Collectors.toList()));
157162

158163
try {
159164
ConnectionString.updateStatsbeatConnectionString(config.internal.statsbeat.instrumentationKey, config.internal.statsbeat.endpoint, configuration);

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/processors/AgentProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AgentProcessor(@Nullable IncludeExclude include,
4646
}
4747

4848
protected static AttributeProcessor.IncludeExclude getNormalizedIncludeExclude(ProcessorIncludeExclude includeExclude) {
49-
return includeExclude.matchType == MatchType.strict ? AgentProcessor.StrictIncludeExclude.create(includeExclude) : AgentProcessor.RegexpIncludeExclude.create(includeExclude);
49+
return includeExclude.matchType == MatchType.STRICT ? AgentProcessor.StrictIncludeExclude.create(includeExclude) : AgentProcessor.RegexpIncludeExclude.create(includeExclude);
5050
}
5151

5252
public @Nullable IncludeExclude getInclude() {

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/processors/AttributeProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ public SpanData processActions(SpanData span) {
7777

7878
private SpanData processAction(SpanData span, ProcessorAction actionObj) {
7979
switch (actionObj.action) {
80-
case insert:
80+
case INSERT:
8181
return processInsertAction(span, actionObj);
82-
case update:
82+
case UPDATE:
8383
return processUpdateAction(span, actionObj);
84-
case delete:
84+
case DELETE:
8585
return processDeleteAction(span, actionObj);
86-
case hash:
86+
case HASH:
8787
return procesHashAction(span, actionObj);
88-
case extract:
88+
case EXTRACT:
8989
return processExtractAction(span, actionObj);
9090
default:
9191
return span;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ private boolean matches(Attributes attributes) {
144144
}
145145

146146
private static Predicate<Attributes> toPredicate(SamplingOverrideAttribute attribute) {
147-
if (attribute.matchType == MatchType.strict) {
147+
if (attribute.matchType == MatchType.STRICT) {
148148
return new StrictMatcher(attribute.key, attribute.value);
149-
} else if (attribute.matchType == MatchType.regexp) {
149+
} else if (attribute.matchType == MatchType.REGEXP) {
150150
return new RegexpMatcher(attribute.key, attribute.value);
151151
} else {
152152
throw new IllegalStateException("Unexpected match type: " + attribute.matchType);

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/OpenTelemetryConfigurer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.List;
22+
import java.util.stream.Collectors;
2223

2324
public class OpenTelemetryConfigurer implements SdkTracerProviderConfigurer {
2425

@@ -43,7 +44,9 @@ public void configure(SdkTracerProviderBuilder tracerProvider) {
4344
// and the default for DelegatingSampler is to not sample anything)
4445
}
4546

46-
List<ProcessorConfig> processors = new ArrayList<>(config.preview.processors);
47+
List<ProcessorConfig> processors = config.preview.processors.stream()
48+
.filter(processor -> processor.type != Configuration.ProcessorType.METRIC_FILTER)
49+
.collect(Collectors.toCollection(ArrayList::new));
4750
// Reversing the order of processors before passing it to SpanProcessor
4851
Collections.reverse(processors);
4952

@@ -53,13 +56,13 @@ public void configure(SdkTracerProviderBuilder tracerProvider) {
5356
for (ProcessorConfig processorConfig : processors) {
5457
if (processorConfig.type != null) { // Added this condition to resolve spotbugs NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD issue
5558
switch (processorConfig.type) {
56-
case attribute:
59+
case ATTRIBUTE:
5760
currExporter = new ExporterWithAttributeProcessor(processorConfig, currExporter);
5861
break;
59-
case span:
62+
case SPAN:
6063
currExporter = new ExporterWithSpanProcessor(processorConfig, currExporter);
6164
break;
62-
case log:
65+
case LOG:
6366
currExporter = new ExporterWithLogProcessor(processorConfig, currExporter);
6467
break;
6568
default:

0 commit comments

Comments
 (0)