Skip to content

Commit

Permalink
refactor: add null-check
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Oct 11, 2024
1 parent b3e944d commit 9266d45
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.opentelemetry.sdk.trace.data.SpanData;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
import rocks.inspectit.gepard.agent.instrumentation.hook.action.exception.SdkSpanClassNotFoundException;

/**
Expand Down Expand Up @@ -39,18 +40,17 @@ private SpanUtil() {}
*/
public static boolean spanAlreadyExists(String spanName)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Span span = Span.current();
if (Objects.isNull(SDKSPAN_CLASS)) return false;

if (!SDKSPAN_CLASS.isInstance(span)) {
Span span = Span.current();
if (!SDKSPAN_CLASS.isInstance(span))
throw new IllegalArgumentException("The provided Span is not an instance of SdkSpan.");
}

Object sdkSpan = SDKSPAN_CLASS.cast(span);
Method toSpanData = SDKSPAN_CLASS.getDeclaredMethod("toSpanData");
toSpanData.setAccessible(true);

SpanData spanData = (SpanData) toSpanData.invoke(sdkSpan);

return spanName.equals(spanData.getName());
}
}

0 comments on commit 9266d45

Please sign in to comment.