Skip to content

[receiver/azurefunctions] fix config round-trip by using pointer types for optional IDs - #47606

Closed
alliasgher wants to merge 2 commits into
open-telemetry:mainfrom
alliasgher:fix-azurefunctions-config-roundtrip
Closed

[receiver/azurefunctions] fix config round-trip by using pointer types for optional IDs#47606
alliasgher wants to merge 2 commits into
open-telemetry:mainfrom
alliasgher:fix-azurefunctions-config-roundtrip

Conversation

@alliasgher

Copy link
Copy Markdown
Contributor

Description

Fixes #47039.

component.ID marshals to an empty string "" when it holds the zero value. Unmarshaling that empty string calls component.ID.UnmarshalText(""), which returns "id must not be empty". This causes the default config to fail a YAML marshal → unmarshal round-trip (as surfaced by CheckConfigStruct and the round-trip validation work in open-telemetry/opentelemetry-collector#14599).

The two affected fields (Auth and Logs.Encoding) are optional — neither is required in the default config:

Field Required?
auth No — absent means no auth
logs.encoding Yes — but only when the receiver is actually used

Fix

Change both fields from component.ID (value type) to *component.ID (pointer type). A nil pointer is omitted from marshaled YAML and deserialized back to nil, so the default config round-trips cleanly. The Validate() method now compares against nil instead of the zero struct value.

Before

# marshaled default config
auth: ""        # ← UnmarshalText("") fails: "id must not be empty"
logs:
  encoding: ""  # ← same

After

# marshaled default config
{}   # ← or just the fields that are set

Link to tracking Issue

Fixes #47039

Testing

All existing tests pass (go test ./receiver/azurefunctionsreceiver/...). The test fixtures for Auth and Logs.Encoding are updated to use *component.ID pointers.

The check to enable the kafka.cluster.alias resource attribute was in
createDefaultConfig(), which runs before user config is applied. At
that point ClusterAlias is always the zero value, so the attribute
was never enabled even when cluster_alias was set by the user.

Move the check to createMetricsReceiver(), where the user-supplied
config is available.

Fixes open-telemetry#47573

Signed-off-by: alliasgher <alliasgher123@gmail.com>
…s for optional IDs

component.ID marshals as an empty string when zero-valued. Unmarshaling
that empty string calls component.ID.UnmarshalText(""), which returns an
error because component type must not be empty. This makes the default
config fail a YAML marshal/unmarshal round-trip.

Change Auth and Logs.Encoding to pointer types (*component.ID). A nil
pointer is omitted from the marshaled output and is represented as absent
in YAML, so the default config (both pointers nil) round-trips cleanly.
The Validate check is updated to compare against nil instead of the zero
struct value.

Fixes open-telemetry#47039

Signed-off-by: alliasgher <alliasgher123@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!


func createDefaultConfig() component.Config {
config := &Config{
return &Config{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this changes does not belong to this PR

@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelog does not belong to this PR

@alliasgher

Copy link
Copy Markdown
Contributor Author

Reopening with a clean branch that only contains the azurefunctions fix — the previous branch accidentally included unrelated kafkametrics changes from the parent branch. Sorry about the noise!

@alliasgher alliasgher closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[receiver/azurefunctions] Default config fails round-trip validation

3 participants