Skip to content

Commit

Permalink
Add support for providing host.id via intakeV2. (#246)
Browse files Browse the repository at this point in the history
* Add support for providing host.id via intakeV2.

* Apply suggestions from code review

Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>

* Regenerate files

---------

Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>
  • Loading branch information
JonasKunz and carsonip authored Apr 5, 2024
1 parent 06071a1 commit 007b3c8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions input/elasticapm/docs/spec/v2/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,14 @@
],
"maxLength": 1024
},
"host_id": {
"description": "The OpenTelemetry semantic conventions compliant \"host.id\" attribute, if available.",
"type": [
"null",
"string"
],
"maxLength": 1024
},
"hostname": {
"description": "Deprecated: Use ConfiguredHostname and DetectedHostname instead. DeprecatedHostname is the host name of the system the service is running on. It does not distinguish between configured and detected hostname and therefore is deprecated and only used if no other hostname information is available.",
"type": [
Expand Down
6 changes: 6 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,12 @@ func mapToMetadataModel(from *metadata, out *modelpb.APMEvent) {
}
out.Host.Hostname = from.System.DetectedHostname.Val
}
if from.System.HostID.IsSet() {
if out.Host == nil {
out.Host = modelpb.HostFromVTPool()
}
out.Host.Id = from.System.HostID.Val
}
if !from.System.ConfiguredHostname.IsSet() && !from.System.DetectedHostname.IsSet() &&
from.System.DeprecatedHostname.IsSet() {
if out.Host == nil {
Expand Down
2 changes: 2 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ func TestDecodeMapToMetadataModel(t *testing.T) {
input.System.ConfiguredHostname.Set("configured-host")
input.System.DetectedHostname.Set("detected-host")
input.System.DeprecatedHostname.Set("deprecated-host")
input.System.HostID.Set("host-id")
mapToMetadataModel(&input, &out)
assert.Equal(t, "configured-host", out.Host.Name)
assert.Equal(t, "detected-host", out.Host.Hostname)
assert.Equal(t, "host-id", out.Host.Id)
// no detected-host information
out = modelpb.APMEvent{}
input.System.DetectedHostname.Reset()
Expand Down
2 changes: 2 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ type metadataSystem struct {
Kubernetes metadataSystemKubernetes `json:"kubernetes"`
// Platform name of the system platform the monitored service is running on.
Platform nullable.String `json:"platform" validate:"maxLength=1024"`
// The OpenTelemetry semantic conventions compliant "host.id" attribute, if available.
HostID nullable.String `json:"host_id" validate:"maxLength=1024"`
}

type metadataSystemContainer struct {
Expand Down
6 changes: 5 additions & 1 deletion input/elasticapm/internal/modeldecoder/v2/model_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 007b3c8

Please sign in to comment.