Skip to content

Commit

Permalink
feat(react-native): support marking native span end times independently
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Dec 16, 2024
1 parent 4bbe5d8 commit 00efa1a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,28 @@ public WritableMap startNativeSpan(String name, ReadableMap options) {
return nativeSpanToJsSpan(nativeSpan);
}

public void endNativeSpan(String spanId, double endTime, ReadableMap jsAttributes, Promise promise) {
SpanImpl nativeSpan = openSpans.remove(spanId);
public void markNativeSpanEndTime(String spanId, double endTime) {
SpanImpl nativeSpan = openSpans.get(spanId);
if (nativeSpan != null) {
ReactNativeSpanAttributes.setAttributesFromReadableMap(nativeSpan.getAttributes(), jsAttributes);
long nativeEndTime = BugsnagClock.INSTANCE.unixNanoTimeToElapsedRealtime((long)endTime);
nativeSpan.end(nativeEndTime);
nativeSpan.markEndTime$internal(nativeEndTime);
}
}

public void endNativeSpan(String spanId, double endTime, ReadableMap jsAttributes, Promise promise) {
SpanImpl nativeSpan = openSpans.remove(spanId);
if (nativeSpan == null) {
promise.resolve(null);
return;
}

ReactNativeSpanAttributes.setAttributesFromReadableMap(nativeSpan.getAttributes(), jsAttributes);
long nativeEndTime = BugsnagClock.INSTANCE.unixNanoTimeToElapsedRealtime((long)endTime);
if (nativeEndTime > nativeSpan.getEndTime$internal()) {
nativeSpan.markEndTime$internal(nativeEndTime);
}

nativeSpan.sendForProcessing$internal();
promise.resolve(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ public WritableMap getNativeConfiguration() {
return impl.getNativeConfiguration();
}

@Override public WritableMap startNativeSpan(String name, ReadableMap options) {
@Override
public WritableMap startNativeSpan(String name, ReadableMap options) {
return impl.startNativeSpan(name, options);
}

@Override
public void endNativeSpan(String spanId, double endTime, ReadableMap attributes, Promise promise) {
impl.endNativeSpan(spanId, endTime, attributes, promise);
}

@Override
public void markNativeSpanEndTime(String spanId, double endTime) {
impl.markNativeSpanEndTime(spanId, endTime);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public WritableMap startNativeSpan(String name, ReadableMap options) {

@ReactMethod
public void endNativeSpan(String spanId, double endTime, ReadableMap attributes, Promise promise) {
impl.endNativeSpan(spanId, endTime, attributes, promise);
impl.endNativeSpan(spanId, endTime, attributes, promise);
}

@ReactMethod(isBlockingSynchronousMethod = true)
public void markNativeSpanEndTime(String spanId, double endTime) {
impl.markNativeSpanEndTime(spanId, endTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface Spec extends TurboModule {
getNativeConfiguration: () => NativeConfiguration | null
startNativeSpan: (name: string, options: UnsafeObject) => NativeSpan
endNativeSpan: (spanId: string, endTime: number, attributes: UnsafeObject) => Promise<void>
markNativeSpanEndTime: (spanId: string, endTime: number) => void
}

export default TurboModuleRegistry.get<Spec>(
Expand Down

0 comments on commit 00efa1a

Please sign in to comment.