Skip to content

Add instrumentation support for ballerina#1172

Merged
menakaj merged 4 commits into
wso2:mainfrom
hanzjk:trace-key
Jun 30, 2026
Merged

Add instrumentation support for ballerina#1172
menakaj merged 4 commits into
wso2:mainfrom
hanzjk:trace-key

Conversation

@hanzjk

@hanzjk hanzjk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.

Resolves #1110

Introduced a new trait to mount an am-instrumentation.toml file with the following content and set the config file path using the BAL_CONFIG_FILES environment variable:

[ballerina.observe]
tracingEnabled = true
tracingProvider = "amp"
BAL_CONFIG_FILES=am-instrumentation.toml:Config.toml

This is done using an init container with a BusyBox image.

Also updated the existing trait that injects the OTEL endpoint and API key to support renaming the environment variables that are injected with those values. The default environment variable names are AMP_OTEL_ENDPOINT and AMP_AGENT_API_KEY.

[build-options]
observabilityIncluded = true

This configuration is included by default in the Ballerina.toml file generated when initiating a new package using the bal new command in Ballerina.

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter �N/A� plus brief explanation of why there�s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type �Sent� when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type �N/A� and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • New Features
    • Added Ballerina buildpack support across agent creation and build configuration flows.
    • Introduced Ballerina-specific OpenTelemetry auto-instrumentation with configurable environment variable names, plus a new Helm trait that generates and mounts the required config per environment.
    • Updated console UI to support Ballerina selection, display, import snippet copy, and an auto-instrumentation toggle.
  • Bug Fixes
    • Clear stale validation errors when switching to Ballerina.
  • Tests
    • Updated Ballerina agent creation test setup.
  • Chores
    • Expanded the allowed traits list for agent APIs to include the new Ballerina instrumentation trait.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hanzjk, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 45 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c5a0ce8-496c-4bed-a9a8-422e00582f33

📥 Commits

Reviewing files that changed from the base of the PR and between ae6f061 and 3a22c24.

📒 Files selected for processing (14)
  • agent-manager-service/clients/openchoreosvc/client/components.go
  • agent-manager-service/clients/openchoreosvc/client/constants.go
  • agent-manager-service/services/agent_manager.go
  • agent-manager-service/tests/create_agent_test.go
  • console/workspaces/libs/views/src/icons/BuildpackIcon.tsx
  • console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx
  • console/workspaces/pages/add-new-agent/src/utils/buildAgentPayload.ts
  • console/workspaces/pages/build/src/ConfigureBuildDrawer.tsx
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/cluster-workflow-templates/ballerina-buildpack-build.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/cluster-workflow-templates/dockefile-build.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/cluster-workflow-templates/gcp-buildpack-build.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/instrumentation-trait-env-injection.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-types/agent-api.yaml
📝 Walkthrough

Walkthrough

The PR adds Ballerina support to agent creation, trait wiring, and Helm templates. It introduces a Ballerina buildpack path in the UI and payload, Ballerina-specific trait parameters in the client, and Ballerina OTEL instrumentation handling in deployment templates.

Changes

Ballerina agent instrumentation support

Layer / File(s) Summary
Console Ballerina agent setup
console/workspaces/libs/views/src/icons/BuildpackIcon.tsx, console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx, console/workspaces/pages/add-new-agent/src/utils/buildAgentPayload.ts, console/workspaces/pages/build/src/ConfigureBuildDrawer.tsx, agent-manager-service/tests/create_agent_test.go
The add-new-agent and build configuration UI add Ballerina language selection, Ballerina-specific instrumentation controls, a copyable import snippet, a Ballerina buildpack icon, and Ballerina buildpack payload branches; the Ballerina agent creation test setup also adds a mock component response.
Client trait contracts
agent-manager-service/clients/openchoreosvc/client/constants.go, agent-manager-service/clients/openchoreosvc/client/components.go
The client adds a Ballerina trait type, Ballerina config-mapped keys, env-name override helpers, and a Ballerina config-file parameter builder.
Service Ballerina trait wiring
agent-manager-service/services/agent_manager.go
The agent manager detects Ballerina buildpacks, adds Ballerina-specific trait requests during agent creation, and passes buildpack state into per-environment instrumentation updates for deploy, promote, and deploy-settings operations.
Helm Ballerina traits
deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/instrumentation-trait-env-injection.yaml, deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml, deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-types/agent-api.yaml
The Helm charts add env-name parameters to the existing env-injection trait, define the Ballerina OTEL instrumentation trait, and add that trait to the agent-api allowed traits list.

Sequence Diagram(s)

sequenceDiagram
  participant InternalAgentForm
  participant buildAgentCreationPayload
  participant AgentManager
  participant openchoreosvc client
  participant Helm trait config
  InternalAgentForm->>buildAgentCreationPayload: submit Ballerina agent build payload
  buildAgentCreationPayload->>AgentManager: create agent request
  AgentManager->>openchoreosvc client: build Ballerina trait parameters
  AgentManager->>Helm trait config: apply instrumentation settings
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • menakaj
  • RAVEENSR

Poem

🐇 Hop! The Bal bells ring at dawn,
A new trail of configs stretches on.
I nibble imports, tip my ear,
And copy snippets far and near.
Hooray—Ballerina hops appear!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers Purpose but leaves the rest of the required template sections empty or unfilled. Fill in Goals, Approach, User stories, Release note, Documentation, Tests, Security checks, and the remaining template sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: Ballerina instrumentation support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx (1)

