Skip to content

Commit

Permalink
profiler: add WithHostname option (#1442)
Browse files Browse the repository at this point in the history
* profiler: add WithHostname option

This allows overriding the value used for the "host" tag, consistent
with the WithHostname tracer option.
  • Loading branch information
nsrip-dd committed Aug 22, 2022
1 parent 3cc2f6c commit acd5c8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions profiler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,12 @@ func WithLogStartup(enabled bool) Option {
cfg.logStartup = enabled
}
}

// WithHostname sets the hostname which will be added to uploaded profiles
// through the "host:<hostname>" tag. If no hostname is given, the hostname will
// default to the output of os.Hostname()
func WithHostname(hostname string) Option {
return func(cfg *config) {
cfg.hostname = hostname
}
}
6 changes: 6 additions & 0 deletions profiler/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ func TestOptions(t *testing.T) {
WithDeltaProfiles(false)(&cfg)
assert.Equal(t, false, cfg.deltaProfiles)
})

t.Run("WithHostname", func(t *testing.T) {
var cfg config
WithHostname("example")(&cfg)
assert.Equal(t, "example", cfg.hostname)
})
}

func TestEnvVars(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,15 @@ func TestCorrectTags(t *testing.T) {
WithService("xyz"),
WithEnv("testing"),
WithTags("foo:bar", "baz:bonk"),
WithHostname("example"),
)
defer Stop()
expected := []string{
"baz:bonk",
"env:testing",
"foo:bar",
"service:xyz",
"host:example",
}
for i := 0; i < 20; i++ {
// We check the tags we get several times to try to have a
Expand Down

0 comments on commit acd5c8b

Please sign in to comment.