Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't panic when datadog APM socket cannot be found, retry to wait for it to become available #181

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions internal/gitdb/tracing/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,25 @@ func envToStruct(env []string, into interface{}) error {
return json.Unmarshal(b, into)
}

func verifyFileExistsWithRetry(file string, retries int, delay time.Duration) bool {
for i := 0; i < retries; i++ {
if fileExists(file) {
return true
}
time.Sleep(delay)
}
return false
}

func NewTracer(originalConfig tracing.Config) (tracing.Tracing, error) {
var cfg config
if err := envToStruct(originalConfig.Env, &cfg); err != nil {
return nil, fmt.Errorf("unable to convert env to config: %w", err)
}
if !fileExists(cfg.apmFile()) {
// the datadog APM socket is mounted from the host, sometimes it is not available immediately
if !verifyFileExistsWithRetry(cfg.apmFile(), 10, 1*time.Second) {
originalConfig.Log.Info(context.Background(), "Unable to find datadog APM file", zap.String("file_name", cfg.apmFile()))
return nil, nil
return nil, fmt.Errorf("unable to find datadog APM file: %s", cfg.apmFile())
}
u := &unixRoundTripper{
file: cfg.apmFile(),
Expand Down
Loading