92-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated import snippet into a constant.

"import ballerinax/amp as _;" is hard-coded both in handleCopyBalImport (line 92) and in the rendered <pre> (line 549). If one is edited the copy button silently diverges from the displayed text. Define it once and reuse.

Also applies to: 549-549

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx` at
line 92, The AMP import snippet is duplicated between handleCopyBalImport and
the rendered <pre>, so the copy action can drift from what is displayed. Extract
the shared string into a single constant in InternalAgentForm and use it both in
the clipboard writeText call and in the UI rendering to keep them in sync.
deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml (1)

70-78: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Confirm configMountDir and BAL_CONFIG_FILES relative-path coupling.

The toml is mounted at ${parameters.configMountDir}/am-instrumentation.toml, but BAL_CONFIG_FILES references it by the relative name am-instrumentation.toml, which Ballerina resolves against its WORKDIR. If an operator overrides configMountDir to a directory other than the run-image WORKDIR (/workspace), Ballerina will not find the file. The inline comment notes this, but the two values can silently drift. Consider deriving the env value from configMountDir to keep them in sync.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml`
around lines 70 - 78, The `bal-otel-instrumentation-trait.yaml` mount path and
`BAL_CONFIG_FILES` value are coupled but currently defined independently, so
overriding `configMountDir` can break Ballerina’s lookup. Update the trait so
the env var is derived from the same `configMountDir` used in the `volumeMounts`
entry for `am-instrumentation.toml`, keeping `BAL_CONFIG_FILES` in sync with the
mounted location. Use the existing `configMountDir`, `BAL_CONFIG_FILES`, and
`am-instrumentation.toml` symbols to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@agent-manager-service/clients/openchoreosvc/client/constants.go`:
- Around line 113-116: Add the new Ballerina config-var constants to
SystemInjectedEnvVars so the agent treats them as internal injected values.
Update the env-var filter/read-only handling in the code path used by
agent_manager.go, referencing BalConfigVarOTELEndpoint and
BalConfigVarAgentAPIKey, and make sure both
BAL_CONFIG_VAR_BALLERINAX_AMP_OTELENDPOINT and
BAL_CONFIG_VAR_BALLERINAX_AMP_APIKEY are included alongside the existing
injected env vars.

In `@console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx`:
- Around line 523-533: handleFieldChange currently clears conditional validation
only for python and docker, so stale errors can survive when language switches
to Ballerina. Update the language-dependent error reset logic in
InternalAgentForm’s handleFieldChange to add a ballerina branch that clears any
no-longer-relevant errors from the hidden Python/Docker fields, using the
existing field/error handling pattern already used for python and docker.

In
`@deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml`:
- Around line 80-85: The BAL_CONFIG_FILES value in the
bal-otel-instrumentation-trait template is hard-coded to include Config.toml,
which can break workloads that do not ship that file. Update the logic around
the BAL_CONFIG_FILES env entry in the component trait template to make the
Config.toml portion conditional based on its presence, or clearly
enforce/document that Config.toml is required for this trait; use the existing
BAL_CONFIG_FILES/env injection block to locate the change.

---

Nitpick comments:
In `@console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx`:
- Line 92: The AMP import snippet is duplicated between handleCopyBalImport and
the rendered <pre>, so the copy action can drift from what is displayed. Extract
the shared string into a single constant in InternalAgentForm and use it both in
the clipboard writeText call and in the UI rendering to keep them in sync.

In
`@deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml`:
- Around line 70-78: The `bal-otel-instrumentation-trait.yaml` mount path and
`BAL_CONFIG_FILES` value are coupled but currently defined independently, so
overriding `configMountDir` can break Ballerina’s lookup. Update the trait so
the env var is derived from the same `configMountDir` used in the `volumeMounts`
entry for `am-instrumentation.toml`, keeping `BAL_CONFIG_FILES` in sync with the
mounted location. Use the existing `configMountDir`, `BAL_CONFIG_FILES`, and
`am-instrumentation.toml` symbols to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6c908606-aada-4268-87f8-9b5a0e0a858c

📥 Commits

Reviewing files that changed from the base of the PR and between 6eb9786 and 43e8476.

📒 Files selected for processing (9)
  • agent-manager-service/clients/openchoreosvc/client/components.go
  • agent-manager-service/clients/openchoreosvc/client/constants.go
  • agent-manager-service/services/agent_manager.go
  • console/workspaces/libs/views/src/icons/BuildpackIcon.tsx
  • console/workspaces/pages/add-new-agent/src/forms/InternalAgentForm.tsx
  • console/workspaces/pages/add-new-agent/src/utils/buildAgentPayload.ts
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/bal-otel-instrumentation-trait.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-traits/instrumentation-trait-env-injection.yaml
  • deployments/helm-charts/wso2-amp-platform-resources-extension/templates/component-types/agent-api.yaml

Comment thread agent-manager-service/clients/openchoreosvc/client/constants.go
@hanzjk hanzjk force-pushed the trace-key branch 3 times, most recently from bdfe46e to ae6f061 Compare June 25, 2026 03:36
@menakaj menakaj merged commit ca58c84 into wso2:main Jun 30, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manage BI agents in Agent Manager

2 participants