ScopeAgent-Reference is the reference app to showcase Scope integration and functionality in an iOS project.
It is configured manually as explained in https://scope.undefinedlabs.com/docs/ios-installation using:
- Cocoapods: Podfile explains pods and usage
- **GitHub Actions **: See Environment Variables in test Scheme
- Upload symbols: Check Upload Symbols in ScopeAgent-ReferenceTests Build Phases for crash symbolication
- CodePath: Check Post-actions in ScopeAgent-Reference Scheme Test action.
ScopeAgent-Reference is written in Swift but ScopeAgent.framework can also be used from any project written in Objective-C.
The project uses standard logging mechanisms like NSLog()
, os_log()
or print()
(which will show up in Scope), but it also implements custom logging integration in the app. See Logger.swift
for details.
It shows automatic logging of networking requests in Networking.swift
without any changes, and also how to add instrumentation to outgoing requests for integration tests to show tracing information from other services in Geolocation.swift
There are comments in source files to explain what changes are for Scope to work. These changes are marked with /* SCOPE */
comments.
In ScopeAgent_ReferenceTests.swift
there are a variety of tests that show the different outputs that Scope produces with each one.
Unit tests or simple networking tests need no custom code, they just show in Scope with their results automatically:
testPass
: Simple example of a passing testtestFail
: Example of a failing testtestStandardLogging
: Shows howNSLog
,os_log
orprint
messages appear in Scope resultstestNetworkingAlamofire
: Alamofire requesttestNetworkingURLSession
: Simple shared URLSession requesttestNSException
: A test that throws an exception, so it failstestCrash
: A test that produces a crash
Custom logging frameworks are also supported:
testCustomLoggingIntegration
: Example of custom logs. The integration implementation is inLogger.swift
Integration test need some custom code so we can trace all the execution that happens since we start the request until we get a response, including all the services that the request access for the test:
testServicesIntegrationWithAlamofire
: Shows how to adapt an integration test using Alamofire with the helper classAlamofireTracing
written for this purposetestServicesIntegrationWithURLSession
: Shows how to adapt an integration test using URLSession and the helper classSAURLSessionObserver
in the ScopeAgent framework.testErrorInService
: Shows an integration test that produces an error in an external service.
The agent also supports custom tracing using the OpenTracing API:
testCustomOpentracing
: Shows a test that creates spans and events using the OpenTracing API