I've been looking for a way to enrich the error logs from my backend by a stack trace and discovered the Backtrace
API.
I thought it might be useful to share the progress/differences I've observed trying to use this API with Swift 5.9 and Swift 5.10 running my Vapor backend in a docker container on DigitalOcean using their App Platform $10.00 / month thing. Here is the Dockerfile I'm using Dockerfile · GitHub
Here is my test routes
import _Backtracing
app.get("teststacktracep") { req async throws in
let now = Date.now
let trace = try Backtrace.capture(algorithm: .precise).symbolicated()
return "\(Date.now.timeIntervalSince1970 - now.timeIntervalSince1970) | \(trace?.frames)"
}
app.get("teststacktracef") { req async throws in
let now = Date.now
let trace = try Backtrace.capture(algorithm: .fast).symbolicated()
return "\(Date.now.timeIntervalSince1970 - now.timeIntervalSince1970) | \(trace?.frames)"
}
What I've observed is that precise symbolication seems to take around 15 seconds, fast symbolication seems to take around 7 seconds on average. This seems to be roughly 2x faster than my previous attempts using Swift 5.9.
The 15 seconds seems like an acceptable time to me to collect a symbolicated stack trace when my process crashes before it's reset. The 7 seconds when using fast symbolication is still unfortunately way too slow for me use case where I'd like to attach a stack trace to an error log being sent to Sentry (uses standard Logging framework with sentry as a destination), so I'll probably need to look into my options uploading unsymbolicated stack trace and performing the symbolication asynchronously. Any guidance here would be appreciated.
Furthermore, what I've been observing with the limited analytics DigitalOcean App Platform provides, there seems to be a significant spike (leak???) in memory every time I trigger the API (call the vapor route) that does not drop back over time. Please refer to the screenshot bellow
I believe that the total amount of available RAM is 1GB.
This matches my experience using Swift 5.9, the memory footprint (leak???) just also seems lower from what I remember.
Hope this helps!