Skip to content

Commit

Permalink
hack(profiler): filter nil options on the shim
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed Nov 25, 2024
1 parent a5052df commit 7e63654
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ const customProfileLabelLimit = 10
// It may return an error if an API key is not provided by means of the
// WithAPIKey option, or if a hostname is not found.
func Start(opts ...Option) error {
return v2.Start(opts...)
// HACK: quick fix for removing any nil options without releasing a new v2 version
var filteredOpts []Option
for _, opt := range opts {
if opt != nil {
filteredOpts = append(filteredOpts, opt)
}
}
return v2.Start(filteredOpts...)
}

// Stop cancels any ongoing profiling or upload operations and returns after
Expand Down
9 changes: 9 additions & 0 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,12 @@ func TestMetricsProfileStopEarlyNoLog(t *testing.T) {
}
}
}

func TestFilterNilOptionsOnStart(t *testing.T) {
// Test that nil options are filtered out when calling Start
// We set a nil option, because WithAPIKey was deprecated in v2, and
// we set also on purpose an option that will generate an error, as
// WithUploadTimeout(0) is not allowed.
err := Start(WithAPIKey("foo"), WithUploadTimeout(0))
require.Error(t, err)
}

0 comments on commit 7e63654

Please sign in to comment.