fix: Test flake for DataDog agent logs (#1026)

Sometimes the DataDog agent would fail to connect and
angrily log using the standard lib logger. This would
fail tests. See:

https://github.com/coder/coder/runs/6038192436?check_suite_focus=true
This commit is contained in:
Kyle Carberry 2022-04-18 12:37:01 -05:00 committed by GitHub
parent 1df750bf1a
commit d98b7ec469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -64,8 +64,11 @@ func start() *cobra.Command {
root := &cobra.Command{
Use: "start",
RunE: func(cmd *cobra.Command, args []string) error {
logger := slog.Make(sloghuman.Sink(os.Stderr))
if traceDatadog {
tracer.Start()
tracer.Start(tracer.WithLogStartup(false), tracer.WithLogger(&datadogLogger{
logger: logger.Named("datadog"),
}))
defer tracer.Stop()
}
@ -153,7 +156,6 @@ func start() *cobra.Command {
return xerrors.Errorf("parse ssh keygen algorithm %s: %w", sshKeygenAlgorithmRaw, err)
}
logger := slog.Make(sloghuman.Sink(os.Stderr))
options := &coderd.Options{
AccessURL: accessURLParsed,
Logger: logger.Named("coderd"),
@ -534,3 +536,11 @@ func configureTLS(listener net.Listener, tlsMinVersion, tlsClientAuth, tlsCertFi
return tls.NewListener(listener, tlsConfig), nil
}
type datadogLogger struct {
logger slog.Logger
}
func (d *datadogLogger) Log(msg string) {
d.logger.Debug(context.Background(), msg)
}