Skip to content

Add configurable OpenTelemetry sampler for OTLP tracing#13876

Open
Shamly-Shanawaz wants to merge 1 commit into
wso2:masterfrom
Shamly-Shanawaz:otlp-sampler-change
Open

Add configurable OpenTelemetry sampler for OTLP tracing#13876
Shamly-Shanawaz wants to merge 1 commit into
wso2:masterfrom
Shamly-Shanawaz:otlp-sampler-change

Conversation

@Shamly-Shanawaz

Copy link
Copy Markdown

Description

This PR improves OpenTelemetry OTLP tracing by making the trace sampler configurable via deployment.toml (remote_tracer.sampler_mode).

Issue

wso2/api-manager#5075

@wso2-engineering wso2-engineering 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.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0cde1bd4-39d3-42c2-b55b-eb524d2eb821

📥 Commits

Reviewing files that changed from the base of the PR and between 56a4da8 and 1b32f67.

📒 Files selected for processing (3)
  • components/apimgt/org.wso2.carbon.apimgt.tracing/src/main/java/org/wso2/carbon/apimgt/tracing/telemetry/OTLPTelemetry.java
  • components/apimgt/org.wso2.carbon.apimgt.tracing/src/main/java/org/wso2/carbon/apimgt/tracing/telemetry/TelemetryConstants.java
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2

📝 Walkthrough

Walkthrough

Adds configurable trace sampling to the OTLP telemetry implementation. TelemetryConstants gains four sampler-related string constants. OTLPTelemetry adds a getConfiguredSampler() method that maps the configured SamplerMode value to an OpenTelemetry Sampler, with fallback and warning logging, and wires it into SdkTracerProvider. The api-manager.xml.j2 template conditionally emits a SamplerMode XML element when the property is set.

Changes

Configurable OTLP Sampler

Layer / File(s) Summary
Sampler constants and OTLPTelemetry resolver
...tracing/telemetry/TelemetryConstants.java, ...tracing/telemetry/OTLPTelemetry.java
TelemetryConstants adds OTLP_CONFIG_SAMPLER, SAMPLER_ALWAYS_ON, SAMPLER_ALWAYS_OFF, and SAMPLER_PARENT_BASED. OTLPTelemetry adds getConfiguredSampler() mapping those values to Sampler.alwaysOn, Sampler.alwaysOff, or Sampler.parentBased(alwaysOn) with warning-and-fallback for unknown values, and applies it via .setSampler() on the SdkTracerProvider builder.
SamplerMode config template
features/apimgt/.../conf_templates/templates/repository/conf/api-manager.xml.j2
Adds a Jinja {% if %} block under OpenTelemetry/RemoteTracer to conditionally emit <SamplerMode> from apim.open_telemetry.remote_tracer.sampler_mode.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding configurable OpenTelemetry sampler support for OTLP tracing, which is the primary objective of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining that the PR makes the trace sampler configurable via deployment.toml and references the corresponding issue.
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 and usage tips.

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.

2 participants