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 c4750aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Stop pooling Transaction/Span/Error, introduce internal pooled objects (#319)
- Enable metrics collection with default interval of 30s (#322)
- `ELASTIC_APM_SERVER_CERT` enables server certificate pinning (#325)
- Add Docker container ID to metadata (#330)

## [v1.0.0](https://github.com/elastic/apm-agent-go/releases/tag/v1.0.0)

Expand Down
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 c4750aa

Please sign in to comment.