Skip to content

fix(daemon): handle bool values sent as strings in OTEL processor#166

Merged
AnnatarHe merged 1 commit intomainfrom
fix/ccotel-bool-value-parsing
Dec 25, 2025
Merged

fix(daemon): handle bool values sent as strings in OTEL processor#166
AnnatarHe merged 1 commit intomainfrom
fix/ccotel-bool-value-parsing

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

Summary

  • Added getBoolFromValue helper function to parse boolean values from OTEL data
  • Claude Code sends some boolean values (like success) as strings instead of native bools
  • The new function handles both native bool and string representations ("true"/"false")

Test plan

  • Run existing tests to ensure no regression
  • Test with Claude Code to verify boolean fields are correctly parsed

🤖 Generated with Claude Code

Claude Code sends some boolean values as strings. Added getBoolFromValue
helper function to properly parse both bool and string representations.

🤖 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 addresses a data parsing inconsistency within the daemon's OTEL processor, where boolean values, particularly from Claude Code, are sometimes transmitted as strings instead of native booleans. To rectify this, a new utility function, getBoolFromValue, has been implemented. This function intelligently parses incoming values, accommodating both standard boolean types and their string equivalents, thereby ensuring accurate and reliable processing of boolean fields like success in log records.

Highlights

  • New Helper Function: Introduced a new helper function getBoolFromValue to robustly parse boolean values from commonv1.AnyValue objects.
  • Boolean Parsing Improvement: The getBoolFromValue function handles both native boolean types and string representations (e.g., "true", "false"), specifically addressing cases where Claude Code sends boolean values as strings.
  • OTEL Processor Update: The success field within the parseLogRecord function now utilizes the new getBoolFromValue helper to ensure correct boolean interpretation.
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 4134b61 into main Dec 25, 2025
2 checks passed
@AnnatarHe AnnatarHe deleted the fix/ccotel-bool-value-parsing branch December 25, 2025 16:34
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 25, 2025

Codecov Report

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

Files with missing lines Patch % Lines
daemon/ccotel_processor.go 0.00% 8 Missing ⚠️
Flag Coverage Δ
unittests 19.96% <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 helper function getBoolFromValue to handle boolean values that may be sent as strings from OTEL data sources, which is a good improvement for data parsing robustness. My review includes a critical fix to prevent a potential panic in the new function and a suggestion to improve its clarity using a type switch, which is more idiomatic in Go for this scenario. I've also pointed out some commented-out code that should be removed to keep the codebase clean. While not part of this PR's changes, I noticed that similar helper functions like getIntFromValue and getFloatFromValue might also be vulnerable to a nil pointer panic. It would be beneficial to address this in a follow-up change to improve overall stability.

Comment on lines +539 to +551
func getBoolFromValue(value *commonv1.AnyValue) bool {
// First try to get as bool
if boolVal := value.GetBoolValue(); boolVal {
return boolVal
}
// Try to parse from string (Claude Code sends some values as strings)
if strVal := value.GetStringValue(); strVal != "" {
if parsed, err := strconv.ParseBool(strVal); err == nil {
return parsed
}
}
return false
}
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.

critical

This function can panic if value is nil. The value comes from attr.GetValue(), which can return nil and would cause a panic on value.GetBoolValue(). You should add a nil check at the beginning of the function.

Additionally, the current implementation is a bit difficult to follow. A type switch on value.Value would be more idiomatic for handling protobuf oneof fields, making the logic clearer and more robust.

Suggested change
func getBoolFromValue(value *commonv1.AnyValue) bool {
// First try to get as bool
if boolVal := value.GetBoolValue(); boolVal {
return boolVal
}
// Try to parse from string (Claude Code sends some values as strings)
if strVal := value.GetStringValue(); strVal != "" {
if parsed, err := strconv.ParseBool(strVal); err == nil {
return parsed
}
}
return false
}
func getBoolFromValue(value *commonv1.AnyValue) bool {
if value == nil {
return false
}
switch v := value.Value.(type) {
case *commonv1.AnyValue_BoolValue:
return v.BoolValue
case *commonv1.AnyValue_StringValue:
if parsed, err := strconv.ParseBool(v.StringValue); err == nil {
return parsed
}
}
return false
}

Comment on lines +414 to +419
// case "decision_source":
// event.DecisionSource = value.GetStringValue()
// case "decision_type":
// event.DecisionType = value.GetStringValue()
// case "tool_result_size_bytes":
// event.ToolResultSizeBytes = getIntFromValue(value)
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.

medium

This commented-out code should be removed. If this functionality is planned for the future, it should be tracked in an issue rather than being left as dead code in the codebase, as it reduces readability.

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