fix: quote attribute/resource_attribute values in bundled-config templates#338
Merged
sfc-gh-zeningchen merged 3 commits intoJun 1, 2026
Merged
Conversation
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
| {{- range $key, $value := .Attributes }} | ||
| - key: {{ $key }} | ||
| value: {{ $value }} | ||
| value: {{ printf "%q" $value }} |
Collaborator
There was a problem hiding this comment.
Nice find! Can this use the toYaml template function instead of printf? I don't know if %q is guaranteed to match the yaml format.
Collaborator
Author
There was a problem hiding this comment.
thanks, that's a good point! I just updated it to use toYaml
9d7f23f to
d7c6924
Compare
…lates
The templates that render the operator's `attributes:` and `resource_attributes:`
config blocks into the bundled otelcol `attributes`/`resource` processor configs
emitted unquoted YAML scalars:
- key: {{ $key }}
value: {{ $value }} # bare scalar — string typing lost
When otelcol then loaded the rendered config, its YAML parser interpreted any
value that happened to look like a YAML 1.1 typed scalar (octal/decimal digits,
booleans, dates, null, hex) as that type. The resourceprocessor.Action.Value
field is `interface{}`, so the typed value was injected onto every span,
metric, and log going through the affected pipelines.
Concrete cases observed during validation (OB-60193):
- service.version="060520262036" -> int64 6,530,622,494 (octal)
- service.version="060520261956" -> int64 60,520,261,956 (decimal,
leading zero dropped)
- team.name="no" -> bool false (the YAML "Norway problem")
- service.namespace="1.0" -> float64 1
- any value with `:` `#` `[` `,` etc. in flow-syntax position -> parse breaks
The fix routes each value through the existing `toYaml` template helper
(internal/utils/templatefuncs.go), which marshals through goccy/go-yaml and
returns a canonical YAML scalar — guaranteed to be a valid scalar by
construction, with proper handling of values that contain quotes, newlines,
or other characters that need escaping.
Snapshot test snap1 was extended with regression fixtures covering the
distinct coercion classes that still fire under YAML 1.2 (otelcol's confmap
loader uses gopkg.in/yaml.v3, which dropped the YAML 1.1 yes/no/on/off bool
aliases — so the Norway-problem class observed in the bug report no longer
manifests through this loader and was not added as a test case):
attributes:
bool-attr: "true" -> bool true (without fix)
digits-attr: "12345" -> int64 12345 (without fix)
resource_attributes:
service.namespace: "1.0" -> float64 1 (without fix)
service.version: "060520262300" -> int64 6530622656 (octal, without fix)
The four snap1 output files (linux/macos/windows/docker) now show these
values quoted; reverting just the template change makes each one diff back
to the unquoted, type-coerced form.
Affected pipelines (anything using `resource/observe_global_resource_attributes`
or `attributes/observe_global_attributes`):
- traces/metrics/logs forward
- host/process metrics, host logs
- R.E.D metrics
- self-monitoring
- fleet heartbeat
The bug surfaced during validation of 4 Java Spring Boot messaging apps where
`sample-app-validator` sets a digit-only timestamp service.version. With this
fix, Tracing/Deployment indexing works correctly for all-digit version strings.
Tested:
- `go test ./internal/...` — all green
- `Test_RenderOtelConfig` — 14 snapshot tests pass
- Reverted just the template (kept expanded snap1 inputs) — each of the
four added cases produces the expected coerced-value diff, confirming
the regression coverage is real.
- `observe-agent config` against /etc/observe-agent/observe-agent.yaml with
digit-only service.version — rendered output now contains
`value: "060520262300"`
d7c6924 to
424d183
Compare
obs-gh-abhishekrao
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The bundled-config templates that render the operator's
attributes:andresource_attributes:blocks into the otelcolattributes/resourceprocessor configs emitted unquoted YAML scalars:When otelcol then loaded the rendered config, its YAML parser interpreted any value that happened to look like a typed scalar as that type.
resourceprocessor.Action.Valueisinterface{}, so the typed value was stamped onto every span, metric, and log going through the affected pipelines.The fix routes each value through the existing
toYamltemplate helper (internal/utils/templatefuncs.go), which marshals throughgoccy/go-yamland returns a canonical YAML scalar — guaranteed to be a valid scalar by construction, with proper handling of values that contain quotes, newlines, or other characters that need escaping.Concrete cases observed (OB-60193)
service.version: "060520262036"int64 6,530,622,494(octal)"060520262036"✓service.version: "060520261956"int64 60,520,261,956(decimal, leading 0 stripped)"060520261956"✓team.name: "no"bool false(YAML 1.1 "Norway problem")"no"✓service.namespace: "1.0"float64 1"1.0"✓:#[]{},Affected pipelines
Anything using
resource/observe_global_resource_attributesorattributes/observe_global_attributes:forward.yaml.tmpl)So the same misrendered attribute lands wrong on every signal — not just one dataset.
Origin
Discovered during validation of 4 Java Spring Boot messaging apps where
sample-app-validatorsets a digit-only timestampservice.version. The empty Tracing/Deployment dataset led upstream to this template. See OB-60193 for the full investigation, including the Python SDK reproduction that isolated the bug to the agent (Observe backend correctly preserves strings that arrive intact on the wire).Test plan
go test ./internal/... ./components/...— all packages PASSTest_RenderOtelConfig— 14/14 snapshot tests PASSExtended
snap1-full-agent-config.yamlwith regression fixtures covering each coercion class still active under YAML 1.2 (otelcol'sconfmaploader usesgopkg.in/yaml.v3, which dropped the YAML 1.1yes/no/on/offboolean aliases — so the Norway-problem case from the bug report no longer manifests through this loader and was intentionally omitted as a test case):bool-attr: "true"value: true(bool)value: "true"✓digits-attr: "12345"value: 12345(int64)value: "12345"✓service.namespace: "1.0"value: 1(float→int)value: "1.0"✓service.version: "060520262300"value: 6530622656(octal int64)value: "060520262300"✓Verified each of the four added cases is regression-catching: with the inputs in place, reverting just the template change produces a diff on every line above.
observe-agent configagainst/etc/observe-agent/observe-agent.yamlwith digit-onlyservice.version— rendered output now containsvalue: "060520262300"(verified manually before this PR).