Skip to content

Commit

Permalink
apm: populate System.Container in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Nov 26, 2018
1 parent e466152 commit edbd49b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/require"

"go.elastic.co/apm"
"go.elastic.co/apm/internal/apmhostutil"
"go.elastic.co/apm/transport"
"go.elastic.co/apm/transport/transporttest"
)
Expand Down Expand Up @@ -352,6 +353,24 @@ func TestTracerBodyUnread(t *testing.T) {
tracer.Flush(nil)
}

func TestTracerMetadata(t *testing.T) {
tracer, recorder := transporttest.NewRecorderTracer()
defer tracer.Close()

tracer.StartTransaction("name", "type").End()
tracer.Flush(nil)

// TODO(axw) check other metadata
system, _, _ := recorder.Metadata()
containerID, err := apmhostutil.ContainerID()
if err != nil {
assert.Nil(t, system.Container)
} else {
require.NotNil(t, system.Container)
assert.Equal(t, containerID, system.Container.ID)
}
}

type blockedTransport struct {
transport.Transport
unblocked chan struct{}
Expand Down
6 changes: 6 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/pkg/errors"

"go.elastic.co/apm/internal/apmhostutil"
"go.elastic.co/apm/internal/apmstrings"
"go.elastic.co/apm/model"
)
Expand Down Expand Up @@ -74,6 +75,11 @@ func getLocalSystem() model.System {
}
}
system.Hostname = truncateString(system.Hostname)
if containerID, err := apmhostutil.ContainerID(); err == nil {
system.Container = &model.Container{
ID: containerID,
}
}
return system
}

Expand Down

0 comments on commit edbd49b

Please sign in to comment.