Skip to content

Commit

Permalink
Dvernon: MOB-3260/MOB-3261 - New Options (#154)
Browse files Browse the repository at this point in the history
* MOB-3260 Add an option for slowRenderingDetectionEnabled

* MOB-3260 adding slowRenderingDetectionEnabled to builder

* MOB-3261 create new option for spanScheduleDelay

* MOB-3261 renaming bspScheduleDelay and updating description
  • Loading branch information
dvernon-splunk authored Aug 2, 2023
1 parent 83db163 commit 9522240
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
2 changes: 1 addition & 1 deletion SplunkOtel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

Pod::Spec.new do |s|
s.name = 'SplunkOtel'
s.version = '0.11.0'
s.version = '0.11.1'
s.summary = 'Splunk OpenTelemetry pod for iOS'
s.description = <<-DESC
The Splunk RUM agent for iOS provides a Swift package that captures:
Expand Down
55 changes: 41 additions & 14 deletions SplunkRumWorkspace/SplunkRum/SplunkRum/SplunkRum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import WebKit

// Make sure the version numbers on the podspec and SplunkRum.swift match
let SplunkRumVersionString = "0.11.0"
let SplunkRumVersionString = "0.11.1"

/**
Default maximum size of the disk cache in bytes.
Expand Down Expand Up @@ -48,9 +48,11 @@ public let DEFAULT_DISK_CACHE_MAX_SIZE_BYTES: Int64 = 25 * 1024 * 1024
networkInstrumentation: Bool = true,
enableDiskCache: Bool = false,
spanDiskCacheMaxSize: Int64 = DEFAULT_DISK_CACHE_MAX_SIZE_BYTES,
slowRenderingDetectionEnabled: Bool = true,
slowFrameDetectionThresholdMs: Double = 16.7,
frozenFrameDetectionThresholdMs: Double = 700,
sessionSamplingRatio: Double = 1.0
sessionSamplingRatio: Double = 1.0,
spanSchedulingDelay: TimeInterval = 5.0
) {
// rejectionFilter not specified to make it possible to call from objc
self.allowInsecureBeacon = allowInsecureBeacon
Expand All @@ -62,6 +64,7 @@ public let DEFAULT_DISK_CACHE_MAX_SIZE_BYTES: Int64 = 25 * 1024 * 1024
self.networkInstrumentation = networkInstrumentation
self.enableDiskCache = enableDiskCache
self.spanDiskCacheMaxSize = spanDiskCacheMaxSize
self.slowRenderingDetectionEnabled = slowRenderingDetectionEnabled
self.slowFrameDetectionThresholdMs = slowFrameDetectionThresholdMs
self.frozenFrameDetectionThresholdMs = frozenFrameDetectionThresholdMs
self.sessionSamplingRatio = sessionSamplingRatio
Expand All @@ -79,12 +82,14 @@ public let DEFAULT_DISK_CACHE_MAX_SIZE_BYTES: Int64 = 25 * 1024 * 1024
self.spanFilter = opts.spanFilter
self.showVCInstrumentation = opts.showVCInstrumentation
self.screenNameSpans = opts.screenNameSpans
self.slowRenderingDetectionEnabled = opts.slowRenderingDetectionEnabled
self.slowFrameDetectionThresholdMs = opts.slowFrameDetectionThresholdMs
self.frozenFrameDetectionThresholdMs = opts.frozenFrameDetectionThresholdMs
self.networkInstrumentation = opts.networkInstrumentation
self.enableDiskCache = opts.enableDiskCache
self.spanDiskCacheMaxSize = opts.spanDiskCacheMaxSize
self.sessionSamplingRatio = opts.sessionSamplingRatio
self.bspScheduleDelay = opts.bspScheduleDelay
}

/**
Expand Down Expand Up @@ -130,6 +135,11 @@ public let DEFAULT_DISK_CACHE_MAX_SIZE_BYTES: Int64 = 25 * 1024 * 1024
*/
@objc public var networkInstrumentation: Bool = true

/**
Enable slow rendering detection. Slow rendering detection generates spans whenever it detects a slow or frozen frame render.
*/
@objc public var slowRenderingDetectionEnabled: Bool = true

/**
Threshold, in milliseconds, from which to count a rendered frame as slow.
*/
Expand All @@ -156,6 +166,11 @@ public let DEFAULT_DISK_CACHE_MAX_SIZE_BYTES: Int64 = 25 * 1024 * 1024
*/
@objc public var sessionSamplingRatio: Double = 1.0

/**
Set the maximum interval between 2 consecutive span exports
*/
@objc public var bspScheduleDelay: TimeInterval = 5.0

func toAttributeValue() -> String {
var answer = "debug: "+debug.description
if spanFilter != nil {
Expand Down Expand Up @@ -259,7 +274,9 @@ var splunkRumInitializeCalledTime = Date()
spanDb: spanDb,
maxFileSizeBytes: options?.spanDiskCacheMaxSize ?? DEFAULT_DISK_CACHE_MAX_SIZE_BYTES)
let limiting = LimitingExporter(proxy: diskExporter, spanFilter: options?.spanFilter ?? nil)
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting))
let delay = options?.bspScheduleDelay ?? 5.0
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting,
scheduleDelay: delay))
} else {
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
SpanDb.deleteAtDefaultLocation()
Expand All @@ -268,7 +285,9 @@ var splunkRumInitializeCalledTime = Date()
let zipkin = ZipkinTraceExporter(options: exportOptions)
let retry = RetryExporter(proxy: zipkin)
let limiting = LimitingExporter(proxy: retry, spanFilter: options?.spanFilter ?? nil)
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting))
let delay = options?.bspScheduleDelay ?? 5.0
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting,
scheduleDelay: delay))
}

