Skip to content

Commit

Permalink
Added an E2E test for pre-loaded views instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Jan 25, 2024
1 parent 9ae3e02 commit 00bd0e1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
37 changes: 37 additions & 0 deletions features/default/automatic_spans.feature
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,43 @@ Feature: Automatic instrumentation spans
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.name" equals "bugsnag.performance.cocoa"
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.version" matches the regex "[0-9]\.[0-9]\.[0-9]"

Scenario: AutoInstrumentPreLoadedViewLoadScenario
Given I run "AutoInstrumentPreLoadedViewLoadScenario"
And I wait for 18 spans
Then the trace "Content-Type" header equals "application/json"
* the trace "Bugsnag-Sent-At" header matches the regex "^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\dZ$"
* a span field "name" equals "[ViewLoad/UIKit]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/loadView]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/viewDidLoad]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/viewWillAppear]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/View appearing]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/viewDidAppear]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/viewWillLayoutSubviews]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/Subview layout]/Fixture.ViewController"
* a span field "name" equals "[ViewLoadPhase/viewDidLayoutSubviews]/Fixture.ViewController"
* a span field "name" equals "[ViewLoad/UIKit]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController (pre-loaded)"
* a span field "name" equals "[ViewLoadPhase/loadView]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/viewDidLoad]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/viewWillAppear]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/View appearing]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/viewDidAppear]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/viewWillLayoutSubviews]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/Subview layout]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* a span field "name" equals "[ViewLoadPhase/viewDidLayoutSubviews]/Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController"
* every span field "spanId" matches the regex "^[A-Fa-f0-9]{16}$"
* every span field "traceId" matches the regex "^[A-Fa-f0-9]{32}$"
* every span field "kind" equals 1
* every span field "startTimeUnixNano" matches the regex "^[0-9]+$"
* every span field "endTimeUnixNano" matches the regex "^[0-9]+$"
* a span string attribute "bugsnag.span.category" equals "view_load"
* a span string attribute "bugsnag.view.name" equals "Fixture.ViewController"
* a span string attribute "bugsnag.view.name" equals "Fixture.AutoInstrumentPreLoadedViewLoadScenario_ViewController (pre-loaded)"
* a span bool attribute "bugsnag.span.first_class" is true
* a span string attribute "bugsnag.view.type" equals "UIKit"
* the trace payload field "resourceSpans.0.resource" string attribute "service.name" equals "com.bugsnag.fixtures.PerformanceFixture"
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.name" equals "bugsnag.performance.cocoa"
* the trace payload field "resourceSpans.0.resource" string attribute "telemetry.sdk.version" matches the regex "[0-9]\.[0-9]\.[0-9]"

