You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Converting log resources for loki labels works only for the first LogRecord.
Reading the code, I figured out that after first LogRecord process, resource attributes that were promoted to label are removed, so LogRecords #1 and #2 will not be able to convert labels.
for k := 0; k < logs.Len(); k++ {
// similarly, we may remove attributes, so change only our version
log := plog.NewLogRecord()
logs.At(k).CopyTo(log)
mergedLabels := convertAttributesAndMerge(log.Attributes(), resource.Attributes())
// remove the attributes that were promoted to labels
removeAttributes(log.Attributes(), mergedLabels)
removeAttributes(resource.Attributes(), mergedLabels)
Also could notice that a copy of resources are made, but I think that it should be inside LogRecord loop, not outside. Ex:
This:
for i := 0; i < rls.Len(); i++ {
ills := rls.At(i).ScopeLogs()
for j := 0; j < ills.Len(); j++ {
logs := ills.At(j).LogRecords()
for k := 0; k < logs.Len(); k++ {
// we may remove attributes, so we make a copy and change our version
resource := pcommon.NewResource()
rls.At(i).Resource().CopyTo(resource)
// similarly, we may remove attributes, so change only our version
log := plog.NewLogRecord()
logs.At(k).CopyTo(log)
mergedLabels := convertAttributesAndMerge(log.Attributes(), resource.Attributes())
// remove the attributes that were promoted to labels
removeAttributes(log.Attributes(), mergedLabels)
removeAttributes(resource.Attributes(), mergedLabels)
Instead of this:
for i := 0; i < rls.Len(); i++ {
ills := rls.At(i).ScopeLogs()
// we may remove attributes, so we make a copy and change our version
resource := pcommon.NewResource()
rls.At(i).Resource().CopyTo(resource)
for j := 0; j < ills.Len(); j++ {
logs := ills.At(j).LogRecords()
for k := 0; k < logs.Len(); k++ {
// similarly, we may remove attributes, so change only our version
log := plog.NewLogRecord()
logs.At(k).CopyTo(log)
mergedLabels := convertAttributesAndMerge(log.Attributes(), resource.Attributes())
// remove the attributes that were promoted to labels
removeAttributes(log.Attributes(), mergedLabels)
removeAttributes(resource.Attributes(), mergedLabels)
Steps to Reproduce
Application writes 3 LogRecords:
log.info("Info example #0");
log.info("Info example #1");
log.info("Info example #2");
Expected Result
I expected all logRecords to have host_name, container_name and namespace labels.
What happened?
Description
Converting log resources for loki labels works only for the first LogRecord.
Reading the code, I figured out that after first LogRecord process, resource attributes that were promoted to label are removed, so LogRecords #1 and #2 will not be able to convert labels.
Also could notice that a copy of resources are made, but I think that it should be inside LogRecord loop, not outside. Ex:
This:
Instead of this:
Steps to Reproduce
Application writes 3 LogRecords:
Expected Result
I expected all logRecords to have host_name, container_name and namespace labels.
Actual Result
Only the first LogRecord contains correct labels.
Collector version
0.60.0
Environment information
No response
OpenTelemetry Collector configuration
Log output
Additional context
No response
The text was updated successfully, but these errors were encountered: