Skip to content

Commit d28fc3d

Browse files
authored
fix for issue where null pointer exception is thrown when attribute value is not provided and matchType is regexp (#1400)
1 parent e276b1c commit d28fc3d

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
# Version 3.0.1 GA
4+
* Telemetry processor config throws null pointer exception when attribute value is not provided and matchType is regexp
5+
36
# Version 3.0.0 GA
47
* Config changes
58
- Change json config file name from ApplicationInsights.json to applicationinsights.json

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public static RegexpIncludeExclude create(ProcessorIncludeExclude includeExclude
110110
Map<AttributeKey<?>, Pattern> attributeKeyValuePatterns = new HashMap<>();
111111
if (attributes != null) {
112112
for (ProcessorAttribute attribute : attributes) {
113-
attributeKeyValuePatterns.put(AttributeKey.stringKey(attribute.key), Pattern.compile(attribute.value));
113+
if (attribute.value != null) {
114+
attributeKeyValuePatterns.put(AttributeKey.stringKey(attribute.key), Pattern.compile(attribute.value));
115+
}
114116
}
115117
}
116118
List<Pattern> spanPatterns = new ArrayList<>();

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithAttributeProcessorTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,77 @@ public void simpleIncludeRegexValueTest() {
682682
assertEquals("testV1", Objects.requireNonNull(resultSpanE.getAttributes().get(AttributeKey.stringKey("testKey"))));
683683
}
684684

685+
@Test
686+
public void simpleIncludeRegexNoValueTest() {
687+
MockExporter mockExporter = new MockExporter();
688+
ProcessorConfig config = new ProcessorConfig();
689+
config.type = ProcessorType.attribute;
690+
config.processorName = "simpleIncludeRegexNoValue";
691+
config.include = new ProcessorIncludeExclude();
692+
config.include.matchType = ProcessorMatchType.regexp;
693+
config.include.spanNames = Arrays.asList("svc.*", "test.*");
694+
ProcessorAttribute attributeWithNoValue = new ProcessorAttribute();
695+
attributeWithNoValue.key = "testKey";
696+
config.include.attributes = new ArrayList<>();
697+
config.include.attributes.add(attributeWithNoValue);
698+
ProcessorAction action = new ProcessorAction();
699+
action.key = "testKey";
700+
action.action = ProcessorActionType.update;
701+
action.value = "redacted";
702+
List<ProcessorAction> actions = new ArrayList<>();
703+
actions.add(action);
704+
config.actions = actions;
705+
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
706+
707+
Span spanA = OpenTelemetry.getGlobalTracer("test").spanBuilder("svcA")
708+
.setAttribute("one", "1")
709+
.setAttribute("two", 2L)
710+
.setAttribute("testKey", "testValue1")
711+
.setAttribute("testKey2", "testValue2")
712+
.startSpan();
713+
Span spanB = OpenTelemetry.getGlobalTracer("test").spanBuilder("svcB")
714+
.setAttribute("one", "1")
715+
.setAttribute("testKey", "testValue2")
716+
.setAttribute("testKey2", "testValue2")
717+
.startSpan();
718+
Span spanC = OpenTelemetry.getGlobalTracer("test").spanBuilder("serviceC")
719+
.setAttribute("two", 2L)
720+
.setAttribute("testKey", "testValue")
721+
.setAttribute("testKey2", "testValue2")
722+
.startSpan();
723+
Span spanD = OpenTelemetry.getGlobalTracer("test").spanBuilder("serviceD")
724+
.setAttribute("one", "1")
725+
.setAttribute("two", 2L)
726+
.setAttribute("testKey", "testValue")
727+
.setAttribute("testKey2", "testValue2")
728+
.startSpan();
729+
Span spanE = OpenTelemetry.getGlobalTracer("test").spanBuilder("svcE")
730+
.setAttribute("one", "1")
731+
.setAttribute("two", 2L)
732+
.setAttribute("testKey", "testV1")
733+
.setAttribute("testKey2", "testValue2")
734+
.startSpan();
735+
List<SpanData> spans = new ArrayList<>();
736+
spans.add(((ReadableSpan) spanA).toSpanData());
737+
spans.add(((ReadableSpan) spanB).toSpanData());
738+
spans.add(((ReadableSpan) spanC).toSpanData());
739+
spans.add(((ReadableSpan) spanD).toSpanData());
740+
spans.add(((ReadableSpan) spanE).toSpanData());
741+
742+
exampleExporter.export(spans);
743+
744+
// verify that resulting spans are filtered in the way we want
745+
List<SpanData> result = mockExporter.getSpans();
746+
SpanData resultSpanA = result.get(0);
747+
SpanData resultSpanB = result.get(1);
748+
SpanData resultSpanC = result.get(2);
749+
SpanData resultSpanE = result.get(4);
750+
assertEquals("redacted", Objects.requireNonNull(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey"))));
751+
assertEquals("redacted", Objects.requireNonNull(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))));
752+
assertEquals("testValue", Objects.requireNonNull(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))));
753+
assertEquals("redacted", Objects.requireNonNull(resultSpanE.getAttributes().get(AttributeKey.stringKey("testKey"))));
754+
}
755+
685756
@Test
686757
public void simpleIncludeHashTest() {
687758
MockExporter mockExporter = new MockExporter();

0 commit comments

Comments
 (0)