Add support for OTLP OpenTelemetry and resource attributes#166
Add support for OTLP OpenTelemetry and resource attributes#166schaer-bgs wants to merge 1 commit intowso2:mainfrom
Conversation
|
|
WalkthroughThis PR adds two OpenTelemetry configuration options ( Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@all-in-one/confs/instance-1/deployment.toml`:
- Around line 336-341: The Helm template uses the wrong `ne` call order causing
parse errors; update the if-condition to call `ne` with the value first (e.g.,
use `if ne .Values.wso2.apim.configurations.openTelemetry.url ""`) so the branch
that sets remote_tracer.url versus remote_tracer.hostname/remote_tracer.port
works correctly; locate the conditional around the symbols remote_tracer.url,
remote_tracer.hostname, remote_tracer.port and the template variable
.Values.wso2.apim.configurations.openTelemetry.url and change the `if` to use
`ne` as a function with its arguments in the correct order.
- Around line 344-348: Replace the incorrect Go template loop and move it inside
the enabled check: change the `for` loop over
`.Values.wso2.apim.configurations.openTelemetry.resourceAttributes` to a `range`
and ensure the whole `[[apim.open_telemetry.resource_attributes]]` block is
emitted only when `.Values.wso2.apim.configurations.openTelemetry.enabled` is
true so the `apim.open_telemetry` parent exists; also add the missing `url` and
`resourceAttributes` keys under `openTelemetry` in `all-in-one/values.yaml`
(e.g. `openTelemetry.url` and `openTelemetry.resourceAttributes: []`) so the
template has those fields to iterate over.
In `@all-in-one/confs/instance-2/deployment.toml`:
- Around line 336-348: The Helm template has invalid conditional and loop syntax
and the resource attribute block sits outside the openTelemetry feature guard;
change the if to use the ne function (e.g. {{- if ne
.Values.wso2.apim.configurations.openTelemetry.url "" }}) instead of infix
comparison, change the loop to use range (iterate
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes with {{- range
$i, $attr := ... }}), and move the [[apim.open_telemetry.resource_attributes]]
range block inside the outer openTelemetry-enabled guard so
apim.open_telemetry.resource_attributes and the remote_tracer.url/hostname/port
logic only render when openTelemetry is enabled.
In `@distributed/control-plane/confs/instance-1/deployment.toml`:
- Around line 282-294: Fix the Helm template logic: change the conditional to
use the prefix function form (if ne
.Values.wso2.apim.configurations.openTelemetry.url "") when checking
.Values.wso2.apim.configurations.openTelemetry.url; replace the "for" loop with
Helm's "range" for iterating
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes; move the
[[apim.open_telemetry.resource_attributes]] range block so it is nested inside
the openTelemetry.enabled conditional (the same block that renders
remote_tracer.url/hostname/port) to avoid orphaned TOML entries; and add url and
resourceAttributes keys to distributed/control-plane/values.yaml under
.Values.wso2.apim.configurations.openTelemetry so the template has those values
available.
In `@distributed/control-plane/confs/instance-2/deployment.toml`:
- Around line 282-294: The template has multiple Helm syntax and logic errors:
change the conditional to use the ne function (e.g., if ne
.Values.wso2.apim.configurations.openTelemetry.url "" ) when checking url,
replace the Golang "for" with Helm's "range" when iterating resourceAttributes,
and move the entire [[apim.open_telemetry.resource_attributes]] block (the range
over .Values.wso2.apim.configurations.openTelemetry.resourceAttributes that
creates name/value entries) inside the openTelemetry.enabled conditional so
resource attributes are only rendered when openTelemetry is enabled; update
references to remote_tracer.* and apim.open_telemetry.resource_attributes
accordingly.
In `@distributed/gateway/confs/deployment.toml`:
- Around line 265-277: Add the new OpenTelemetry defaults to the gateway values
so the template keys exist by default: update the distributed gateway chart's
values for openTelemetry (the openTelemetry map used by
wso2.apim.configurations.openTelemetry) to include url and resourceAttributes in
addition to enabled, name, hostname, and port; ensure openTelemetry.url is set
to an empty string and openTelemetry.resourceAttributes is an empty list so the
template branches using wso2.apim.configurations.openTelemetry.url and
wso2.apim.configurations.openTelemetry.resourceAttributes have sensible defaults
and the generated docs reflect the new options.
- Around line 265-277: The Helm template has invalid Go-template syntax and a
misplaced loop: change the if condition from "if
.Values.wso2.apim.configurations.openTelemetry.url ne \"\"" to use the ne
function as "if ne .Values.wso2.apim.configurations.openTelemetry.url \"\"" and
replace the "for $i, $attr :=" loop with "range $i, $attr :="; also ensure the
[[apim.open_telemetry.resource_attributes]] loop (references to
$attr.name/$attr.value and the resource_attributes block) is placed inside the
same openTelemetry enabled guard so resource_attributes are not emitted when
openTelemetry is disabled, and apply the same fixes for the other
deployment.toml files (distributed/control-plane, distributed/traffic-manager,
all-in-one) where the same symbols appear.
In `@distributed/traffic-manager/confs/instance-1/deployment.toml`:
- Around line 166-178: The Helm template has syntax and logic errors: change the
if test to prefix notation using ne for
.Values.wso2.apim.configurations.openTelemetry.url (e.g. {{- if ne
.Values.wso2.apim.configurations.openTelemetry.url "" }}), replace the template
"for" with "range" when iterating
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes, and move the
[[apim.open_telemetry.resource_attributes]] block (the resourceAttributes
iteration) inside the openTelemetry.enabled conditional so resource attribute
rendering only occurs when openTelemetry is enabled; also ensure the values.yaml
for distributed/traffic-manager includes the openTelemetry.url and
resourceAttributes fields referenced by remote_tracer and
apim.open_telemetry.resource_attributes.
In `@distributed/traffic-manager/confs/instance-2/deployment.toml`:
- Around line 164-176: The Helm template has syntax and logic issues: change the
if expression to use the Helm ne helper (e.g., if ne
.Values.wso2.apim.configurations.openTelemetry.url "" ) for the URL check,
replace the template `for` loop with Helm's `range` when iterating
`.Values.wso2.apim.configurations.openTelemetry.resourceAttributes`, and move
the entire resource attributes block (the
[[apim.open_telemetry.resource_attributes]] entries) and the
remote_tracer.url/hostname/port logic inside the `openTelemetry.enabled`
conditional so they only render when openTelemetry is enabled; update references
to remote_tracer.url, remote_tracer.hostname, remote_tracer.port, and the
resource attribute loop accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9a2d8267-b7bf-4c18-aeb6-e926b16c9f96
📒 Files selected for processing (11)
all-in-one/README.mdall-in-one/confs/instance-1/deployment.tomlall-in-one/confs/instance-2/deployment.tomldistributed/control-plane/README.mddistributed/control-plane/confs/instance-1/deployment.tomldistributed/control-plane/confs/instance-2/deployment.tomldistributed/gateway/README.mddistributed/gateway/confs/deployment.tomldistributed/traffic-manager/README.mddistributed/traffic-manager/confs/instance-1/deployment.tomldistributed/traffic-manager/confs/instance-2/deployment.toml
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
Use range instead of for and move inside the enabled block.
Two issues here:
- Helm/Go templates use
range, notfor— this will cause a template parsing error. - The resource attributes loop is outside the
openTelemetry.enabledconditional, which could generate[[apim.open_telemetry.resource_attributes]]entries without a parent[apim.open_telemetry]section, producing invalid TOML.
Additionally, the url and resourceAttributes fields are not defined in all-in-one/values.yaml (see Context snippet 1). These must be added for the template to work correctly.
🐛 Proposed fix
{{- if .Values.wso2.apim.configurations.openTelemetry.enabled }}
[apim.open_telemetry]
remote_tracer.enable = {{ .Values.wso2.apim.configurations.openTelemetry.enabled }}
remote_tracer.name = {{ .Values.wso2.apim.configurations.openTelemetry.name | quote }}
{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}Also add the missing fields in all-in-one/values.yaml:
openTelemetry:
enabled: false
name: ""
hostname: ""
port: ""
# -- Remote tracer URL. This should be used when name is OTLP
url: ""
# -- Open Telemetry resource attributes
resourceAttributes: []🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@all-in-one/confs/instance-1/deployment.toml` around lines 344 - 348, Replace
the incorrect Go template loop and move it inside the enabled check: change the
`for` loop over
`.Values.wso2.apim.configurations.openTelemetry.resourceAttributes` to a `range`
and ensure the whole `[[apim.open_telemetry.resource_attributes]]` block is
emitted only when `.Values.wso2.apim.configurations.openTelemetry.enabled` is
true so the `apim.open_telemetry` parent exists; also add the missing `url` and
`resourceAttributes` keys under `openTelemetry` in `all-in-one/values.yaml`
(e.g. `openTelemetry.url` and `openTelemetry.resourceAttributes: []`) so the
template has those fields to iterate over.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | ||
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | ||
| {{- else }} | ||
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | ||
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's view the actual file content around lines 336-348
cd all-in-one/confs/instance-2 && wc -l deployment.tomlRepository: wso2/helm-apim
Length of output: 77
🏁 Script executed:
# View the specific section mentioned in the review
cd all-in-one/confs/instance-2 && sed -n '330,360p' deployment.tomlRepository: wso2/helm-apim
Length of output: 1642
🏁 Script executed:
# Search for similar OpenTelemetry patterns in the codebase to understand the context
rg -A 15 "open_telemetry" all-in-one/confs/ --type toml | head -100Repository: wso2/helm-apim
Length of output: 5540
🌐 Web query:
Helm template syntax "if ne" vs "if" with comparison operators
💡 Result:
In Helm (Go text/template), if doesn’t take infix comparison operators like !=, ==, >, etc. Instead, comparisons are done with functions like eq, ne, lt, gt, le, ge (and boolean combinators and, or, not). Helm documents this explicitly: “operators … are all implemented as functions.” [1]
{{ if ... }} (no comparison)
if evaluates the truthiness of the pipeline result (e.g., false, 0, empty string, nil, empty list/map → falsey; otherwise truthy). So:
{{- if .Values.enabled -}}
...
{{- end -}}
{{ if ne ... }} (not-equal comparison)
Use ne when you want a not-equal test:
{{- if ne .Values.env "prod" -}}
...
{{- end -}}
Why ne instead of !=?
Because in Helm templates you write comparisons as function calls (ne a b), not as a != b. [1] (The Go template comparison functions are named eq, ne, lt, le, gt, ge and correspond to ==, !=, <, <=, >, >= in meaning.) [2]
Small extras that matter
eqcan compare against multiple candidates:{{ if eq .Values.tier "gold" "platinum" }}[2]- You can combine conditions with
and/orand parentheses:{{ if and (ne .A 0) (gt .B 5) }}[1]
Sources: Helm template guide [1], Go template comparison functions notes [2].
[1] (helm.sh)
[2] (tip.golang.org)
Citations:
- 1: https://helm.sh/es/docs/chart_template_guide/functions_and_pipelines
- 2: https://tip.golang.org/doc/go1.2
🌐 Web query:
Helm Go template range vs for loop syntax
💡 Result:
In Helm charts you’re writing Go text/template, which has range for iteration—there is no for loop syntax in the template language. [1][2]
range (the “for-each” loop)
Iterate lists/slices/arrays/maps:
{{- range $i, $v := .Values.items }}
# $i = index/key, $v = value
{{- end }}
Notes:
rangeblocks must be closed with{{ end }}. [1][2]- Variable assignment order in templates is
$index, $element(and for maps,$key, $value). [1]
“for i := 0; i < n; i++” (numeric loops)
Go templates don’t have a C-style for, so in Helm you typically generate a slice of integers (Sprig/Helm functions) and then range over it:
{{- range $i := until 5 }}
# $i is 0..4
{{- end }}
Helm’s until returns [0, 1, 2, 3, 4], and untilStep start stop step is the step-version. [3]
Sources: Go text/template docs for range/variables and Helm docs for until/untilStep. [1][3]
Fix Helm template syntax: invalid if condition and for loop; move attribute loop inside feature guard.
Lines contain two Helm template syntax errors. The comparison condition uses invalid infix syntax; it should be {{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}. The loop uses invalid for syntax; it should be range. Additionally, the resource_attributes loop runs outside the openTelemetry.enabled block and will render attributes even when the feature is disabled—it must move inside the outer guard.
Suggested fix
[apim.open_telemetry]
remote_tracer.enable = {{ .Values.wso2.apim.configurations.openTelemetry.enabled }}
remote_tracer.name = {{ .Values.wso2.apim.configurations.openTelemetry.name | quote }}
-{{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }}
+{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@all-in-one/confs/instance-2/deployment.toml` around lines 336 - 348, The Helm
template has invalid conditional and loop syntax and the resource attribute
block sits outside the openTelemetry feature guard; change the if to use the ne
function (e.g. {{- if ne .Values.wso2.apim.configurations.openTelemetry.url ""
}}) instead of infix comparison, change the loop to use range (iterate
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes with {{- range
$i, $attr := ... }}), and move the [[apim.open_telemetry.resource_attributes]]
range block inside the outer openTelemetry-enabled guard so
apim.open_telemetry.resource_attributes and the remote_tracer.url/hostname/port
logic only render when openTelemetry is enabled.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | ||
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | ||
| {{- else }} | ||
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | ||
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
Multiple Helm template syntax errors and logic issue.
This segment has the same issues as the all-in-one deployment template:
- Line 282:
nemust be a prefix function:{{- if ne .Values...url "" }} - Line 290: Use
rangeinstead offor - Lines 290-294: The resource attributes loop should be inside the
openTelemetry.enabledblock to avoid generating orphaned TOML entries
The url and resourceAttributes fields must also be added to distributed/control-plane/values.yaml.
🐛 Proposed fix
{{- if .Values.wso2.apim.configurations.openTelemetry.enabled }}
[apim.open_telemetry]
remote_tracer.enable = {{ .Values.wso2.apim.configurations.openTelemetry.enabled }}
remote_tracer.name = {{ .Values.wso2.apim.configurations.openTelemetry.name | quote }}
-{{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }}
+{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@distributed/control-plane/confs/instance-1/deployment.toml` around lines 282
- 294, Fix the Helm template logic: change the conditional to use the prefix
function form (if ne .Values.wso2.apim.configurations.openTelemetry.url "") when
checking .Values.wso2.apim.configurations.openTelemetry.url; replace the "for"
loop with Helm's "range" for iterating
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes; move the
[[apim.open_telemetry.resource_attributes]] range block so it is nested inside
the openTelemetry.enabled conditional (the same block that renders
remote_tracer.url/hostname/port) to avoid orphaned TOML entries; and add url and
resourceAttributes keys to distributed/control-plane/values.yaml under
.Values.wso2.apim.configurations.openTelemetry so the template has those values
available.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | ||
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | ||
| {{- else }} | ||
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | ||
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
Multiple Helm template syntax errors and logic issue.
Same issues as instance-1:
- Line 282: Use
{{- if ne .Values...url "" }} - Line 290: Use
rangeinstead offor - Lines 290-294: Move inside the
openTelemetry.enabledblock
🐛 Proposed fix
-{{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }}
+{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@distributed/control-plane/confs/instance-2/deployment.toml` around lines 282
- 294, The template has multiple Helm syntax and logic errors: change the
conditional to use the ne function (e.g., if ne
.Values.wso2.apim.configurations.openTelemetry.url "" ) when checking url,
replace the Golang "for" with Helm's "range" when iterating resourceAttributes,
and move the entire [[apim.open_telemetry.resource_attributes]] block (the range
over .Values.wso2.apim.configurations.openTelemetry.resourceAttributes that
creates name/value entries) inside the openTelemetry.enabled conditional so
resource attributes are only rendered when openTelemetry is enabled; update
references to remote_tracer.* and apim.open_telemetry.resource_attributes
accordingly.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | ||
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | ||
| {{- else }} | ||
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | ||
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
Add the new gateway defaults to distributed/gateway/values.yaml too.
This template now reads wso2.apim.configurations.openTelemetry.url and wso2.apim.configurations.openTelemetry.resourceAttributes, but distributed/gateway/values.yaml:480-488 still only defines enabled, name, hostname, and port. That leaves the gateway chart’s default values and generated docs incomplete for the new feature.
# distributed/gateway/values.yaml
openTelemetry:
enabled: false
name: ""
hostname: ""
port: ""
url: ""
resourceAttributes: []🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@distributed/gateway/confs/deployment.toml` around lines 265 - 277, Add the
new OpenTelemetry defaults to the gateway values so the template keys exist by
default: update the distributed gateway chart's values for openTelemetry (the
openTelemetry map used by wso2.apim.configurations.openTelemetry) to include url
and resourceAttributes in addition to enabled, name, hostname, and port; ensure
openTelemetry.url is set to an empty string and openTelemetry.resourceAttributes
is an empty list so the template branches using
wso2.apim.configurations.openTelemetry.url and
wso2.apim.configurations.openTelemetry.resourceAttributes have sensible defaults
and the generated docs reflect the new options.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find the same invalid Helm-template patterns elsewhere in the repo.
rg -n -C2 '\{\{[- ]*for\b' --glob '**/*.toml'
rg -n -C2 '\{\{[- ]*if\s+\.[^}]*\s+ne\s+""\s*\}\}' --glob '**/*.toml'Repository: wso2/helm-apim
Length of output: 7664
🏁 Script executed:
# Verify the exact guard structure and context around the flagged lines
cat -n distributed/gateway/confs/deployment.toml | sed -n '258,280p'Repository: wso2/helm-apim
Length of output: 1346
🌐 Web query:
Helm Go-template if ne operator syntax comparison
💡 Result:
In Helm (Go text/template), ne is a function (“not equal”), not an infix operator.
Basic not-equal check
{{- if ne .Values.env "prod" -}}
# ...
{{- end -}}
ne takes two arguments: ne <left> <right>. (helm.sh)
Combine comparisons (use parentheses because it’s function-call style)
{{- if and (ne .Values.a "x") (ne .Values.b "y") -}}
# ...
{{- end -}}
This works because and is also a template function that takes boolean expressions as arguments. (helm.sh)
Alternative form
{{- if not (eq .Values.env "prod") -}}
# ...
{{- end -}}
not negates the result of eq. (helm.sh)
Citations:
- 1: https://helm.sh/el/docs/v3/chart_template_guide/function_list?utm_source=openai
- 2: https://helm.sh/el/docs/v3/chart_template_guide/function_list?utm_source=openai
- 3: https://helm.sh/el/docs/v3/chart_template_guide/function_list?utm_source=openai
🌐 Web query:
Helm Go-template range loop syntax vs for loop
💡 Result:
Helm templates use Go’s text/template, which does not have a for loop statement. The looping construct is range (“for-each”). (helm.sh)
range (for-each) syntax in Helm/Go templates
Loop over a list (slice/array)
{{- range .Values.items }}
name: {{ . }}
{{- end }}
Inside the loop, . becomes the current element. (pkg.go.dev)
Capture index + element
{{- range $i, $v := .Values.items }}
{{ $i }} => {{ $v }}
{{- end }}
Note: in Go templates, when you declare two variables, the first is index/key and the second is element/value; with one variable, it gets the element (not the index). (pkg.go.dev)
Loop over a map (key/value)
{{- range $k, $v := .Values.labels }}
{{ $k }}: {{ $v | quote }}
{{- end }}
(Go maps iterate in undefined order.) (pkg.go.dev)
range ... else for empty collections
{{- range .Values.items }}
- {{ . }}
{{- else }}
# no items
{{- end }}
“For loop” (numeric counting) pattern in Helm
Helm typically does “counting loops” by generating a list of integers (via Sprig) and ranging over it:
{{- range $i, $_ := until 5 }}
i={{ $i }}
{{- end }}
Or step sizes:
{{- range $i, $_ := untilStep 0 10 2 }}
i={{ $i }}
{{- end }}
Citations:
- 1: https://helm.sh/zh/docs/chart_template_guide/control_structures/?utm_source=openai
- 2: https://pkg.go.dev/text/template?utm_source=openai
- 3: https://pkg.go.dev/text/template?utm_source=openai
- 4: https://pkg.go.dev/text/template?utm_source=openai
- 5: https://pkg.go.dev/text/template?utm_source=openai
- 6: https://blog.helm.sh/docs/chart_template_guide/function_list/?utm_source=openai
Fix invalid Helm/Go-template syntax in OpenTelemetry configuration blocks.
The control flow syntax is incorrect and prevents template rendering:
if .Values...url ne ""must beif ne .Values.url ""(ne is a function, not an operator)for $i, $attr :=must berange $i, $attr :=(Go templates userange, notfor)- The
resource_attributesloop (line 273) is outside theopenTelemetry.enabledguard, allowing partial configuration when telemetry is disabled
This pattern appears in all deployment.toml files (distributed/gateway, distributed/control-plane, distributed/traffic-manager, and all-in-one charts).
Suggested fix
[apim.open_telemetry]
remote_tracer.enable = {{ .Values.wso2.apim.configurations.openTelemetry.enabled }}
remote_tracer.name = {{ .Values.wso2.apim.configurations.openTelemetry.name | quote }}
-{{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }}
+{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@distributed/gateway/confs/deployment.toml` around lines 265 - 277, The Helm
template has invalid Go-template syntax and a misplaced loop: change the if
condition from "if .Values.wso2.apim.configurations.openTelemetry.url ne \"\""
to use the ne function as "if ne
.Values.wso2.apim.configurations.openTelemetry.url \"\"" and replace the "for
$i, $attr :=" loop with "range $i, $attr :="; also ensure the
[[apim.open_telemetry.resource_attributes]] loop (references to
$attr.name/$attr.value and the resource_attributes block) is placed inside the
same openTelemetry enabled guard so resource_attributes are not emitted when
openTelemetry is disabled, and apply the same fixes for the other
deployment.toml files (distributed/control-plane, distributed/traffic-manager,
all-in-one) where the same symbols appear.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | ||
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | ||
| {{- else }} | ||
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | ||
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
Multiple Helm template syntax errors and logic issue.
Same issues as other deployment templates:
- Line 166: Use
{{- if ne .Values...url "" }}(prefix notation) - Line 174: Use
rangeinstead offor - Lines 174-178: Move inside the
openTelemetry.enabledblock
Update distributed/traffic-manager/values.yaml with the missing url and resourceAttributes fields.
🐛 Proposed fix
{{- if .Values.wso2.apim.configurations.openTelemetry.enabled }}
[apim.open_telemetry]
remote_tracer.enable = {{ .Values.wso2.apim.configurations.openTelemetry.enabled }}
remote_tracer.name = {{ .Values.wso2.apim.configurations.openTelemetry.name | quote }}
-{{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }}
+{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@distributed/traffic-manager/confs/instance-1/deployment.toml` around lines
166 - 178, The Helm template has syntax and logic errors: change the if test to
prefix notation using ne for .Values.wso2.apim.configurations.openTelemetry.url
(e.g. {{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}),
replace the template "for" with "range" when iterating
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes, and move the
[[apim.open_telemetry.resource_attributes]] block (the resourceAttributes
iteration) inside the openTelemetry.enabled conditional so resource attribute
rendering only occurs when openTelemetry is enabled; also ensure the values.yaml
for distributed/traffic-manager includes the openTelemetry.url and
resourceAttributes fields referenced by remote_tracer and
apim.open_telemetry.resource_attributes.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | ||
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | ||
| {{- else }} | ||
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | ||
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | ||
| [[apim.open_telemetry.resource_attributes]] | ||
| name = {{ $attr.name | quote }} | ||
| value = {{ $attr.value | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
Multiple Helm template syntax errors and logic issue.
Same issues as instance-1:
- Line 164: Use
{{- if ne .Values...url "" }} - Line 172: Use
rangeinstead offor - Lines 172-176: Move inside the
openTelemetry.enabledblock
🐛 Proposed fix
-{{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }}
+{{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }}
remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }}
{{- else }}
remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }}
remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }}
{{- end }}
-{{- end }}
-
-{{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
+{{- range $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }}
[[apim.open_telemetry.resource_attributes]]
name = {{ $attr.name | quote }}
value = {{ $attr.value | quote }}
{{- end }}
+{{- end }}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {{- if .Values.wso2.apim.configurations.openTelemetry.url ne "" }} | |
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | |
| {{- else }} | |
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | |
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | |
| {{- end }} | |
| {{- end }} | |
| {{- for $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | |
| [[apim.open_telemetry.resource_attributes]] | |
| name = {{ $attr.name | quote }} | |
| value = {{ $attr.value | quote }} | |
| {{- end }} | |
| {{- if ne .Values.wso2.apim.configurations.openTelemetry.url "" }} | |
| remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} | |
| {{- else }} | |
| remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} | |
| remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} | |
| {{- end }} | |
| {{- range $i, $attr := .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} | |
| [[apim.open_telemetry.resource_attributes]] | |
| name = {{ $attr.name | quote }} | |
| value = {{ $attr.value | quote }} | |
| {{- end }} | |
| {{- end }} |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@distributed/traffic-manager/confs/instance-2/deployment.toml` around lines
164 - 176, The Helm template has syntax and logic issues: change the if
expression to use the Helm ne helper (e.g., if ne
.Values.wso2.apim.configurations.openTelemetry.url "" ) for the URL check,
replace the template `for` loop with Helm's `range` when iterating
`.Values.wso2.apim.configurations.openTelemetry.resourceAttributes`, and move
the entire resource attributes block (the
[[apim.open_telemetry.resource_attributes]] entries) and the
remote_tracer.url/hostname/port logic inside the `openTelemetry.enabled`
conditional so they only render when openTelemetry is enabled; update references
to remote_tracer.url, remote_tracer.hostname, remote_tracer.port, and the
resource attribute loop accordingly.
1e6e49b to
7a6a943
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (3)
distributed/traffic-manager/confs/instance-1/deployment.toml (1)
172-178:⚠️ Potential issue | 🟠 MajorResource attributes loop is still outside the
openTelemetry.enabledguard.Same issue as other deployment templates: the
{{- end }}on line 172 closes the enabled block, but theresourceAttributesloop executes unconditionally. This produces orphaned TOML entries when OpenTelemetry is disabled.🐛 Proposed fix
{{- if ne (.Values.wso2.apim.configurations.openTelemetry.url) "" }} remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} {{- else }} remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} {{- end }} -{{- end }} - -{{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} +{{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} [[apim.open_telemetry.resource_attributes]] name = {{ .name | quote }} value = {{ .value | quote }} {{- end }} +{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@distributed/traffic-manager/confs/instance-1/deployment.toml` around lines 172 - 178, The TOML resource_attributes loop (.Values.wso2.apim.configurations.openTelemetry.resourceAttributes) is being rendered even when openTelemetry.enabled is false because the {{- end }} closed the openTelemetry.enabled guard too early; move the resourceAttributes range block inside the openTelemetry.enabled conditional (i.e., ensure the {{ if .Values.wso2.apim.configurations.openTelemetry.enabled }} .. {{ end }} surrounds the [[apim.open_telemetry.resource_attributes]] range) so the loop only emits when openTelemetry is enabled.distributed/control-plane/confs/instance-1/deployment.toml (1)
288-294:⚠️ Potential issue | 🟠 MajorResource attributes loop is still outside the
openTelemetry.enabledguard.The
{{- end }}on line 288 closes theopenTelemetry.enabledblock, but theresourceAttributesloop (lines 290-294) executes unconditionally. WhenopenTelemetry.enabled=falsebutresourceAttributesis non-empty, this generates orphaned[[apim.open_telemetry.resource_attributes]]TOML entries without the parent[apim.open_telemetry]section.Move the loop inside the enabled block by swapping lines 288 and 294.
🐛 Proposed fix
{{- if ne (.Values.wso2.apim.configurations.openTelemetry.url) "" }} remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} {{- else }} remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} {{- end }} -{{- end }} - -{{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} +{{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} [[apim.open_telemetry.resource_attributes]] name = {{ .name | quote }} value = {{ .value | quote }} {{- end }} +{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@distributed/control-plane/confs/instance-1/deployment.toml` around lines 288 - 294, The resourceAttributes range is rendered outside the openTelemetry guard causing orphaned [[apim.open_telemetry.resource_attributes]] entries when openTelemetry.enabled is false; move the resourceAttributes loop inside the openTelemetry block by swapping the closing {{- end }} for the openTelemetry.enabled block with the range block so that the {{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} ... [[apim.open_telemetry.resource_attributes]] ... {{- end }} executes only when openTelemetry.enabled is true (reference openTelemetry.enabled, resourceAttributes, and apim.open_telemetry.resource_attributes).all-in-one/confs/instance-2/deployment.toml (1)
342-348:⚠️ Potential issue | 🟠 MajorResource attributes loop is still outside the
openTelemetry.enabledguard.Same issue as other deployment templates: line 342's
{{- end }}closes the enabled block, leaving theresourceAttributesloop to execute unconditionally. This produces orphaned[[apim.open_telemetry.resource_attributes]]entries when OpenTelemetry is disabled.🐛 Proposed fix
{{- if ne (.Values.wso2.apim.configurations.openTelemetry.url) "" }} remote_tracer.url = {{ .Values.wso2.apim.configurations.openTelemetry.url | quote }} {{- else }} remote_tracer.hostname = {{ .Values.wso2.apim.configurations.openTelemetry.hostname | quote }} remote_tracer.port = {{ .Values.wso2.apim.configurations.openTelemetry.port | quote }} {{- end }} -{{- end }} - -{{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} +{{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} [[apim.open_telemetry.resource_attributes]] name = {{ .name | quote }} value = {{ .value | quote }} {{- end }} +{{- end }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@all-in-one/confs/instance-2/deployment.toml` around lines 342 - 348, The resourceAttributes loop for [[apim.open_telemetry.resource_attributes]] is placed after the closing of the openTelemetry.enabled guard so it runs even when OpenTelemetry is disabled; move the {{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} ... {{- end }} block so it is nested inside the openTelemetry enabled conditional (i.e., before the {{- end }} that closes the openTelemetry.enabled if) so the apim.open_telemetry.resource_attributes entries are only rendered when openTelemetry.enabled is true.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@all-in-one/confs/instance-2/deployment.toml`:
- Around line 342-348: The resourceAttributes loop for
[[apim.open_telemetry.resource_attributes]] is placed after the closing of the
openTelemetry.enabled guard so it runs even when OpenTelemetry is disabled; move
the {{- range .Values.wso2.apim.configurations.openTelemetry.resourceAttributes
}} ... {{- end }} block so it is nested inside the openTelemetry enabled
conditional (i.e., before the {{- end }} that closes the openTelemetry.enabled
if) so the apim.open_telemetry.resource_attributes entries are only rendered
when openTelemetry.enabled is true.
In `@distributed/control-plane/confs/instance-1/deployment.toml`:
- Around line 288-294: The resourceAttributes range is rendered outside the
openTelemetry guard causing orphaned [[apim.open_telemetry.resource_attributes]]
entries when openTelemetry.enabled is false; move the resourceAttributes loop
inside the openTelemetry block by swapping the closing {{- end }} for the
openTelemetry.enabled block with the range block so that the {{- range
.Values.wso2.apim.configurations.openTelemetry.resourceAttributes }} ...
[[apim.open_telemetry.resource_attributes]] ... {{- end }} executes only when
openTelemetry.enabled is true (reference openTelemetry.enabled,
resourceAttributes, and apim.open_telemetry.resource_attributes).
In `@distributed/traffic-manager/confs/instance-1/deployment.toml`:
- Around line 172-178: The TOML resource_attributes loop
(.Values.wso2.apim.configurations.openTelemetry.resourceAttributes) is being
rendered even when openTelemetry.enabled is false because the {{- end }} closed
the openTelemetry.enabled guard too early; move the resourceAttributes range
block inside the openTelemetry.enabled conditional (i.e., ensure the {{ if
.Values.wso2.apim.configurations.openTelemetry.enabled }} .. {{ end }} surrounds
the [[apim.open_telemetry.resource_attributes]] range) so the loop only emits
when openTelemetry is enabled.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aab268b1-9407-4def-8b58-e8469c13dc81
📒 Files selected for processing (11)
all-in-one/README.mdall-in-one/confs/instance-1/deployment.tomlall-in-one/confs/instance-2/deployment.tomldistributed/control-plane/README.mddistributed/control-plane/confs/instance-1/deployment.tomldistributed/control-plane/confs/instance-2/deployment.tomldistributed/gateway/README.mddistributed/gateway/confs/deployment.tomldistributed/traffic-manager/README.mddistributed/traffic-manager/confs/instance-1/deployment.tomldistributed/traffic-manager/confs/instance-2/deployment.toml
🚧 Files skipped from review as they are similar to previous changes (8)
- distributed/gateway/README.md
- distributed/control-plane/confs/instance-2/deployment.toml
- distributed/control-plane/README.md
- distributed/traffic-manager/README.md
- distributed/traffic-manager/confs/instance-2/deployment.toml
- distributed/gateway/confs/deployment.toml
- all-in-one/README.md
- all-in-one/confs/instance-1/deployment.toml
Purpose
OpenTelemetry settings allow for
hostandportvalues but OTLP usesurl. Additionally there is currently no way to set additional resource_attributes to overrideservice.nameordeployment.environment.Goals
Allow users to use OTLP OpenTelemetry and send additional resource attributes.
Approach
wso2.apim.configurations.openTelemetry.urlandwso2.apim.configurations.openTelemetry.resourceAttributes.urlorhost/port.[[apim.open_telemetry.resource_attributes]]entries.Release note
Add support for OTLP OpenTelemetry
urlandresource_attributesDocumentation
Updated README.md with new Helm values.
Samples
Summary by CodeRabbit
New Features
Documentation