Skip to content

Commit

Permalink
Fix concurrent issue in observability
Browse files Browse the repository at this point in the history
  • Loading branch information
NipunaMadhushan committed Jun 20, 2024
1 parent 52176f1 commit 83447fc
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class OpenTracerBallerinaWrapper {
private static OpenTracerBallerinaWrapper instance = new OpenTracerBallerinaWrapper();
private TracersStore tracerStore;
private final boolean enabled;
private Map<Long, ObserverContext> observerContextList = new HashMap<>();
private ConcurrentMap<Long, ObserverContext> observerContextList = new ConcurrentHashMap<>();
private AtomicLong spanId = new AtomicLong();
private static final int SYSTEM_TRACE_INDICATOR = -1;

Expand Down Expand Up @@ -126,7 +126,10 @@ public boolean finishSpan(Strand strand, long spanId) {
if (!enabled) {
return false;
}
ObserverContext observerContext = observerContextList.get(spanId);
ObserverContext observerContext = null;
if (observerContextList.containsKey(spanId)) {
observerContext = observerContextList.get(spanId);
}
if (observerContext != null) {
if (observerContext.isSystemSpan()) {
ObserveUtils.setObserverContextToCurrentFrame(strand, observerContext.getParent());
Expand All @@ -153,7 +156,10 @@ public boolean addTag(String tagKey, String tagValue, long spanId, Strand strand
if (!enabled) {
return false;
}
ObserverContext observerContext = observerContextList.get(spanId);
ObserverContext observerContext = null;
if (observerContextList.containsKey(spanId)) {
observerContext = observerContextList.get(spanId);
}
if (spanId == -1) {
Optional<ObserverContext> observer = ObserveUtils.getObserverContextOfCurrentFrame(strand);
if (observer.isPresent()) {
Expand Down

0 comments on commit 83447fc

Please sign in to comment.