bugsnag / bugsnag-cocoa-performance

Monitor the start-up, screen loading and network requests of your iOS app and see the results in your BugSnag dashboard.
https://docs.bugsnag.com/performance/integration-guides/ios
MIT License
11 stars 8 forks source link

[PLAT-12035] Allow injection of traceparent HTTP headers #259

Closed kstenerud closed 2 months ago

kstenerud commented 2 months ago

Goal

Auto-inject OTLP traceparent headers into network requests sent via URLSession

Design

The header injection code is run from inside our existing swizzle of NSURLSessionTask::resume. The previous injected code runs the same, but we need to inject headers even when the user has specified not to capture a span.

Header injection control is handled by a set of regular expressions propagateTraceParentToUrlsMatching in BugsnagPerformanceConfiguration. Only URLs matching one of these regular expressions will have the header injected (which means that if left unconfigured, no network requests will have the header injected).

It was originally planned to also support this from manually instrumented network requests, but a number of issues have cropped up, so only the groundwork for that has been laid so far (NetworkHeaderInjector handles all of the injection, but is currently only used in NetworkInstrumentation).

Due to the DI style architecture, adding a new responsibility tends to cascade back to the top-level injection point (BugsnagPerformanceImpl), so there's a fair bit of noise in this PR as a result.

"Early" span handling has been moved outside of Tracer and into NetworkInstrumentation (there was already some code and functionality duplication here).

Deep span internals access from the top-level objc object has been added (for internal use).

Testing

New e2e tests

github-actions[bot] commented 2 months ago

BugsnagPerformance.framework binary size increased by 8,200 bytes from 445,632 to 453,832

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +5.5% +5.18Ki  +5.5% +5.18Ki    __TEXT,__text
  +4.5% +4.65Ki  +4.5% +4.65Ki    String Table
  +4.0% +3.28Ki  +4.0% +3.28Ki    Symbol Table
  +4.7%    +416  +4.7%    +416    __TEXT,__gcc_except_tab
  +6.3%    +296  +6.3%    +296    __DATA_CONST,__const
  +2.4%    +257  +2.4%    +257    __TEXT,__objc_methname
  +8.4%    +242  +8.4%    +242    __TEXT,__const
  +5.2%    +224  +5.2%    +224    __TEXT,__unwind_info
  +1.4%    +160  +1.4%    +160    __DATA,__objc_const
  +0.9%     +64  +0.9%     +64    __DATA_CONST,__cfstring
  +0.7%     +64  +0.7%     +64    __TEXT,__objc_stubs
  +0.8%     +42  +0.8%     +42    __TEXT,__cstring
  +4.1%     +40  +4.1%     +40    Function Start Addresses
  +0.8%     +32  +0.8%     +32    [4 Others]
  +0.7%     +24  +0.7%     +24    Binding Info
  +2.0%     +16  +2.0%     +16    Rebase Info
  -1.7%     -43  -1.7%     -43    __TEXT,__objc_methtype
  -1.1%    -180  -1.2%    -180    [__DATA]
  -8.9%    -368  -8.9%    -368    [__DATA_CONST]
 -13.4% -6.35Ki -13.3% -6.35Ki    [__TEXT]
  [DEL]      -4 -62.5% -8.01Ki    [__LINKEDIT]
  +1.8% +8.01Ki  [ = ]       0    TOTAL

Generated by :no_entry_sign: Danger