if options?.debug ?? false {
Expand All @@ -288,10 +307,12 @@ var splunkRumInitializeCalledTime = Date()
}
initializeNetworkTypeMonitoring()
initalizeUIInstrumentation()
startSlowFrameDetector(
slowFrameDetectionThresholdMs: options?.slowFrameDetectionThresholdMs,
frozenFrameDetectionThresholdMs: options?.frozenFrameDetectionThresholdMs
)
if options?.slowRenderingDetectionEnabled ?? true {
startSlowFrameDetector(
slowFrameDetectionThresholdMs: options?.slowFrameDetectionThresholdMs,
frozenFrameDetectionThresholdMs: options?.frozenFrameDetectionThresholdMs
)
}
// not initializeAppLifecycleInstrumentation, done at end of AppStart
srInit.end()
initialized = true
Expand Down Expand Up @@ -351,7 +372,9 @@ var splunkRumInitializeCalledTime = Date()
spanDb: spanDb,
maxFileSizeBytes: options.spanDiskCacheMaxSize)
let limiting = LimitingExporter(proxy: diskExporter, spanFilter: options.spanFilter)
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting))
let delay = options.bspScheduleDelay
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting,
scheduleDelay: delay))
} else {
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
SpanDb.deleteAtDefaultLocation()
Expand All @@ -360,7 +383,9 @@ var splunkRumInitializeCalledTime = Date()
let zipkin = ZipkinTraceExporter(options: exportOptions)
let retry = RetryExporter(proxy: zipkin)
let limiting = LimitingExporter(proxy: retry, spanFilter: options.spanFilter)
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting))
let delay = options.bspScheduleDelay
tracerProvider.addSpanProcessor(BatchSpanProcessor(spanExporter: limiting,
scheduleDelay: delay))
}

if options.debug {
Expand All @@ -378,10 +403,12 @@ var splunkRumInitializeCalledTime = Date()
}
initializeNetworkTypeMonitoring()
initalizeUIInstrumentation()
startSlowFrameDetector(
slowFrameDetectionThresholdMs: options.slowFrameDetectionThresholdMs,
frozenFrameDetectionThresholdMs: options.frozenFrameDetectionThresholdMs
)
if options.slowRenderingDetectionEnabled {
startSlowFrameDetector(
slowFrameDetectionThresholdMs: options.slowFrameDetectionThresholdMs,
frozenFrameDetectionThresholdMs: options.frozenFrameDetectionThresholdMs
)
}
// not initializeAppLifecycleInstrumentation, done at end of AppStart
srInit.end()
initialized = true
Expand Down
20 changes: 19 additions & 1 deletion SplunkRumWorkspace/SplunkRum/SplunkRum/SplunkRumBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import Foundation
private var networkInstrumentation: Bool = true
private var enableDiskCache: Bool = false
private var spanDiskCacheMaxSize: Int64 = DEFAULT_DISK_CACHE_MAX_SIZE_BYTES
private var slowRenderingDetectionEnabled: Bool = true
private var slowFrameDetectionThresholdMs: Double = 16.7
private var frozenFrameDetectionThresholdMs: Double = 700
private var sessionSamplingRatio: Double = 1.0
private var appName: String?
private var spanSchedulingDelay: TimeInterval = 5.0

@objc public init(beaconUrl: String, rumAuth: String) {
self.beaconUrl = beaconUrl
Expand Down Expand Up @@ -108,6 +110,13 @@ import Foundation
return self
}

@discardableResult
@objc
public func slowRenderingDetectionEnabled(_ enabled: Bool) -> SplunkRumBuilder {
self.slowRenderingDetectionEnabled = enabled
return self
}

@discardableResult
@objc
public func slowFrameDetectionThresholdMs(thresholdMs: Double) -> SplunkRumBuilder {
Expand Down Expand Up @@ -136,6 +145,13 @@ import Foundation
return self
}

@discardableResult
@objc
public func setSpanSchedulingDelay(seconds: TimeInterval) -> SplunkRumBuilder {
self.spanSchedulingDelay = seconds
return self
}

@discardableResult
@objc
public func build() -> Bool {
Expand All @@ -151,8 +167,10 @@ import Foundation
networkInstrumentation: self.networkInstrumentation,
enableDiskCache: self.enableDiskCache,
spanDiskCacheMaxSize: self.spanDiskCacheMaxSize,
slowRenderingDetectionEnabled: self.slowRenderingDetectionEnabled,
slowFrameDetectionThresholdMs: self.slowFrameDetectionThresholdMs,
frozenFrameDetectionThresholdMs: self.frozenFrameDetectionThresholdMs,
sessionSamplingRatio: self.sessionSamplingRatio))
sessionSamplingRatio: self.sessionSamplingRatio,
spanSchedulingDelay: self.spanSchedulingDelay))
}
}

0 comments on commit 9522240

Please sign in to comment.