Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Codecov Report
@@ Coverage Diff @@
## rzp_main #58 +/- ##
==============================================
+ Coverage 79.45% 79.50% +0.04%
- Complexity 1311 1329 +18
==============================================
Files 118 119 +1
Lines 5271 5322 +51
Branches 481 486 +5
==============================================
+ Hits 4188 4231 +43
- Misses 865 870 +5
- Partials 218 221 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
| @Override | ||
| public void enrichEvent(StructuredTrace trace, Event event) { | ||
| try { | ||
| if (resourceAttributesToAdd == null || resourceAttributesToAdd.isEmpty()) { |
| if (resourceAttributesToAdd == null || resourceAttributesToAdd.isEmpty()) { | ||
| return; | ||
| } | ||
| if (event.getResourceIndex() < 0) { |
There was a problem hiding this comment.
Add all of these checks to a method validatePreconditions?
| return; | ||
| } | ||
| for (String resourceAttributeKey : resourceAttributesToAdd) { | ||
| Optional<AttributeValue> resourceAttribute = |
| attributeValue -> attributeMap.putIfAbsent(resourceAttributeKey, attributeValue)); | ||
| } | ||
| } catch (Exception e) { | ||
| LOGGER.error("Exception while enriching event with resource attributes.", e); |
|
|
||
| public static Optional<org.hypertrace.core.datamodel.AttributeValue> getAttribute( | ||
| Attributes attributes, String key) { | ||
| return Optional.ofNullable(attributes) |
There was a problem hiding this comment.
Didn't get you, findFirst in the map?
There was a problem hiding this comment.
See my latest comment on this. You can stream the map entries, add a filter and then do a findFirst. This returns an Optional by default. Cleaner IMO but this is fine too.
|
|
||
| when(event.getAttributes()).thenReturn(Attributes.newBuilder().build()); | ||
| when(event.getAttributes().getAttributeMap()).thenReturn(null); | ||
| resourceAttributeEnricher.enrichEvent(null, event); |
There was a problem hiding this comment.
What are you asserting in this test?
There was a problem hiding this comment.
error logs or any exception.
There was a problem hiding this comment.
Where's the assertion? A test method should only throw an AssertionError, as a result of an assertion failing. You can do:
try {
resourceAttributeEnricher.enrichEvent(null, event);
} catch (Exception e) {
throw new AssertionError("...")
}
There was a problem hiding this comment.
yeah, so I think this test is useless as I am not throwing any exceptions. removing it then.
| attributeMapSize = event.getAttributes().getAttributeMap().size(); | ||
| } | ||
| resourceAttributeEnricher.enrichEvent(trace, event); | ||
| if (event.getAttributes() != null && event.getAttributes().getAttributeMap() != null) { |
There was a problem hiding this comment.
Do you really need these checks if you're constructing the trace yourself?
There was a problem hiding this comment.
Yes. These checks were not before and some of the events of custom trace did not have these attributes which makes sense to test on different edge cases.
suddendust
left a comment
There was a problem hiding this comment.
First iteration, please address the changes.
Adds ResourceAttributeEnricher to attach infra metadata to span tags.