Scenario: AutoInstrumentSwiftUIScenario no change
Given I run "AutoInstrumentSwiftUIScenario"
And I wait for 3 spans
Expand Down
4 changes: 4 additions & 0 deletions features/fixtures/ios/Fixture.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
0983A17B2B14BB2000DDF4FF /* BugsnagPerformanceSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 0983A17A2B14BB2000DDF4FF /* BugsnagPerformanceSwiftUI */; };
098808E02B10A6E400DC1677 /* ManualViewLoadPhaseScenario.swift in Sources */ = {isa = PBXBuildFile; fileRef = 098808DF2B10A6E400DC1677 /* ManualViewLoadPhaseScenario.swift */; };
09DA59A52A6E866B00A06EEE /* ManualNetworkCallbackScenario.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DA59A42A6E866B00A06EEE /* ManualNetworkCallbackScenario.swift */; };
96284DCE2B626B6F00025070 /* AutoInstrumentPreLoadedViewLoadScenario.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96284DCD2B626B6F00025070 /* AutoInstrumentPreLoadedViewLoadScenario.swift */; };
9657A8992A3CF75B001CEF5D /* AutoInstrumentTabViewLoadScenario.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9657A8982A3CF75B001CEF5D /* AutoInstrumentTabViewLoadScenario.swift */; };
9657A89B2A3D06EB001CEF5D /* AutoInstrumentNavigationViewLoadScenario.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9657A89A2A3D06EB001CEF5D /* AutoInstrumentNavigationViewLoadScenario.swift */; };
967F6F1A29C4AD300054EED8 /* ReleaseStageNotEnabledScenario.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967F6F1929C4AD300054EED8 /* ReleaseStageNotEnabledScenario.swift */; };
Expand Down Expand Up @@ -87,6 +88,7 @@
0983A1782B14B20C00DDF4FF /* AutoInstrumentSwiftUIScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoInstrumentSwiftUIScenario.swift; sourceTree = "<group>"; };
098808DF2B10A6E400DC1677 /* ManualViewLoadPhaseScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManualViewLoadPhaseScenario.swift; sourceTree = "<group>"; };
09DA59A42A6E866B00A06EEE /* ManualNetworkCallbackScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManualNetworkCallbackScenario.swift; sourceTree = "<group>"; };
96284DCD2B626B6F00025070 /* AutoInstrumentPreLoadedViewLoadScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoInstrumentPreLoadedViewLoadScenario.swift; sourceTree = "<group>"; };
9657A8982A3CF75B001CEF5D /* AutoInstrumentTabViewLoadScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoInstrumentTabViewLoadScenario.swift; sourceTree = "<group>"; };
9657A89A2A3D06EB001CEF5D /* AutoInstrumentNavigationViewLoadScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoInstrumentNavigationViewLoadScenario.swift; sourceTree = "<group>"; };
967F6F1929C4AD300054EED8 /* ReleaseStageNotEnabledScenario.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseStageNotEnabledScenario.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -221,6 +223,7 @@
CBF62108291A4F47004BEE0B /* RetryScenario.swift */,
01A58C1429096AF4006E4DF7 /* SamplingProbabilityZeroScenario.swift */,
01FE4DC428E1AF9600D1F239 /* Scenario.swift */,
96284DCD2B626B6F00025070 /* AutoInstrumentPreLoadedViewLoadScenario.swift */,
);
path = Scenarios;
sourceTree = "<group>";
Expand Down Expand Up @@ -324,6 +327,7 @@
01FE4DA928E1AEBD00D1F239 /* AppDelegate.swift in Sources */,
096EE5EF2B3C2B3E006059CE /* AutoInstrumentSwiftUIDeferredScenario.swift in Sources */,
CBAAE2592912601D006D4AA0 /* BatchingScenario.swift in Sources */,
96284DCE2B626B6F00025070 /* AutoInstrumentPreLoadedViewLoadScenario.swift in Sources */,
09637A3C2B0607F300F4F776 /* Logging.swift in Sources */,
9657A89B2A3D06EB001CEF5D /* AutoInstrumentNavigationViewLoadScenario.swift in Sources */,
01D3A7E028F0290D0063D79E /* AutoInstrumentAppStartsScenario.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// AutoInstrumentPreLoadedViewLoadScenario.swift
// Fixture
//
// Created by Robert Bartoszewski on 25/01/2024.
//

import Foundation

import UIKit

@objcMembers
class AutoInstrumentPreLoadedViewLoadScenario: Scenario {

override func configure() {
super.configure()
config.autoInstrumentViewControllers = true
}

override func run() {
let viewController = AutoInstrumentPreLoadedViewLoadScenario_ViewController()
_ = viewController.view
Thread.sleep(forTimeInterval: 1.5)
UIApplication.shared.windows[0].rootViewController!.present(
viewController, animated: true)
}
}

class AutoInstrumentPreLoadedViewLoadScenario_ViewController: UIViewController {

override func loadView() {
let label = UILabel()
label.backgroundColor = .white
label.textAlignment = .center
label.text = String(describing: type(of: self))
view = label
}
}

0 comments on commit 00bd0e1

Please sign in to comment.