Skip to content

Commit

Permalink
[pkg/otlp/logs] Ignore resource attributes semantic conventions outsi…
Browse files Browse the repository at this point in the history
…de of the resource
  • Loading branch information
mx-psi committed Dec 14, 2023
1 parent 0928442 commit 58da274
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
16 changes: 16 additions & 0 deletions .chloggen/mx-psi_resource-attributes-instead-of-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/logs

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Ignore service.name and host attributes at the log record level, only honor them if in the resource attributes.

# The PR related to this change
issues: [223]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
14 changes: 0 additions & 14 deletions pkg/otlp/logs/logs_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,9 @@ func extractHostNameAndServiceName(resourceAttrs pcommon.Map, logAttrs pcommon.M
if src, ok := attributes.SourceFromAttrs(resourceAttrs); ok && src.Kind == source.HostnameKind {
host = src.Identifier
}
// hostName is blank from resource
// we need to derive from log attributes
if host == "" {
if src, ok := attributes.SourceFromAttrs(logAttrs); ok && src.Kind == source.HostnameKind {
host = src.Identifier
}
}
if s, ok := resourceAttrs.Get(conventions.AttributeServiceName); ok {
service = s.AsString()
}
// serviceName is blank from resource
// we need to derive from log attributes
if service == "" {
if s, ok := logAttrs.Get(conventions.AttributeServiceName); ok {
service = s.AsString()
}
}
return host, service
}

Expand Down
32 changes: 16 additions & 16 deletions pkg/otlp/logs/logs_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ func TestTransform(t *testing.T) {
lr: func() plog.LogRecord {
l := plog.NewLogRecord()
l.Attributes().PutStr("app", "test")
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityNumber(5)
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -159,17 +159,17 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.SetSpanID(spanID)
l.SetTraceID(traceID)
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityNumber(5)
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -192,17 +192,17 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.Attributes().PutStr("spanid", "2e26da881214cd7c")
l.Attributes().PutStr("traceid", "437ab4d83468c540bb0f3398a39faa59")
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityNumber(5)
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -225,17 +225,17 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.Attributes().PutStr("span_id", "2e26da881214cd7c")
l.Attributes().PutStr("trace_id", "740112b325075be8c80a48de336ebc67")
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityNumber(5)
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -258,17 +258,17 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.Attributes().PutStr("spanid", "2e26da881214cd7c")
l.Attributes().PutStr("traceid", "invalidtraceid")
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityNumber(5)
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -290,18 +290,18 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.SetSpanID(spanID)
l.SetTraceID(traceID)
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityText("alert")
l.SetSeverityNumber(5)
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -325,18 +325,18 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.SetSpanID(spanID)
l.SetTraceID(traceID)
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.SetSeverityNumber(13)
l.Body().SetStr("This is log")
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand All @@ -360,18 +360,18 @@ func TestTransform(t *testing.T) {
l.Attributes().PutStr("app", "test")
l.SetSpanID(spanID)
l.SetTraceID(traceID)
l.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
l.Attributes().PutStr("level", "error")
l.Body().SetStr("This is log")
return l
}(),
res: func() pcommon.Resource {
r := pcommon.NewResource()
r.Attributes().PutStr(conventions.AttributeServiceName, "otlp_col")
return r
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString(""),
Ddtags: datadog.PtrString("service:otlp_col"),
Message: *datadog.PtrString(""),
Service: datadog.PtrString("otlp_col"),
AdditionalProperties: map[string]string{
Expand Down

0 comments on commit 58da274

Please sign in to comment.