Skip to content

sdk/log: Deduplicate key-value collections in Record.SetBody #6982

@pellared

Description

@pellared

"Deduplication" of the key-values is part of the specification and it also involves Body of the log record.
Body is of any type (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-body).
any can have a map<string, any> (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-any).
map<string, any> does not allow duplicated keys (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-mapstring-any).

Currently, we're not de-duplicating key-value collections within the log record body.

// SetBody sets the body of the log record.
func (r *Record) SetBody(v log.Value) {
r.body = v
}

Here is what we should add

case log.KindMap:
// Deduplicate then truncate. Do not do at the same time to avoid
// wasted truncation operations.
kvs, dropped := dedup(val.AsMap())
r.addDropped(dropped)

It is important to do it recursively and also make sure that the attribute limits are NOT applied; see: open-telemetry/opentelemetry-specification#4006.

Originally posted by @pellared in #6968 (comment)

Metadata

Metadata

Assignees

Labels

area:logsPart of OpenTelemetry logsbugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is neededpkg:SDKRelated to an SDK package

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions