From 443fb349c021a72beb68169608da93acd711069e Mon Sep 17 00:00:00 2001 From: mackjmr Date: Thu, 3 Oct 2024 17:26:49 +0200 Subject: [PATCH 1/2] Add coding guideline for optional fields. Specify to use pointers to represent optional fields. This is a follow up to: https://github.com/open-telemetry/opentelemetry-collector/issues/9478. --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f671ee84ef5..7dc1ba16f43 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -294,6 +294,10 @@ To guarantee backward-compatible behavior, all configuration packages should sup Users should always initialize the config struct with this function and overwrite anything as needed. +### Optional Fields + +Use pointers to represent optional fields in configuration to distinguish between unset values and zero values. + ### Startup Error Handling Verify configuration during startup and fail fast if the configuration is invalid. From 63028be1352371876dcfce09bcd6a06c4d4650db Mon Sep 17 00:00:00 2001 From: mackjmr Date: Thu, 3 Oct 2024 17:41:58 +0200 Subject: [PATCH 2/2] feedback --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7dc1ba16f43..aacac0b3bd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -296,7 +296,7 @@ Users should always initialize the config struct with this function and overwrit ### Optional Fields -Use pointers to represent optional fields in configuration to distinguish between unset values and zero values. +Config fields should use the normal type and rely on zero values. In cases where it is necessary to distinguish between unset values and zero values, use a pointer to the type. ### Startup Error Handling