From 4ec201c4b2b695f86e392a4e9e2c95380be09032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Mon, 26 Jan 2026 19:31:41 +0000 Subject: [PATCH 1/9] added toStringMapRaw method --- confmap/internal/conf.go | 4 ++++ confmap/internal/e2e/expand_test.go | 16 ++++++++++++++++ confmap/xconfmap/confmap.go | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 confmap/xconfmap/confmap.go diff --git a/confmap/internal/conf.go b/confmap/internal/conf.go index 1760cdd425c..800794aae83 100644 --- a/confmap/internal/conf.go +++ b/confmap/internal/conf.go @@ -182,6 +182,10 @@ func (l *Conf) ToStringMap() map[string]any { return sanitize(l.toStringMapWithExpand()).(map[string]any) } +func ToStringMapRaw(conf *Conf) map[string]any { + return conf.toStringMapWithExpand() +} + func (l *Conf) unsanitizedGet(key string) any { return l.k.Get(key) } diff --git a/confmap/internal/e2e/expand_test.go b/confmap/internal/e2e/expand_test.go index 3e1cbf86fea..49ea9cf04e8 100644 --- a/confmap/internal/e2e/expand_test.go +++ b/confmap/internal/e2e/expand_test.go @@ -12,8 +12,10 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/confmap/internal" "go.opentelemetry.io/collector/confmap/provider/envprovider" "go.opentelemetry.io/collector/confmap/provider/fileprovider" + "go.opentelemetry.io/collector/confmap/xconfmap" ) func Test_EscapedEnvVars_NoDefaultScheme(t *testing.T) { @@ -111,3 +113,17 @@ func Test_EscapedEnvVars_DefaultScheme(t *testing.T) { m := cfgMap.ToStringMap() assert.Equal(t, expectedMap, m) } + +func Test_RawConfMap(t *testing.T) { + data := map[string]any{ + "value": internal.ExpandedValue{ + Value: 8080, + Original: "8080", + }, + } + conf := confmap.NewFromStringMap(data) + + rawData := xconfmap.ToStringMapRaw(conf) + _, isPresentAndExpandedValue := rawData["value"].(internal.ExpandedValue) + require.True(t, isPresentAndExpandedValue) +} diff --git a/confmap/xconfmap/confmap.go b/confmap/xconfmap/confmap.go new file mode 100644 index 00000000000..e3b959c9a7e --- /dev/null +++ b/confmap/xconfmap/confmap.go @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package xconfmap // import "go.opentelemetry.io/collector/confmap/xconfmap" + +import ( + "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/confmap/internal" +) + +// ToStringMapRaw returns the raw configuration map without sanitization. +// This is an experimental API and may change or be removed in future versions. +// +// Unlike confmap.Conf.ToStringMap(), this function does not sanitize the map +// by removing expandedValue references. This allows for configmap manipulation +// without destroying internal types. +func ToStringMapRaw(conf *confmap.Conf) map[string]any { + return internal.ToStringMapRaw(conf) +} From 19721cdbd5671813d83be243472493d7b59282c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Mon, 26 Jan 2026 19:37:08 +0000 Subject: [PATCH 2/9] added changelog --- .chloggen/add-tostringmapraw-xconfmap.yaml | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/add-tostringmapraw-xconfmap.yaml diff --git a/.chloggen/add-tostringmapraw-xconfmap.yaml b/.chloggen/add-tostringmapraw-xconfmap.yaml new file mode 100644 index 00000000000..65376692267 --- /dev/null +++ b/.chloggen/add-tostringmapraw-xconfmap.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp) +component: pkg/confmap + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: added experimental method to decode confmap into a string map without losing internal types + +# One or more tracking issues or pull requests related to the change +issues: [14480] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From 586dc288cc48cb7ea2174e7c396b329b9115399d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Mon, 26 Jan 2026 19:41:34 +0000 Subject: [PATCH 3/9] gotidy --- confmap/internal/e2e/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/confmap/internal/e2e/go.mod b/confmap/internal/e2e/go.mod index 8a2536aa0e7..f00949b0d13 100644 --- a/confmap/internal/e2e/go.mod +++ b/confmap/internal/e2e/go.mod @@ -8,6 +8,7 @@ require ( go.opentelemetry.io/collector/confmap v1.51.0 go.opentelemetry.io/collector/confmap/provider/envprovider v1.51.0 go.opentelemetry.io/collector/confmap/provider/fileprovider v1.51.0 + go.opentelemetry.io/collector/confmap/xconfmap v0.145.0 go.opentelemetry.io/collector/featuregate v1.51.0 ) @@ -22,7 +23,6 @@ require ( github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/collector/confmap/xconfmap v0.145.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.1 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect From ab799bbf758ff36ff196ad2804fc34e40dd4bb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Thu, 29 Jan 2026 17:48:00 +0100 Subject: [PATCH 4/9] Apply suggestions Co-authored-by: Pablo Baeyens --- .chloggen/add-tostringmapraw-xconfmap.yaml | 3 ++- confmap/xconfmap/confmap.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.chloggen/add-tostringmapraw-xconfmap.yaml b/.chloggen/add-tostringmapraw-xconfmap.yaml index 65376692267..6ea35b1404a 100644 --- a/.chloggen/add-tostringmapraw-xconfmap.yaml +++ b/.chloggen/add-tostringmapraw-xconfmap.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: pkg/confmap # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: added experimental method to decode confmap into a string map without losing internal types +note: added experimental method to decode `confmap.Conf` into a string map without losing internal types # One or more tracking issues or pull requests related to the change issues: [14480] @@ -16,6 +16,7 @@ issues: [14480] # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. subtext: + | This method exposes the internal structure of a `confmap.Conf` which may change at any time without prior notice # Optional: The change log or logs in which this entry should be included. # e.g. '[user]' or '[user, api]' diff --git a/confmap/xconfmap/confmap.go b/confmap/xconfmap/confmap.go index e3b959c9a7e..635d832c3ac 100644 --- a/confmap/xconfmap/confmap.go +++ b/confmap/xconfmap/confmap.go @@ -10,6 +10,7 @@ import ( // ToStringMapRaw returns the raw configuration map without sanitization. // This is an experimental API and may change or be removed in future versions. +// The returned map may change at any time without prior notice. // // Unlike confmap.Conf.ToStringMap(), this function does not sanitize the map // by removing expandedValue references. This allows for configmap manipulation From 690ee21c134e51ba11592340c8809064e0341cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Thu, 29 Jan 2026 16:51:44 +0000 Subject: [PATCH 5/9] add ExpandedValue alias type --- confmap/xconfmap/confmap.go | 1 + 1 file changed, 1 insertion(+) diff --git a/confmap/xconfmap/confmap.go b/confmap/xconfmap/confmap.go index 635d832c3ac..c655553f4cc 100644 --- a/confmap/xconfmap/confmap.go +++ b/confmap/xconfmap/confmap.go @@ -8,6 +8,7 @@ import ( "go.opentelemetry.io/collector/confmap/internal" ) +type ExpandedValue = internal.ExpandedValue // ToStringMapRaw returns the raw configuration map without sanitization. // This is an experimental API and may change or be removed in future versions. // The returned map may change at any time without prior notice. From be88eb8f2d314b8906770592fe06080975fb4baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Thu, 29 Jan 2026 17:16:31 +0000 Subject: [PATCH 6/9] fixed changelog format error --- .chloggen/add-tostringmapraw-xconfmap.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.chloggen/add-tostringmapraw-xconfmap.yaml b/.chloggen/add-tostringmapraw-xconfmap.yaml index 6ea35b1404a..db2067ca878 100644 --- a/.chloggen/add-tostringmapraw-xconfmap.yaml +++ b/.chloggen/add-tostringmapraw-xconfmap.yaml @@ -15,8 +15,8 @@ issues: [14480] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: - | This method exposes the internal structure of a `confmap.Conf` which may change at any time without prior notice +subtext: | + This method exposes the internal structure of a `confmap.Conf` which may change at any time without prior notice # Optional: The change log or logs in which this entry should be included. # e.g. '[user]' or '[user, api]' From 007542d0b5e7ff835a2870047017e5123a9745cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Thu, 29 Jan 2026 17:16:37 +0000 Subject: [PATCH 7/9] lint --- confmap/xconfmap/confmap.go | 1 + 1 file changed, 1 insertion(+) diff --git a/confmap/xconfmap/confmap.go b/confmap/xconfmap/confmap.go index c655553f4cc..e11efd1b4ef 100644 --- a/confmap/xconfmap/confmap.go +++ b/confmap/xconfmap/confmap.go @@ -9,6 +9,7 @@ import ( ) type ExpandedValue = internal.ExpandedValue + // ToStringMapRaw returns the raw configuration map without sanitization. // This is an experimental API and may change or be removed in future versions. // The returned map may change at any time without prior notice. From f755e91f2bed6b187b1ab88af72f1af2fbab93d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Wed, 4 Feb 2026 16:12:00 +0100 Subject: [PATCH 8/9] Apply suggestions Co-authored-by: Pablo Baeyens --- .chloggen/add-tostringmapraw-xconfmap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/add-tostringmapraw-xconfmap.yaml b/.chloggen/add-tostringmapraw-xconfmap.yaml index db2067ca878..31c2a5d3fea 100644 --- a/.chloggen/add-tostringmapraw-xconfmap.yaml +++ b/.chloggen/add-tostringmapraw-xconfmap.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: pkg/confmap # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: added experimental method to decode `confmap.Conf` into a string map without losing internal types +note: Add experimental `ToStringMapRaw` function to decode `confmap.Conf` into a string map without losing internal types # One or more tracking issues or pull requests related to the change issues: [14480] From 5a03f60265df495628f84860b5ff79e9b17968ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20de=20Magalhaes?= Date: Wed, 4 Feb 2026 15:13:53 +0000 Subject: [PATCH 9/9] added godoc above ExpandedValue type forwarding --- confmap/xconfmap/confmap.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/confmap/xconfmap/confmap.go b/confmap/xconfmap/confmap.go index e11efd1b4ef..ab061c8d7fd 100644 --- a/confmap/xconfmap/confmap.go +++ b/confmap/xconfmap/confmap.go @@ -8,6 +8,11 @@ import ( "go.opentelemetry.io/collector/confmap/internal" ) +// ExpandedValue represents a configuration value that has been expanded from a template +// (e.g., environment variable substitution). It contains both the parsed value and the +// original string representation. +// +// This type is exposed to allow working with configuration values returned by ToStringMapRaw. type ExpandedValue = internal.ExpandedValue // ToStringMapRaw returns the raw configuration map without sanitization.