feat(profiling): continuous CPU/heap profiling via WithProfiling#6
Open
FrameAutomata wants to merge 2 commits into
Open
feat(profiling): continuous CPU/heap profiling via WithProfiling#6FrameAutomata wants to merge 2 commits into
FrameAutomata wants to merge 2 commits into
Conversation
Add an opt-in background profiler that, on an interval (default 60s, CPU window ~30s capped to interval/2), captures CPU and heap pprof profiles and POSTs each as a separate request to <server>/api/profiles/ingest, reusing the connection-string token and host. The ingest URL is derived from the existing report URL (scheme+host + /api/profiles/ingest); Bearer auth, serverName and appVersion reuse the existing report plumbing. Profiling never affects the host app: capture and upload failures are isolated and silent unless WithDebug is set, and a bad URL disables profiling without failing Init. Verified against the backend contract (tracewayapp/traceway /api/profiles/ingest): path, Bearer auth, service/serverName/appVersion query params, and raw already-gzipped pprof body with no extra Content-Encoding. Core package only; HTTP middleware pass-through options are a follow-up. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Init split the connection string on "@" and unconditionally indexed connParts[1], panicking with "index out of range" when the string had no "@". Use SplitN with a length guard so a malformed connection string returns an error, and so a "@" inside the URL (e.g. userinfo) no longer silently truncates the endpoint. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds opt-in continuous profiling to the core SDK.
traceway.WithProfiling(serviceName)starts a background goroutine that, on an interval (WithProfilingInterval, default 60s; CPU window ~30s, capped tointerval/2), captures a CPU profile and a heap profile and POSTs each as a separate request to<server>/api/profiles/ingest.Also folds in a small, independent hardening commit:
Initno longer panics on a malformed connection string.Why
Profiling powers flame graphs / allocation views alongside the existing traces and metrics. The ingest contract is already live on the backend.
How it works
scheme://host+/api/profiles/ingest); auth (Authorization: Bearer <token>),serverName, andappVersioncome from the same config as/api/report.Content-Encoding— the backend's gzip middleware only decompresses when that header is present, andprofile.Parsereads gzipped pprof directly.service/serverName/appVersionquery params, raw pprof body, and200 {}success.WithDebug(true)is set; a bad URL disables profiling without failingInit.Scope
Core
tracewaypackage only. HTTP middleware pass-through options (tracewayhttp/gin/fiber/chi/fasthttp) are a deliberate follow-up — apps that calltraceway.Initdirectly (e.g. workers usingMeasureTask) can enable it today.Commits
feat(profiling): add WithProfiling continuous CPU/heap profilingfix(init): reject malformed connection strings instead of panickingTests
Content-Encoding); options wiring; and a deterministic single-cycle test asserting CPU + heap are sent as two requests.Initpanic fix.go test,go vet,go buildall green; framework subpackage suites (tracewayhttp,tracewaygin) green.Docs
See
docs/profiling.md.🤖 Generated with Claude Code