Skip to content

Commit acdfb47

Browse files
dloucasfxatoulme
authored andcommitted
[extension/headerssetter] Change DefaultValue to use configopaque.String type (open-telemetry#39144)
#### Description Change `DefaultValue` to `opaque.String` type #### Link to tracking issue Fixes open-telemetry#39127 Signed-off-by: Dani Louca <[email protected]> Co-authored-by: Antoine Toulme <[email protected]>
1 parent c6329c3 commit acdfb47

File tree

7 files changed

+49
-12
lines changed

7 files changed

+49
-12
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: extension/headerssetter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Change `DefaultValue` to use `configopaque.String` type.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [39127]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user, api]

extension/headerssetterextension/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package headerssetterextension // import "github.com/open-telemetry/opentelemetr
55

66
import (
77
"fmt"
8+
9+
"go.opentelemetry.io/collector/config/configopaque"
810
)
911

1012
var (
@@ -19,12 +21,12 @@ type Config struct {
1921
}
2022

2123
type HeaderConfig struct {
22-
Action ActionValue `mapstructure:"action"`
23-
Key *string `mapstructure:"key"`
24-
Value *string `mapstructure:"value"`
25-
FromContext *string `mapstructure:"from_context"`
26-
FromAttribute *string `mapstructure:"from_attribute"`
27-
DefaultValue *string `mapstructure:"default_value"`
24+
Action ActionValue `mapstructure:"action"`
25+
Key *string `mapstructure:"key"`
26+
Value *string `mapstructure:"value"`
27+
FromContext *string `mapstructure:"from_context"`
28+
FromAttribute *string `mapstructure:"from_attribute"`
29+
DefaultValue *configopaque.String `mapstructure:"default_value"`
2830
}
2931

3032
// ActionValue is the enum to capture the four types of actions to perform on a header

extension/headerssetterextension/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestLoadConfig(t *testing.T) {
4242
Key: stringp("X-Scope-OrgID"),
4343
Action: INSERT,
4444
FromContext: stringp("tenant_id"),
45-
DefaultValue: stringp("some_id"),
45+
DefaultValue: opaquep("some_id"),
4646
Value: nil,
4747
},
4848
{
@@ -163,7 +163,7 @@ func TestValidateConfig(t *testing.T) {
163163
Key: stringp("name"),
164164
Action: INSERT,
165165
FromContext: stringp("from context"),
166-
DefaultValue: stringp("default"),
166+
DefaultValue: opaquep("default"),
167167
},
168168
},
169169
nil,

extension/headerssetterextension/extension.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func newHeadersSetterExtension(cfg *Config, logger *zap.Logger) (*headerSetterEx
6666
case header.FromAttribute != nil:
6767
defaultValue := ""
6868
if header.DefaultValue != nil {
69-
defaultValue = *header.DefaultValue
69+
defaultValue = string(*header.DefaultValue)
7070
}
7171
s = &source.AttributeSource{
7272
Key: *header.FromAttribute,
@@ -75,7 +75,7 @@ func newHeadersSetterExtension(cfg *Config, logger *zap.Logger) (*headerSetterEx
7575
case header.FromContext != nil:
7676
defaultValue := ""
7777
if header.DefaultValue != nil {
78-
defaultValue = *header.DefaultValue
78+
defaultValue = string(*header.DefaultValue)
7979
}
8080
s = &source.ContextSource{
8181
Key: *header.FromContext,

extension/headerssetterextension/extension_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/stretchr/testify/assert"
1212
"go.opentelemetry.io/collector/client"
13+
"go.opentelemetry.io/collector/config/configopaque"
1314
)
1415

1516
type mockRoundTripper struct{}
@@ -225,7 +226,7 @@ var (
225226
Key: &header,
226227
Action: INSERT,
227228
FromContext: stringp("tenant"),
228-
DefaultValue: stringp("default_tenant"),
229+
DefaultValue: opaquep("default_tenant"),
229230
},
230231
},
231232
},
@@ -243,7 +244,7 @@ var (
243244
Key: &header,
244245
Action: INSERT,
245246
FromContext: stringp("tenant"),
246-
DefaultValue: stringp("default_tenant"),
247+
DefaultValue: opaquep("default_tenant"),
247248
},
248249
},
249250
},
@@ -260,3 +261,7 @@ var (
260261
func stringp(str string) *string {
261262
return &str
262263
}
264+
265+
func opaquep(stro configopaque.String) *configopaque.String {
266+
return &stro
267+
}

extension/headerssetterextension/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
go.opentelemetry.io/collector/client v1.29.1-0.20250402200755-cb5c3f4fb9dc
88
go.opentelemetry.io/collector/component v1.29.1-0.20250402200755-cb5c3f4fb9dc
99
go.opentelemetry.io/collector/component/componenttest v0.123.1-0.20250402200755-cb5c3f4fb9dc
10+
go.opentelemetry.io/collector/config/configopaque v1.29.1-0.20250402200755-cb5c3f4fb9dc
1011
go.opentelemetry.io/collector/confmap v1.29.1-0.20250402200755-cb5c3f4fb9dc
1112
go.opentelemetry.io/collector/confmap/xconfmap v0.123.1-0.20250402200755-cb5c3f4fb9dc
1213
go.opentelemetry.io/collector/extension v1.29.1-0.20250402200755-cb5c3f4fb9dc

extension/headerssetterextension/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)