ci: add sidecar start/stop lifecycle for Claude Code telemetry#107
Open
jqdsouza wants to merge 3 commits into
Open
ci: add sidecar start/stop lifecycle for Claude Code telemetry#107jqdsouza wants to merge 3 commits into
jqdsouza wants to merge 3 commits into
Conversation
`ci exec` only captures telemetry when it wraps the Claude invocation. The sidecar lifecycle covers the case where Claude runs inside another action or a later step that cannot be wrapped: - `beacon ci start` provisions and launches the collector in the background, records a tokenless session state file, and exports the Claude OTLP environment variables (appending them to $GITHUB_ENV in GitHub Actions) so every later step in the job emits to the sidecar. - `beacon ci stop` reads the state file, terminates the collector by PID (escalating to kill after a grace period), validates the runtime log, and honors --require-telemetry / --keep-artifacts like `ci exec`. The Claude telemetry variables are now produced by a single ClaudeTelemetryVars source of truth shared by in-process injection (ci exec) and the $GITHUB_ENV export (ci start). The forwarding token is read from the collector's environment at start and never written to the state file. Includes a reference sidecar workflow under examples/ and README docs. https://claude.ai/code/session_01XeN6mjkot19NzydHEazaWq
…o start Bug 1: ci stop now derives the state file path from --log-path when neither --state-file nor --base-dir is specified, mirroring how ci start derives BaseDir from the log path via resolveBaseDir. Bug 2: ci start now hooks SIGINT/SIGTERM so that if the process is interrupted after StartDetached succeeds, the detached collector is stopped instead of being orphaned with ports held. Co-authored-by: Justin D'Souza <jqdsouza@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Stop lacks base-dir flag
- Added ciStopCmd to the --base-dir flag registration loop so that
beacon ci stop --base-dircorrectly resolves the session state path written byci start --base-dir.
- Added ciStopCmd to the --base-dir flag registration loop so that
You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 453fad6. Configure here.
The --base-dir flag was only registered for ci exec and ci start, but runCIStop checks ciOpts.baseDir to resolve the session state path. Without the flag on ci stop, ciOpts.baseDir was always empty, causing stop to fall back to DefaultStatePath() and fail to find the session state written by a start that used a custom base directory. This left the sidecar collector running. Add ciStopCmd to the --base-dir flag registration loop and mark it hidden (consistent with exec and start). Co-authored-by: Justin D'Souza <jqdsouza@users.noreply.github.com>
| if err != nil { | ||
| return err | ||
| } | ||
| defer logFile.Close() |
| if err != nil { | ||
| return err | ||
| } | ||
| defer f.Close() |
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.

Summary
Adds a sidecar lifecycle (
beacon ci start/beacon ci stop) for Claude Code CI telemetry.ci execonly captures telemetry when it can wrap the Claude invocation; the sidecar covers the common case where Claude runs inside another action or a later step you can't wrap.How it works
ci startprovisions and launches the collector detached (background, reparented to init on exit), records a small tokenless session state file ($RUNNER_TEMP/beacon/session.json), and exports the Claude OTLP env vars — appending them to$GITHUB_ENVin GitHub Actions so every later step in the job emits to the sidecar.ci stopreads the state file, terminates the collector by PID (SIGTERM, escalating to kill after a grace period), validates the runtime log, and honors--require-telemetry/--keep-artifactsexactly likeci exec.Notable details
ClaudeTelemetryVarsis shared by in-process injection (ci exec) and the$GITHUB_ENVexport (ci start);ClaudeEnvis refactored to use it.${env:...}mechanism) and is never written to the state file; a round-trip test asserts the state contains no token.StartDetachedreaps the child via a goroutine if it exits while the short-livedci startprocess is alive; in normal useci startexits immediately and the OS reparents/reaps afterci stopsignals by PID.Tests
New
sidecar_test.go(start→stop lifecycle with a fake collector, readiness-failure returns error + resets PID, state round-trip with no-token assertion) and aClaudeTelemetryVarsretention test.internal/cipasses under-race;cmdgreen;go vetandgofmtclean.Relationship to other PRs
Independent of the composite action (#106). The two compose: a future JS action with a
post:hook could wrapstart/stop, but the documentedstart … always()-stopsteps already deliver the capability today. Includes a reference workflow inexamples/.https://claude.ai/code/session_01XeN6mjkot19NzydHEazaWq
Generated by Claude Code
Note
Medium Risk
Introduces background process management and persists session metadata on disk; SIEM tokens are excluded from state but collector config on disk may still hold env-referenced secrets as in exec.
Overview
Adds a sidecar CI lifecycle (
beacon ci start/beacon ci stop) so Claude Code telemetry can be collected when later steps or third-party actions run Claude without wrapping them inbeacon ci exec.ci startprovisions the ephemeral collector, runs it detached with PID recorded in a tokenlesssession.json, appends Claude OTLP env vars to$GITHUB_ENVon GitHub Actions (and prints them), and supports the same forwarding/collector flags as exec.ci stoploads that state, stops the collector by PID, validates the runtime log (including--require-telemetry/--keep-artifacts), and can clean up artifacts.Refactors Claude OTLP configuration into shared
ClaudeTelemetryVars(used byClaudeEnvandci start). Newsidecar.goimplements detached start/stop, state I/O, and process liveness checks, with tests and README plus an example GitHub Actions workflow.Reviewed by Cursor Bugbot for commit 02f5bb3. Bugbot is set up for automated code reviews on this repo. Configure here.