Skip to content

Commit f2b2e4a

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #363 from lunij/marc/ios-support
Fix iOS support and add iOS specific testing
2 parents 6fc9920 + a6a581b commit f2b2e4a

File tree

8 files changed

+69
-11
lines changed

8 files changed

+69
-11
lines changed

.github/workflows/BuildAndTest.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ jobs:
1717
chmod +x codecov
1818
xcrun llvm-cov export -ignore-filename-regex="pb\.swift|grpc\.swift" -format="lcov" .build/debug/opentelemetry-swiftPackageTests.xctest/Contents/MacOS/opentelemetry-swiftPackageTests -instr-profile .build/debug/codecov/default.profdata > .build/debug/codecov/coverage_report.lcov
1919
./codecov -f .build/debug/codecov/coverage_report.lcov
20+
- name: Install Homebrew kegs
21+
run: make setup_brew
22+
- name: Build for iOS
23+
run: make build_for_testing_ios
24+
- name: Test for iOS
25+
run: make test_without_building_ios

Examples/Datadog Sample/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import DatadogExporter
77
import Foundation
88
import OpenTelemetryApi
99
import OpenTelemetrySdk
10-
#if targetEnvironment(macCatalyst)
10+
#if !os(macOS)
1111
import UIKit
1212
#endif
1313

@@ -26,10 +26,10 @@ var instrumentationScopeInfo = InstrumentationScopeInfo(name: instrumentationSco
2626
var tracer: TracerSdk
2727
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationScopeName, instrumentationVersion: instrumentationScopeVersion) as! TracerSdk
2828

29-
#if targetEnvironment(macCatalyst)
30-
let hostName = UIDevice.current.name
31-
#else
29+
#if os(macOS)
3230
let hostName = Host.current().localizedName
31+
#else
32+
let hostName = UIDevice.current.name
3333
#endif
3434

3535
let exporterConfiguration = ExporterConfiguration(

Examples/Simple Exporter/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let spanExporter = MultiSpanExporter(spanExporters: [jaegerExporter, stdoutExpor
5454
let spanProcessor = SimpleSpanProcessor(spanExporter: spanExporter)
5555
OpenTelemetrySDK.instance.tracerProvider.addSpanProcessor(spanProcessor)
5656

57-
if #available(macOS 10.14, *) {
57+
if #available(iOS 12.0, macOS 10.14, *) {
5858
OpenTelemetrySDK.instance.tracerProvider.addSpanProcessor(SignPostIntegration())
5959
}
6060

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
PROJECT_NAME="opentelemetry-swift-Package"
2+
3+
XCODEBUILD_OPTIONS_IOS=\
4+
-configuration Debug \
5+
-destination platform='iOS Simulator,name=iPhone 14,OS=latest' \
6+
-scheme $(PROJECT_NAME) \
7+
-workspace .
8+
9+
.PHONY: setup_brew
10+
setup_brew:
11+
brew update && brew install xcbeautify
12+
13+
.PHONY: build_ios
14+
build_ios:
15+
set -o pipefail && xcodebuild $(XCODEBUILD_OPTIONS_IOS) build | xcbeautify
16+
17+
.PHONY: build_for_testing_ios
18+
build_for_testing_ios:
19+
set -o pipefail && xcodebuild $(XCODEBUILD_OPTIONS_IOS) build-for-testing | xcbeautify
20+
21+
.PHONY: test_ios
22+
test_ios:
23+
set -o pipefail && xcodebuild $(XCODEBUILD_OPTIONS_IOS) test | xcbeautify
24+
25+
.PHONY: test_without_building_ios
26+
test_without_building_ios:
27+
set -o pipefail && xcodebuild $(XCODEBUILD_OPTIONS_IOS) test-without-building | xcbeautify

Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ let package = Package(
3636
.package(name: "swift-nio", url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
3737
.package(name: "grpc-swift", url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
3838
.package(name: "swift-metrics", url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
39+
.package(name: "Reachability.swift", url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0")
3940
],
4041
targets: [
4142
.target(name: "OpenTelemetryApi",
@@ -98,7 +99,7 @@ let package = Package(
9899
dependencies: ["OpenTelemetrySdk"],
99100
path: "Sources/Exporters/Persistence"),
100101
.testTarget(name: "NetworkStatusTests",
101-
dependencies: ["NetworkStatus"],
102+
dependencies: ["NetworkStatus", .product(name: "Reachability", package: "Reachability.swift")],
102103
path: "Tests/InstrumentationTests/NetworkStatusTests"),
103104
.testTarget(name: "OpenTelemetryApiTests",
104105
dependencies: ["OpenTelemetryApi"],

Tests/ExportersTests/DatadogExporter/Helpers/DeviceMock.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,29 @@ class UIDeviceMock: UIDevice {
1717
init(
1818
model: String = .mockAny(),
1919
systemName: String = .mockAny(),
20-
systemVersion: String = .mockAny()
20+
systemVersion: String = .mockAny(),
21+
isBatteryMonitoringEnabled: Bool = .mockAny(),
22+
batteryState: UIDevice.BatteryState = .unknown,
23+
batteryLevel: Float = 0
2124
) {
2225
self._model = model
2326
self._systemName = systemName
2427
self._systemVersion = systemVersion
28+
self._isBatteryMonitoringEnabled = isBatteryMonitoringEnabled
29+
self._batteryState = batteryState
30+
self._batteryLevel = batteryLevel
2531
}
2632

2733
override var model: String { _model }
2834
override var systemName: String { _systemName }
2935
override var systemVersion: String { "mock system version" }
36+
override var batteryState: UIDevice.BatteryState { _batteryState }
37+
override var batteryLevel: Float { _batteryLevel }
38+
39+
override var isBatteryMonitoringEnabled: Bool {
40+
get { _isBatteryMonitoringEnabled }
41+
set { _isBatteryMonitoringEnabled = newValue }
42+
}
3043
}
3144

3245
#endif

Tests/ExportersTests/DatadogExporter/Utils/DeviceTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import XCTest
77

8-
#if !os(macOS)
8+
#if os(iOS)
99
import UIKit
1010
#else
1111
import Foundation
@@ -19,9 +19,9 @@ class DeviceTests: XCTestCase {
1919
XCTAssertNotNil(Device.current)
2020
}
2121

22-
#if !os(macOS) && !targetEnvironment(macCatalyst)
22+
#if os(iOS) && !targetEnvironment(macCatalyst)
2323
func testWhenRunningOnMobile_itUsesUIDeviceInfo() {
24-
let uiDevice = DeviceMock(
24+
let uiDevice = UIDeviceMock(
2525
model: "model mock",
2626
systemName: "system name mock",
2727
systemVersion: "system version mock"
@@ -32,5 +32,7 @@ class DeviceTests: XCTestCase {
3232
XCTAssertEqual(device.osName, uiDevice.systemName)
3333
XCTAssertEqual(device.osVersion, uiDevice.systemVersion)
3434
}
35-
#endif // os(iOS) && !targetEnvironment(macCatalyst)
35+
36+
class ProcessInfoMock: ProcessInfo {}
37+
#endif
3638
}

0 commit comments

Comments
 (0)