-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-native): support for starting native spans on android (#536)
* feat(react-native): support for starting native spans on android * refactor(react-native): add ReactNativeSpanContext class * refactor(react-native): use constants for hex radix and trace id midpoint values * fix(react-native): update `isNativePerformanceAvailable` runtime check
- Loading branch information
1 parent
d890a1c
commit ab5a293
Showing
5 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...-native/android/src/main/java/com/bugsnag/android/performance/ReactNativeSpanContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.bugsnag.reactnative.performance; | ||
|
||
import androidx.annotation.NonNull; | ||
import com.bugsnag.android.performance.SpanContext; | ||
import java.util.UUID; | ||
import java.util.concurrent.Callable; | ||
|
||
class ReactNativeSpanContext implements SpanContext { | ||
private static final int HEX_RADIX = 16; | ||
private static final int TRACE_ID_MIDPOINT = 16; | ||
|
||
private final long nativeSpanId; | ||
private final UUID nativeTraceId; | ||
|
||
ReactNativeSpanContext(String spanId, String traceId) { | ||
nativeSpanId = Long.parseUnsignedLong(spanId, HEX_RADIX); | ||
nativeTraceId = new UUID( | ||
Long.parseUnsignedLong(traceId.substring(0, TRACE_ID_MIDPOINT), HEX_RADIX), | ||
Long.parseUnsignedLong(traceId.substring(TRACE_ID_MIDPOINT), HEX_RADIX) | ||
); | ||
} | ||
|
||
@Override | ||
public long getSpanId() { | ||
return nativeSpanId; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public UUID getTraceId() { | ||
return nativeTraceId; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Runnable wrap(@NonNull Runnable runnable) { | ||
return SpanContext.DefaultImpls.wrap(this, runnable); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public <T> Callable<T> wrap(@NonNull Callable<T> callable) { | ||
return SpanContext.DefaultImpls.wrap(this, callable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters