opentelemetry-java-instrumentation
opentelemetry-java-instrumentation copied to clipboard
Remove Attributes combination from onEnd
Hopefully resolves https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11887
Remove reduntant attributes combination in OperationListener.onEnd, move all attributes extract to AttributesExtractor.onEnd
Also see https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/11092
Did you consider using something like
public final class CompositeAttributes implements Attributes {
private final Attributes first;
private final Attributes second;
private CompositeAttributes(Attributes first, Attributes second) {
this.first = first;
this.second = second;
}
public static Attributes of(Attributes first, Attributes second) {
return new CompositeAttributes(first, second);
}
@Nullable
@Override
public <T> T get(AttributeKey<T> attributeKey) {
T value = first.get(attributeKey);
if (value != null) {
return value;
}
return second.get(attributeKey);
}
@Override
public void forEach(BiConsumer<? super AttributeKey<?>, ? super Object> biConsumer) {
first.forEach(biConsumer);
second.forEach(biConsumer);
}
@Override
public int size() {
return first.size() + second.size();
}
@Override
public boolean isEmpty() {
return first.isEmpty() && second.isEmpty();
}
@Override
public Map<AttributeKey<?>, Object> asMap() {
Map<AttributeKey<?>, Object> map = new HashMap<>();
map.putAll(first.asMap());
map.putAll(second.asMap());
return map;
}
@Override
public AttributesBuilder toBuilder() {
return first.toBuilder().putAll(second);
}
}
@wgy035 have you had a chance to check whether composing the start and end attributes as described above would help?
@wgy035 have you had a chance to check whether composing the start and end attributes as described above would help?
@laurit yep, using such a composite structure will reduce traverse overhead and approximately a CompositeAttributesBuilder is also needed, now I'm testing the performance improvement and the code will be updated with a new commit.
This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 14 days.