Skip to content

Commit ddc565a

Browse files
committed
Fix lint error
1 parent bebe34e commit ddc565a

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

SplunkRumWorkspace/SmokeTest/SmokeTestUITests/SmokeTestUITests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var lastTimestamp: CFTimeInterval = CACurrentMediaTime()
3535
class SmokeTestUITests: XCTestCase {
3636

3737
override func setUpWithError() throws {
38+
try super.setUpWithError()
39+
3840
// Put setup code here. This method is called before the invocation of each test method in the class.
3941

4042
// In UI tests it is usually best to stop immediately when a failure occurs.

SplunkRumWorkspace/SplunkRum/SplunkRum/SessionBasedSampler.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,57 @@ import Foundation
1818

1919
struct BoolDecision: Decision {
2020
var isSampled: Bool
21-
var attributes: [String : AttributeValue] = [:]
21+
var attributes: [String: AttributeValue] = [:]
2222
}
2323

2424
class SessionBasedSampler: Sampler {
25-
25+
2626
var probability: Double = 1.0
2727
var currentlySampled: Bool?
2828
var lock: Lock = Lock()
29-
29+
3030
init(ratio: Double) {
3131
probability = ratio
3232
observeSessionIdChange()
3333
}
34-
35-
func shouldSample(parentContext: SpanContext?, traceId: TraceId, name: String, kind: SpanKind, attributes: [String : AttributeValue], parentLinks: [SpanData.Link]) -> Decision {
34+
35+
// swiftlint:disable function_parameter_count
36+
func shouldSample(parentContext: SpanContext?, traceId: TraceId, name: String, kind: SpanKind, attributes: [String: AttributeValue], parentLinks: [SpanData.Link]) -> Decision {
3637
return lock.withLock({
3738
return self.getDecision()
3839
})
39-
40+
4041
}
41-
42+
// swiftlint:enable function_parameter_count
43+
4244
var description: String {
4345
return "SessionBasedSampler, Ratio: \(probability)"
4446
}
45-
47+
4648
private func observeSessionIdChange() {
4749
addSessionIdCallback { [weak self] in
4850
self?.lock.withLockVoid {
4951
self?.currentlySampled = self?.shouldSampleNewSession()
5052
}
5153
}
5254
}
53-
55+
5456
private func getDecision() -> Decision {
55-
57+
5658
if let currentlySampled = self.currentlySampled {
5759
return BoolDecision(isSampled: currentlySampled)
5860
}
59-
61+
6062
let isSampled = self.shouldSampleNewSession()
6163
self.currentlySampled = isSampled
6264
return BoolDecision(isSampled: isSampled)
6365
}
64-
66+
6567
/**Check if session will be sampled or not.**/
6668
private func shouldSampleNewSession() -> Bool {
67-
69+
6870
var result = false
69-
71+
7072
switch probability {
7173
case 0.0:
7274
result = false
@@ -75,8 +77,8 @@ class SessionBasedSampler: Sampler {
7577
default:
7678
result = Double.random(in: 0.0...1.0) <= probability
7779
}
78-
80+
7981
return result
8082
}
81-
83+
8284
}

SplunkRumWorkspace/SplunkRum/SplunkRum/SplunkRum.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ var splunkRumInitializeCalledTime = Date()
243243
.add(spanProcessor: GlobalAttributesProcessor())
244244
.with(sampler: SessionBasedSampler(ratio: options?.sessionSamplingRatio ?? 1.0))
245245
.build()
246-
246+
247247
OpenTelemetry.registerTracerProvider(tracerProvider: tracerProvider)
248248

249249
if options != nil {
@@ -341,7 +341,7 @@ var splunkRumInitializeCalledTime = Date()
341341
.add(spanProcessor: GlobalAttributesProcessor(appName: appName))
342342
.with(sampler: SessionBasedSampler(ratio: options.sessionSamplingRatio))
343343
.build()
344-
344+
345345
OpenTelemetry.registerTracerProvider(tracerProvider: tracerProvider)
346346

347347
configuredOptions = SplunkRumOptions(opts: options)

SplunkRumWorkspace/SplunkRum/SplunkRumTests/SessionSamplingTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class SessionSamplingTests: XCTestCase {
2929
.globalAttributes(globalAttributes: [:])
3030
.sessionSamplingRatio(samplingRatio: 0.2)
3131
.build()
32-
32+
3333
let provider = OpenTelemetry.instance.tracerProvider as! TracerProviderSdk
3434
let sampler = provider.getActiveSampler() as! SessionBasedSampler
35-
35+
3636
XCTAssertTrue(sampler.probability >= 0.0 && sampler.probability <= 1.0)
3737
XCTAssertEqual(sampler.probability, 0.2)
3838
resetRUM()
@@ -48,11 +48,11 @@ class SessionSamplingTests: XCTestCase {
4848
.globalAttributes(globalAttributes: [:])
4949
.sessionSamplingRatio(samplingRatio: 1.0)
5050
.build()
51-
51+
5252
let provider = OpenTelemetry.instance.tracerProvider as! TracerProviderSdk
5353
let sampler = provider.getActiveSampler() as! SessionBasedSampler
5454
let shouldSample = sampler.shouldSample(parentContext: nil, traceId: .random(), name: "Span Example", kind: .client, attributes: [:], parentLinks: [])
55-
55+
5656
XCTAssertTrue(shouldSample.isSampled)
5757
resetRUM()
5858
}
@@ -67,11 +67,11 @@ class SessionSamplingTests: XCTestCase {
6767
.globalAttributes(globalAttributes: [:])
6868
.sessionSamplingRatio(samplingRatio: 0.0)
6969
.build()
70-
70+
7171
let provider = OpenTelemetry.instance.tracerProvider as! TracerProviderSdk
7272
let sampler = provider.getActiveSampler() as! SessionBasedSampler
7373
let shouldSample = sampler.shouldSample(parentContext: nil, traceId: .random(), name: "Span Example", kind: .client, attributes: [:], parentLinks: [])
74-
74+
7575
XCTAssertFalse(shouldSample.isSampled)
7676
resetRUM()
7777
}
@@ -86,16 +86,16 @@ class SessionSamplingTests: XCTestCase {
8686
.globalAttributes(globalAttributes: [:])
8787
.sessionSamplingRatio(samplingRatio: 0.5)
8888
.build()
89-
89+
9090
let provider = OpenTelemetry.instance.tracerProvider as! TracerProviderSdk
9191
let sampler = provider.getActiveSampler() as! SessionBasedSampler
92-
92+
9393
func testSampling() -> Bool {
9494
_ = getRumSessionId(forceNewSessionId: true)
9595
let shouldSample = sampler.shouldSample(parentContext: nil, traceId: .random(), name: "Span Example", kind: .client, attributes: [:], parentLinks: [])
9696
return shouldSample.isSampled
9797
}
98-
98+
9999
var countSpans = 0
100100
for _ in 1...100 where testSampling() {
101101
countSpans += 1

0 commit comments

Comments
 (0)