Skip to content

feat(ccotel): add debug config for raw JSON output#155

Merged
AnnatarHe merged 1 commit intomainfrom
feat/ccotel-debug-logging
Dec 25, 2025
Merged

feat(ccotel): add debug config for raw JSON output#155
AnnatarHe merged 1 commit intomainfrom
feat/ccotel-debug-logging

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

Summary

  • Add debug option to CCOtel config for troubleshooting OTEL data
  • When enabled, writes raw JSON metrics/logs to /tmp/shelltime/ccotel-debug-{metrics,logs}.txt
  • Includes timestamps for each entry

Config Example

[ccotel]
enabled = true
grpcPort = 54027
debug = true

Test plan

  • Enable debug in config and verify files are created in /tmp/shelltime/
  • Verify metrics and logs are written in readable JSON format
  • Verify build passes

🤖 Generated with Claude Code

Add debug option to CCOtel config that writes raw OTEL metrics and logs
to files in /tmp/shelltime/ for troubleshooting purposes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the CCOtel processor by adding a new debugging feature. It allows developers and operators to inspect the raw OpenTelemetry metrics and logs in JSON format directly on the filesystem. This capability is invaluable for verifying the structure and content of the data being processed, aiding in troubleshooting and ensuring data integrity before it is forwarded to the backend.

Highlights

  • New Debug Configuration: Introduced a new "debug" option within the "ccotel" configuration, allowing users to enable raw JSON output for OpenTelemetry data.
  • Raw JSON Output: When the "debug" option is enabled, the system will write raw JSON representations of incoming metrics and logs to files named "ccotel-debug-metrics.txt" and "ccotel-debug-logs.txt" respectively, located in "/tmp/shelltime/".
  • Timestamped Entries: Each entry written to the debug files includes a timestamp, making it easier to track the flow of data over time during troubleshooting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@AnnatarHe AnnatarHe merged commit 86893b0 into main Dec 25, 2025
2 checks passed
@AnnatarHe AnnatarHe deleted the feat/ccotel-debug-logging branch December 25, 2025 07:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 25, 2025

Codecov Report

❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
daemon/ccotel_processor.go 0.00% 24 Missing ⚠️
Flag Coverage Δ
unittests 19.74% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
daemon/ccotel_processor.go 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helpful debugging feature for the CCOtel processor, allowing raw OTEL data to be logged to files. The implementation is straightforward and follows the description.

My main feedback concerns a potential race condition in the new writeDebugFile function. Since the OTEL processor handles requests concurrently, multiple goroutines could attempt to write to the same debug file simultaneously, leading to corrupted output. I've suggested adding a mutex to synchronize file access and ensure thread safety. I've also included a minor suggestion to improve file writing performance within the same fix.

Overall, this is a valuable addition for troubleshooting. Addressing the concurrency issue will make it robust.

config model.ShellTimeConfig
endpoint model.Endpoint
hostname string
debug bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To prevent race conditions when writing to debug files from concurrent goroutines, a mutex should be added to this struct. This will be used in the writeDebugFile function to ensure thread-safe file access. You will also need to add import "sync" to the file's import block.

	debug    bool
	debugMtx sync.Mutex

Comment on lines +52 to 77
func (p *CCOtelProcessor) writeDebugFile(filename string, data interface{}) {
debugDir := filepath.Join(os.TempDir(), "shelltime")
if err := os.MkdirAll(debugDir, 0755); err != nil {
slog.Error("CCOtel: Failed to create debug directory", "error", err)
return
}

filePath := filepath.Join(debugDir, filename)
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
slog.Error("CCOtel: Failed to open debug file", "error", err, "path", filePath)
return
}
defer f.Close()

jsonData, err := json.MarshalIndent(data, "", " ")
if err != nil {
slog.Error("CCOtel: Failed to marshal debug data", "error", err)
return
}

timestamp := time.Now().Format(time.RFC3339)
if _, err := f.WriteString(fmt.Sprintf("\n--- %s ---\n%s\n", timestamp, jsonData)); err != nil {
slog.Error("CCOtel: Failed to write debug data", "error", err)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This function writes to a file but doesn't handle concurrent access, which can lead to race conditions and corrupted debug logs since ProcessMetrics and ProcessLogs can be called from multiple goroutines. To ensure thread safety, the file writing operations should be synchronized using a mutex.

Additionally, using fmt.Sprintf with f.WriteString can be inefficient for large JSON payloads as it allocates a single large string. Using fmt.Fprintf is more memory-efficient.

The suggested change below incorporates both thread safety with a mutex and more efficient file writing. Note that this change depends on another suggestion to add the debugMtx field to the CCOtelProcessor struct.

func (p *CCOtelProcessor) writeDebugFile(filename string, data interface{}) {
	p.debugMtx.Lock()
	defer p.debugMtx.Unlock()

	debugDir := filepath.Join(os.TempDir(), "shelltime")
	if err := os.MkdirAll(debugDir, 0755); err != nil {
		slog.Error("CCOtel: Failed to create debug directory", "error", err)
		return
	}

	filePath := filepath.Join(debugDir, filename)
	f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
	if err != nil {
		slog.Error("CCOtel: Failed to open debug file", "error", err, "path", filePath)
		return
	}
	defer f.Close()

	jsonData, err := json.MarshalIndent(data, "", "  ")
	if err != nil {
		slog.Error("CCOtel: Failed to marshal debug data", "error", err)
		return
	}

	timestamp := time.Now().Format(time.RFC3339)
	if _, err := fmt.Fprintf(f, "\n--- %s ---\n%s\n", timestamp, jsonData); err != nil {
		slog.Error("CCOtel: Failed to write debug data", "error", err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant