Skip to content

Commit 5f530e8

Browse files
DEMRUM-2304: remove force try for regex compilation (#313)
* DEMRUM-2304: remove force try in regex compilation * DEMRUM-2293: Remove project and workspace files (#309) * feat: Remove Agent's project and workspace files * chore: Consolidate linting into the top-level Tools/ folder * feat: Move DevelApp and AgentTestApp to SPM dependency * DEMRUM-2304: update outdated link that was causing pipeline issue * DEMRUM-2304: reenable SplunkNetwork lint checks in app project files --------- Co-authored-by: Martin Budínský <[email protected]>
1 parent 56bd0b9 commit 5f530e8

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

Applications/AgentTestApp/AgentTestApp.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
);
200200
runOnlyForDeploymentPostprocessing = 0;
201201
shellPath = /bin/sh;
202-
shellScript = "TOOLS_DIR=\"${PROJECT_DIR}/../../Tools\"\n\n# Check SplunkAgent directory\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAgent/\necho \"$(pwd)\"\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCommon module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCommon/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSessionReplayProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSessionReplayProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCrashReports module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCrashReports/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkAppStart module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAppStart/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCustomData module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCustomData/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkErrorReporting module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkErrorReporting/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkNetwork module\n# cd \"${PROJECT_DIR}\"\n# cd ../../SplunkNetwork/\n# \"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetry module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetry/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetryBackgroundExporter module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetryBackgroundExporter/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSlowFrameDetector module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSlowFrameDetector/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebView module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebView/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebViewProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebViewProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n";
202+
shellScript = "TOOLS_DIR=\"${PROJECT_DIR}/../../Tools\"\n\n# Check SplunkAgent directory\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAgent/\necho \"$(pwd)\"\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCommon module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCommon/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSessionReplayProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSessionReplayProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCrashReports module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCrashReports/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkAppStart module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAppStart/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCustomData module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCustomData/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkErrorReporting module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkErrorReporting/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkNetwork module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkNetwork/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetry module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetry/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetryBackgroundExporter module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetryBackgroundExporter/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSlowFrameDetector module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSlowFrameDetector/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebView module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebView/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebViewProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebViewProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n";
203203
};
204204
/* End PBXShellScriptBuildPhase section */
205205

Applications/DevelApp/DevelApp.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
);
186186
runOnlyForDeploymentPostprocessing = 0;
187187
shellPath = /bin/sh;
188-
shellScript = "TOOLS_DIR=\"${PROJECT_DIR}/../../Tools\"\n\n# Check SplunkAgent directory\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAgent/\necho \"$(pwd)\"\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCommon module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCommon/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSessionReplayProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSessionReplayProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCrashReports module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCrashReports/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkAppStart module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAppStart/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCustomData module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCustomData/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkErrorReporting module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkErrorReporting/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkNetwork module\n# cd \"${PROJECT_DIR}\"\n# cd ../../SplunkNetwork/\n# \"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetry module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetry/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetryBackgroundExporter module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetryBackgroundExporter/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSlowFrameDetector module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSlowFrameDetector/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebView module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebView/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebViewProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebViewProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n";
188+
shellScript = "TOOLS_DIR=\"${PROJECT_DIR}/../../Tools\"\n\n# Check SplunkAgent directory\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAgent/\necho \"$(pwd)\"\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCommon module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCommon/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSessionReplayProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSessionReplayProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCrashReports module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCrashReports/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkAppStart module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkAppStart/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkCustomData module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkCustomData/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkErrorReporting module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkErrorReporting/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkNetwork module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkNetwork/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetry module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetry/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkOpenTelemetryBackgroundExporter module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkOpenTelemetryBackgroundExporter/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkSlowFrameDetector module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkSlowFrameDetector/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebView module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebView/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n\n# Check SplunkWebViewProxy module\ncd \"${PROJECT_DIR}\"\ncd ../../SplunkWebViewProxy/\n\"${TOOLS_DIR}/Linting.sh\" --config \"${TOOLS_DIR}/.swiftlint.yml\"\n";
189189
};
190190
/* End PBXShellScriptBuildPhase section */
191191

SplunkNetwork/Sources/SplunkNetwork/NetworkInstrumentation.swift

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,37 @@ public class NetworkInstrumentation {
152152
}
153153
}
154154

155-
let serverTimingPattern = #"traceparent;desc=['\"]00-([0-9a-f]{32})-([0-9a-f]{16})-01['\"]"#
156-
157155
func addLinkToSpan(span: Span, valStr: String) {
158-
let regex = try! NSRegularExpression(pattern: serverTimingPattern)
156+
157+
let serverTimingPattern = #"traceparent;desc=['"]00-([0-9a-f]{32})-([0-9a-f]{16})-01['"]"#
158+
159+
guard let regex = try? NSRegularExpression(pattern: serverTimingPattern) else {
160+
self.logger.log(level: .fault) {
161+
"Regex failed to compile"
162+
}
163+
// Intentional hard failure in both Debug and Release builds
164+
preconditionFailure("Regex failed to compile. Likely programmer error in edit of serverTimingPattern regex: #\(serverTimingPattern)#")
165+
}
166+
167+
// Match the regex against the input string
159168
let result = regex.matches(in: valStr, range: NSRange(location: 0, length: valStr.utf16.count))
160-
// per standard regex logic, number of matched segments is 3 (whole match plus two () captures)
161-
if result.count != 1 || result[0].numberOfRanges != 3 {
169+
170+
// Ensure there's exactly one match and the correct number of capture groups
171+
guard result.count == 1, result[0].numberOfRanges == 3,
172+
let traceIdRange = Range(result[0].range(at: 1), in: valStr),
173+
let spanIdRange = Range(result[0].range(at: 2), in: valStr) else {
174+
// If the match or capture groups are invalid, log and return early
175+
// Also, prevent over-long log output
176+
let truncatedValStr = valStr.count > 255 ? String(valStr.prefix(252)) + "..." : valStr
177+
self.logger.log(level: .debug) {
178+
"Failed to match traceparent string: \(truncatedValStr)"
179+
}
162180
return
163181
}
164-
let traceId = String(valStr[Range(result[0].range(at: 1), in: valStr)!])
165-
let spanId = String(valStr[Range(result[0].range(at: 2), in: valStr)!])
182+
183+
let traceId = String(valStr[traceIdRange])
184+
let spanId = String(valStr[spanIdRange])
185+
166186
span.setAttribute(key: "link.traceId", value: traceId)
167187
span.setAttribute(key: "link.spanId", value: spanId)
168188
}

0 commit comments

Comments
 (0)