Skip to content

Commit

Permalink
Added mapping of experimental Otel telemetry.distro.name and version …
Browse files Browse the repository at this point in the history
…attributes (#203)

* Added mapping of experimental Otel telemetry.distro.name and version attributes

* Move initialization outside of branch

---------

Co-authored-by: Victor Martinez <[email protected]>
  • Loading branch information
JonasKunz and v1v authored Mar 12, 2024
1 parent 66e0ef3 commit 0e072ce
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
36 changes: 29 additions & 7 deletions input/otlp/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ func translateResourceMetadata(resource pcommon.Resource, out *modelpb.APMEvent)
// devices. APM server should drop this field.
case "telemetry.sdk.elastic_export_timestamp":
// Do nothing.
case "telemetry.distro.name":
case "telemetry.distro.version":
//distro version & name are handled below and should not end up as labels

// data_stream.*
case attributeDataStreamDataset:
Expand Down Expand Up @@ -375,23 +378,42 @@ func translateResourceMetadata(resource pcommon.Resource, out *modelpb.APMEvent)
// service.name is a required field.
out.Service.Name = "unknown"
}
if out.Agent == nil {
out.Agent = modelpb.AgentFromVTPool()
}
if out.GetAgent().GetName() == "" {
if out.Agent == nil {
out.Agent = modelpb.AgentFromVTPool()
}
// agent.name is a required field.
out.Agent.Name = "otlp"
}
if out.Agent.Version == "" {
// agent.version is a required field.
out.Agent.Version = "unknown"
}
if out.GetService().GetLanguage().GetName() != "" {
if out.Agent == nil {
out.Agent = modelpb.AgentFromVTPool()

distroName, distroNameSet := resource.Attributes().Get("telemetry.distro.name")
distroVersion, distroVersionSet := resource.Attributes().Get("telemetry.distro.version")

if distroNameSet && distroName.Str() != "" {
agentLang := "unknown"
if out.GetService().GetLanguage().GetName() != "" {
agentLang = out.GetService().GetLanguage().GetName()
}

out.Agent.Name = fmt.Sprintf("%s/%s/%s", out.Agent.Name, agentLang, distroName.Str())

//we intentionally do not want to fallback to the Otel SDK version if we have a distro name, this would only cause confusion
out.Agent.Version = "unknown"
if distroVersionSet && distroVersion.Str() != "" {
out.Agent.Version = distroVersion.Str()
}
out.Agent.Name = fmt.Sprintf("%s/%s", out.Agent.Name, out.Service.Language.Name)
} else {
//distro is not set, use just the language as suffix if present
if out.GetService().GetLanguage().GetName() != "" {
out.Agent.Name = fmt.Sprintf("%s/%s", out.Agent.Name, out.GetService().GetLanguage().GetName())
}
}

if out.GetService().GetLanguage().GetName() == "" {
if out.Service == nil {
out.Service = modelpb.ServiceFromVTPool()
}
Expand Down
46 changes: 46 additions & 0 deletions input/otlp/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,52 @@ func TestResourceConventions(t *testing.T) {
},
},
},
"agent_distro": {
attrs: map[string]interface{}{
"telemetry.sdk.name": "sdk_name",
"telemetry.sdk.version": "sdk_version",
"telemetry.sdk.language": "language_name",
"telemetry.distro.name": "distro_name",
"telemetry.distro.version": "distro_version",
},
expected: &modelpb.APMEvent{
Agent: &modelpb.Agent{Name: "sdk_name/language_name/distro_name", Version: "distro_version"},
Service: &modelpb.Service{
Name: "unknown",
Language: &modelpb.Language{Name: "language_name"},
},
},
},
"agent_distro_no_language": {
attrs: map[string]interface{}{
"telemetry.sdk.name": "sdk_name",
"telemetry.sdk.version": "sdk_version",
"telemetry.distro.name": "distro_name",
"telemetry.distro.version": "distro_version",
},
expected: &modelpb.APMEvent{
Agent: &modelpb.Agent{Name: "sdk_name/unknown/distro_name", Version: "distro_version"},
Service: &modelpb.Service{
Name: "unknown",
Language: &modelpb.Language{Name: "unknown"},
},
},
},
"agent_distro_no_version": {
attrs: map[string]interface{}{
"telemetry.sdk.name": "sdk_name",
"telemetry.sdk.version": "sdk_version",
"telemetry.sdk.language": "language_name",
"telemetry.distro.name": "distro_name",
},
expected: &modelpb.APMEvent{
Agent: &modelpb.Agent{Name: "sdk_name/language_name/distro_name", Version: "unknown"},
Service: &modelpb.Service{
Name: "unknown",
Language: &modelpb.Language{Name: "language_name"},
},
},
},
"runtime": {
attrs: map[string]interface{}{
"process.runtime.name": "runtime_name",
Expand Down

0 comments on commit 0e072ce

Please sign in to comment.