Skip to content

[extension/googlecloudlogentryencoding] Fix incorrect snake_case conversion for numeronyms (e.g. k8s)#46588

Merged
codeboten merged 3 commits into
open-telemetry:mainfrom
57Ajay:fix/46571-gcp-log-snake-case
Mar 11, 2026
Merged

[extension/googlecloudlogentryencoding] Fix incorrect snake_case conversion for numeronyms (e.g. k8s)#46588
codeboten merged 3 commits into
open-telemetry:mainfrom
57Ajay:fix/46571-gcp-log-snake-case

Conversation

@57Ajay

@57Ajay 57Ajay commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Description:

This PR fixes an issue where the googlecloudlogentryencoding extension incorrectly converted log field names containing numeronyms (abbreviations containing numbers, such as "k8s") into snake_case.

The Problem:

The previous implementation relied on strcase.ToSnakeWithIgnore, which treats a digit followed by a lowercase letter as a word boundary.

  • Input: labels.authorization.k8s.io/decision
  • Previous Output: labels.authorization.k8_s.io/decision (Incorrect split at 8 and s)
  • Expected Output: labels.authorization.k8s.io/decision

The Solution:

Introduced a shared.ToSnakeCase helper function that wraps the existing library call. It uses a regex replacement ((\d)_([a-z]) -> ${1}${2}) to post-process the string, re-merging digits and subsequent lowercase letters. This approach preserves standard numeronyms (e.g., k8s, v1beta) while maintaining snake_case for standard camelCase inputs.

Link to tracking Issue:

Fixes #46571

Testing:

  • Added unit tests in internal/shared to cover edge cases (k8s, v1beta, standard camelCase).
  • Updated log_entry_test.go to verify the fix in the extension logic.
  • Updated golden files (activity_expected.yaml) to reflect the correct output.
  • Ran tests locally; all tests passed.

Documentation:

  • I have updated the changelog (.chloggen directory)

@57Ajay 57Ajay requested a review from a team as a code owner March 3, 2026 12:31
@57Ajay 57Ajay requested a review from VihasMakwana March 3, 2026 12:31
@github-actions github-actions Bot added the first-time contributor PRs made by new contributors label Mar 3, 2026
@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

@constanca-m constanca-m left a comment

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.

Thank you

@57Ajay

57Ajay commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Thank you

Should i add this:

func ToSnakeCase(s, ignore string) string {
	result := strcase.ToSnakeWithIgnore(s, ignore)

	// Fast path: if there are no digits, skip the regex entirely
	if !strings.ContainsAny(result, "0123456789") {
		return result
	}

	return digitToLetter.ReplaceAllString(result, "${1}${2}")
}

so we skip the regex entirely if no numbers

@paulojmdias

Copy link
Copy Markdown
Member

/workflow-approve

previous component name used:
extension/googlecloudlogentryencoding

corrected component name:
extension/googlecloudlogentry_encoding
@paulojmdias

Copy link
Copy Markdown
Member

/workflow-approve

@57Ajay

57Ajay commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

@paulojmdias It looks like the Checkout Repo step is hitting a GitHub 500 error across multiple jobs (11 failures). Could you please re-run the failed checks?

@paulojmdias

Copy link
Copy Markdown
Member

@57Ajay You could ask for a rerun commenting /rerun only

@57Ajay

57Ajay commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

/rerun

@codeboten codeboten merged commit a809fed into open-telemetry:main Mar 11, 2026
323 of 334 checks passed
@otelbot

otelbot Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @57Ajay! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encoding extension convert log field name unexpectedly

5 participants