|
17 | 17 | import java.util.Map;
|
18 | 18 |
|
19 | 19 | import static java.util.Map.entry;
|
20 |
| -import static org.hamcrest.Matchers.sameInstance; |
21 | 20 |
|
22 | 21 | public class NormalizeToOTelProcessorTests extends ESTestCase {
|
23 | 22 |
|
@@ -121,8 +120,10 @@ public void testExecute_validOTelDocument() {
|
121 | 120 | entry("key1", "value1")
|
122 | 121 | );
|
123 | 122 | IngestDocument document = new IngestDocument("index", "id", 1, null, null, source);
|
| 123 | + Map<String, Object> shallowCopy = new HashMap<>(source); |
124 | 124 | processor.execute(document);
|
125 |
| - assertThat(source, sameInstance(document.getSource())); |
| 125 | + // verify that top level keys are not moved when processing a valid OTel document |
| 126 | + assertEquals(shallowCopy, document.getSource()); |
126 | 127 | }
|
127 | 128 |
|
128 | 129 | public void testExecute_nonOTelDocument() {
|
@@ -325,6 +326,35 @@ public void testExecute_moveToAttributeMaps() {
|
325 | 326 | assertFalse(source.containsKey("service"));
|
326 | 327 | }
|
327 | 328 |
|
| 329 | + public void testKeepNullValues() { |
| 330 | + Map<String, Object> source = new HashMap<>(); |
| 331 | + Map<String, Object> span = new HashMap<>(); |
| 332 | + span.put("id", null); |
| 333 | + source.put("span", span); |
| 334 | + source.put("log.level", null); |
| 335 | + source.put("trace_id", null); |
| 336 | + source.put("foo", null); |
| 337 | + source.put("agent.name", null); |
| 338 | + IngestDocument document = new IngestDocument("index", "id", 1, null, null, source); |
| 339 | + |
| 340 | + processor.execute(document); |
| 341 | + |
| 342 | + assertFalse(source.containsKey("span")); |
| 343 | + assertTrue(source.containsKey("span_id")); |
| 344 | + assertNull(source.get("span_id")); |
| 345 | + assertFalse(source.containsKey("log")); |
| 346 | + assertTrue(source.containsKey("severity_text")); |
| 347 | + assertNull(source.get("severity_text")); |
| 348 | + assertFalse(source.containsKey("trace_id")); |
| 349 | + Map<String, Object> expectedAttributes = new HashMap<>(); |
| 350 | + expectedAttributes.put("foo", null); |
| 351 | + expectedAttributes.put("trace_id", null); |
| 352 | + assertEquals(expectedAttributes, get(source, "attributes")); |
| 353 | + Map<String, Object> expectedResourceAttributes = new HashMap<>(); |
| 354 | + expectedResourceAttributes.put("agent.name", null); |
| 355 | + assertEquals(expectedResourceAttributes, get(get(source, "resource"), "attributes")); |
| 356 | + } |
| 357 | + |
328 | 358 | public void testExecute_deepFlattening() {
|
329 | 359 | Map<String, Object> source = new HashMap<>();
|
330 | 360 | Map<String, Object> nestedAgent = new HashMap<>();
|
|
0 commit comments