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(instrumentor): thread safe copy of default sdks map #1708

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Changes from all commits
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
19 changes: 18 additions & 1 deletion instrumentor/sdks/sdks.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ func SetDefaultSDKs(ctx context.Context) error {
return nil
}

func copyOtelSdkMap(m map[common.ProgrammingLanguage]common.OtelSdk) map[common.ProgrammingLanguage]common.OtelSdk {
// Create a new map with the same capacity as the original
newMap := make(map[common.ProgrammingLanguage]common.OtelSdk, len(m))

// Copy each key-value pair to the new map
for key, value := range m {
newMap[key] = common.OtelSdk{
SdkType: value.SdkType,
SdkTier: value.SdkTier,
}
}

return newMap
}

func GetDefaultSDKs() map[common.ProgrammingLanguage]common.OtelSdk {
return defaultOtelSdkPerLanguage
// return a copy of the map, so it can be modified without affecting the original
// and if used by multiple goroutines, it will be safe to write to the instance returned
return copyOtelSdkMap(defaultOtelSdkPerLanguage)
}
Loading