+
Skip to content

Conversation

yousif-bugsnag
Copy link
Contributor

Goal

Added a new BugsnagPerformanceNamedSpans module which exposes a BugsnagPerformanceNamedSpansPlugin hat can be used to track spans by name. This allows for easier access to open spans without needing to keep references.

Design

The new plugin allows spans to be queried by name (using a BugsnagPerformanceNamedSpanQuery). If the span exists, a BugsnagPerformanceSpan instance is returned from BugsnagPerformance.getSpanControlsWithQuery.

Only the latest span for a given span name is tracked, and spans older than 10 minutes are removed from tracked memory to allow them to be deallocated.

Changeset

  • Added the new module to the project
  • Added BugsnagPerformanceNamedSpansPlugin implementation

Testing

Added new unit tests and a new E2E test scenario

Copy link

github-actions bot commented Aug 4, 2025

BugsnagPerformance.framework binary size increased by 200 bytes from 660,696 to 660,896

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +17%     +72   +17%     +72    Export Info
  +0.0%     +64  +0.0%     +64    String Table
  +0.0%     +64  +0.0%     +64    Symbol Table
  +0.5%     +16  +0.5%     +16    __TEXT,__const
  -0.0%     -16  -0.0%     -16    [__TEXT]
  [ = ]       0  -1.8%    -200    [__LINKEDIT]
  +0.0%    +200  [ = ]       0    TOTAL

Generated by 🚫 Danger


#pragma mark BugsnagPerformancePlugin

#pragma clang diagnostic ignored "-Wdirect-ivar-access"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refer to spanTimeoutTimers property instead of accessing ivar directly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think we can just ditch the timers all together by utilizing dispatch_after.
We can also introduce another callback that will be called whenever a span ceases to exist. As of now, we only update SpanStackingHandler when a span is deallocated without getting closed in some way. Perhaps we can expand this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a new callback will require more work but it will save us the overhead of dispatching an operation every time a span is created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to raise a separate task to implement these optimizations at a later date


#pragma clang diagnostic ignored "-Wdirect-ivar-access"
- (void)installWithContext:(BugsnagPerformancePluginContext *)context {
self.spansByName = [NSMutableDictionary new];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This results in the spansByName being cleared every time the plugin gets installed. It shouldn't matter as the plugin will presumably be installed once. It's an unnecessary side effect though
  2. NSMutableDictionary proved to be not efficient enough for our purposes in the past. As this will be heavily used, I think we should opt for an std::map

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Given that the keys to this NSMutableDictionary are strings, changing it to a C++ map will either carry an encode/decode overhead (to go from NSString (UTF-16) <-> std::string (UTF-8) or will require that we implement a custom std::hash and std::equal_to so that we can directly store the NSString*s in the C++ map.

I think we should keep the existing NSMutableDictionary implementation until we have a chance to benchmark the performance differences between the implementations.


#pragma mark BugsnagPerformancePlugin

#pragma clang diagnostic ignored "-Wdirect-ivar-access"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a new callback will require more work but it will save us the overhead of dispatching an operation every time a span is created

yousif-bugsnag and others added 3 commits August 7, 2025 14:14
Co-authored-by: Jason <lemnik@users.noreply.github.com>
Co-authored-by: Robert Bartoszewski <126675445+robert-smartbear@users.noreply.github.com>
@yousif-bugsnag yousif-bugsnag force-pushed the PLAT-14245/named-span-access branch from 078a3c3 to 14c7618 Compare August 7, 2025 13:15
@yousif-bugsnag yousif-bugsnag requested a review from lemnik August 13, 2025 14:01
@yousif-bugsnag yousif-bugsnag merged commit 7b389f4 into next Aug 14, 2025
26 checks passed
@yousif-bugsnag yousif-bugsnag deleted the PLAT-14245/named-span-access branch August 14, 2025 08:54
@DariaKunoichi DariaKunoichi mentioned this pull request Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载