Skip to content

app/vlinsert/opentelemetry: fix field collisions after flattening#1379

Open
yagmurcicekdagi wants to merge 1 commit intoVictoriaMetrics:masterfrom
yagmurcicekdagi:fix_otel_field_collision
Open

app/vlinsert/opentelemetry: fix field collisions after flattening#1379
yagmurcicekdagi wants to merge 1 commit intoVictoriaMetrics:masterfrom
yagmurcicekdagi:fix_otel_field_collision

Conversation

@yagmurcicekdagi
Copy link
Copy Markdown

Changes

Fixes: #1371

  • Added -opentelemetry.enableFieldPrefixes flag (disabled by default). When enabled, fields are prefixed
    by their source before flattening:

  resource.attributes[\"service.name\"] -> resource.service.name
  logRecord.attributes[\"service.name\"] -> attributes.service.name
  logRecord.body (KV list) [\"service.name\"] -> body.service.name
  • Added tests covering prefix mode for all field sources and verify generated fields
    (trace_id, span_id, severity_number, severity_text) remain unprefixed.

  • Updated docs/victorialogs/data-ingestion/opentelemetry.md with a Field prefixes
    section and victoria_logs_common_flags.md with the new flag.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

@yagmurcicekdagi
Copy link
Copy Markdown
Author

Hi, Can you review this pr ? @func25? I've fixed the field name collisions, haven't implemented the query/merge path duplicate name issue yet. Let me know what you think so I can adjust the code.

Signed-off-by: Yağmur Çiçekdağı <ygmcicekdagi@gmail.com>
@yagmurcicekdagi yagmurcicekdagi force-pushed the fix_otel_field_collision branch from d6d6440 to b8779ba Compare May 4, 2026 12:33
@func25
Copy link
Copy Markdown
Member

func25 commented May 4, 2026

Hey, thank you for your interest in this issue.

haven't implemented the query/merge path duplicate name issue yet

I'd recommend starting with a few smaller issues first to get familiar with the logic, the code conventions and the contribution guidelines. As I skimmed through it, this PR appears to be a low-quality AI-generated contribution.

@yagmurcicekdagi
Copy link
Copy Markdown
Author

yagmurcicekdagi commented May 4, 2026

I did use AI to help me locate the issue and give me skeleton to work on, but if you mean the abstractions that I put , that was from me unfortunately -which breaks the contribution guidelines

Could you maybe guide me a bit to how to make this code better quality?

I'd still love to work on getting this to better quality code, but if you don't want that, that's totally understandable as well

Thanks for the reply @func25

Copy link
Copy Markdown
Member

@func25 func25 left a comment

Choose a reason for hiding this comment

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

No problem. I saw some improvements/bug fixes in this PR itself, it's not entirely AI-generated slop, so haven't closed it. Please see below comments.

Using AI to enhance quality and make small improvements is encouraged, but not for this kind of task (yet).

Comment on lines +18 to +41
const (
resourcePrefix = "resource"
attributesPrefix = "attributes"
bodyPrefix = "body"
)

// fieldPrefixes holds the field name prefixes for each OpenTelemetry source.
// Empty string means no prefix (default behaviour).
type fieldPrefixes struct {
resource string
attributes string
body string
}

func newFieldPrefixes(enabled bool) fieldPrefixes {
if !enabled {
return fieldPrefixes{}
}
return fieldPrefixes{
resource: resourcePrefix,
attributes: attributesPrefix,
body: bodyPrefix,
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's avoid this mini-framework and put the code directly into decoder functions, e.g. decodeResource, decodeLogRecord, ...

}

func decodeResourceLogs(src []byte, pushLogs pushLogsHandler) (err error) {
func decodeResourceLogs(src []byte, pushLogs pushLogsHandler, prefixes fieldPrefixes) (err error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
func decodeResourceLogs(src []byte, pushLogs pushLogsHandler, prefixes fieldPrefixes) (err error) {
func decodeResourceLogs(src []byte, pushLogs pushLogsHandler, useFieldNamePrefixes bool) (err error) {

Comment on lines +82 to +87
effectiveMsgFields := msgFields
if useFieldPrefixes && len(msgFields) == 0 {
// When field prefixes are enabled, scalar body values are stored under the "body" field name.
// Auto-rename "body" -> "_msg" so the body still appears as the log message by default.
effectiveMsgFields = []string{"body"}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's better to avoid this kind of nuance here

return "", 0, fmt.Errorf("cannot read Body")
}
if err := decodeAnyValue(body, fs, fb, ""); err != nil {
if err := decodeAnyValue(body, fs, fb, prefixes.body); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if err := decodeAnyValue(body, fs, fb, prefixes.body); err != nil {
if err := decodeAnyValue(body, fs, fb, "", bodyKeyValueListFieldNamePrefix); err != nil {

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.

otel/ingestion: prevent OpenTelemetry field collisions after flattening

2 participants