in Sources/CrashReporter2/CrashReporterOTel.swift [39:117]
func initOtel() {
let scope = CrashReporterOTel.SCOPE
let workspace = ConfigurationManager.shared.workspaceProvider?(scope)
let accessKey = ConfigurationManager.shared.accessKeyProvider?(scope)
let environment = ConfigurationManager.shared.environmentProvider?(scope)
let otlpSLSExporter = OtlpSLSSpanExporter.builder(scope)
.setEndpoint(workspace?.endpoint ?? "")
.setProject(workspace?.project ?? "")
.setLogstore("\(workspace?.instanceId ?? "")-uem-mobile-raw")
.setPersistentFlush(true)
.setAccessKey(
accessKeyId: accessKey?.accessKeyId,
accessKeySecret: accessKey?.accessKeySecret,
accessKeyToken: accessKey?.accessKeySecuritToken
)
.build()
let spanExporters = MultiSpanExporter(spanExporters: [otlpSLSExporter])
let spanProcessor = BatchSpanProcessor(spanExporter: spanExporters)
var appName: String? = ""
var appVersion: String? = ""
var appVersionCode: String? = ""
if let infoDictionary = Bundle.main.infoDictionary {
appName = infoDictionary["CFBundleDisplayName"] as? String ?? infoDictionary["CFBundleName"] as? String
appVersion = infoDictionary["CFBundleShortVersionString"] as? String
appVersionCode = infoDictionary["CFBundleVersion"] as? String
}
#if os(iOS)
let osName = "iOS"
#elseif os(macOS)
let osName = "macOS"
#elseif os(tvOS)
let osName = "tvOS"
#elseif os(watchOS)
let osName = "watchOS"
#else
let osName = "unknown"
#endif
let utdid = environment?.utdid ?? Utdid.getUtdid()
#if canImport(UIKit)
let systemVersion = AttributeValue.string(UIDevice.current.systemVersion)
#elseif canImport(AppKit)
let version = ProcessInfo.processInfo.operatingSystemVersion
let systemVersion = AttributeValue.string("\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)")
#else
let systemVersion = "unknown"
#endif
CrashReporterOTel.tracerProvider = TracerProviderBuilder()
.add(spanProcessor: spanProcessor)
.with(resource: Resource()
.merging(other: Resource(attributes: [
ResourceAttributes.serviceName.rawValue: AttributeValue.string("sls-cocoa"),
ResourceAttributes.deviceId.rawValue: AttributeValue.string(utdid),
ResourceAttributes.deviceManufacturer.rawValue: AttributeValue.string("Apple"),
ResourceAttributes.deviceModelName.rawValue: AttributeValue.string(DeviceUtils.getDeviceModel()),
ResourceAttributes.deviceModelIdentifier.rawValue: AttributeValue.string(DeviceUtils.getDeviceModelIdentifier()),
"device.screen": AttributeValue.string(DeviceUtils.getResolution()),
"app.version": AttributeValue.string(appVersion ?? ""),
"app.versionCode": AttributeValue.string(appVersionCode ?? ""),
"app.name": AttributeValue.string(appName ?? ""),
ResourceAttributes.osName.rawValue: AttributeValue.string(osName),
ResourceAttributes.osType.rawValue: AttributeValue.string("darwin"),
ResourceAttributes.osVersion.rawValue: systemVersion,
ResourceAttributes.osDescription.rawValue: AttributeValue.string("Apple Darwin"),
ResourceAttributes.hostName.rawValue: AttributeValue.string(ProcessInfo.processInfo.hostName),
ResourceAttributes.hostArch.rawValue: AttributeValue.string(DeviceUtils.getCPUArch()),
"uem.data.type": AttributeValue.string(osName),
"uem.sdk.version": AttributeValue.string(CrashReporterOTel.VERSION),
"workspace": AttributeValue.string(workspace?.instanceId ?? ""),
"deployment.environment": AttributeValue.string(environment?.env ?? "default"),
"deployment.channel": AttributeValue.string(environment?.channel ?? "default")
]))
)
.build()
}