Skip to content

Comments

Adding monetization fields to GW#3753

Merged
HiranyaKavishani merged 2 commits intowso2:monetization-featurefrom
HiranyaKavishani:monetization
Jan 29, 2026
Merged

Adding monetization fields to GW#3753
HiranyaKavishani merged 2 commits intowso2:monetization-featurefrom
HiranyaKavishani:monetization

Conversation

@HiranyaKavishani
Copy link
Contributor

@HiranyaKavishani HiranyaKavishani commented Jan 23, 2026

Purpose

This PR allows to store the billing information sent by the Control Plane (CP) and include them in the analytics event during API invocation.

Related issue: https://github.com/wso2-enterprise/apim-saas/issues/1631

Issues

Fixes #

Automation tests

  • Unit tests added: Yes/No
  • Integration tests added: Yes/No

Tested environments

Not Tested


Maintainers: Check before merge

  • Assigned 'Type' label
  • Assigned the project
  • Validated respective github issues
  • Assigned milestone to the github issue(s)

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

Comment on lines 211 to 217
requestContext.addMetadataToMap(MetadataConstants.APP_OWNER_KEY,
AnalyticsUtils.setDefaultIfNull(authContext.getSubscriber()));
requestContext.addMetadataToMap(MetadataConstants.BILLING_CUSTOMER_ID,
AnalyticsUtils.setDefaultIfNull(authContext.getBillingCustomerId()));
requestContext.addMetadataToMap(MetadataConstants.BILLING_SUBSCRIPTION_ID,
AnalyticsUtils.setDefaultIfNull(authContext.getBillingSubscriptionId()));

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 1

Suggested change
requestContext.addMetadataToMap(MetadataConstants.APP_OWNER_KEY,
AnalyticsUtils.setDefaultIfNull(authContext.getSubscriber()));
requestContext.addMetadataToMap(MetadataConstants.BILLING_CUSTOMER_ID,
AnalyticsUtils.setDefaultIfNull(authContext.getBillingCustomerId()));
requestContext.addMetadataToMap(MetadataConstants.BILLING_SUBSCRIPTION_ID,
AnalyticsUtils.setDefaultIfNull(authContext.getBillingSubscriptionId()));
requestContext.addMetadataToMap(MetadataConstants.APP_OWNER_KEY,
AnalyticsUtils.setDefaultIfNull(authContext.getSubscriber()));
if (log.isDebugEnabled()) {
log.debug("Adding billing metadata - customerId: " +
(authContext.getBillingCustomerId() != null ? "[present]" : "[null]") +
", subscriptionId: " +
(authContext.getBillingSubscriptionId() != null ? "[present]" : "[null]"));
}

Comment on lines 241 to 244
map.put(AnalyticsConstants.GATEWAY_URL, gwURL);
map.put(AnalyticsConstants.DEPLOYMENT_TYPE, deploymentType);
map.put(AnalyticsConstants.BILLING_CUSTOMER_ID, getValueAsString(fieldsMap, MetadataConstants.BILLING_CUSTOMER_ID));
map.put(AnalyticsConstants.BILLING_SUBSCRIPTION_ID, getValueAsString(fieldsMap, MetadataConstants.BILLING_SUBSCRIPTION_ID));

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 2

Suggested change
map.put(AnalyticsConstants.GATEWAY_URL, gwURL);
map.put(AnalyticsConstants.DEPLOYMENT_TYPE, deploymentType);
map.put(AnalyticsConstants.BILLING_CUSTOMER_ID, getValueAsString(fieldsMap, MetadataConstants.BILLING_CUSTOMER_ID));
map.put(AnalyticsConstants.BILLING_SUBSCRIPTION_ID, getValueAsString(fieldsMap, MetadataConstants.BILLING_SUBSCRIPTION_ID));
map.put(AnalyticsConstants.GATEWAY_URL, gwURL);
map.put(AnalyticsConstants.DEPLOYMENT_TYPE, deploymentType);
map.put(AnalyticsConstants.BILLING_CUSTOMER_ID, getValueAsString(fieldsMap, MetadataConstants.BILLING_CUSTOMER_ID));
map.put(AnalyticsConstants.BILLING_SUBSCRIPTION_ID, getValueAsString(fieldsMap, MetadataConstants.BILLING_SUBSCRIPTION_ID));
log.debug("Added billing information to analytics properties.");

Comment on lines 215 to +217
public Map<String, Object> getProperties() {
Map map = new HashMap();
AuthenticationContext authContext = AnalyticsUtils.getAuthenticationContext(requestContext);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 3

Suggested change
public Map<String, Object> getProperties() {
Map map = new HashMap();
AuthenticationContext authContext = AnalyticsUtils.getAuthenticationContext(requestContext);
public Map<String, Object> getProperties() {
Map map = new HashMap();
AuthenticationContext authContext = AnalyticsUtils.getAuthenticationContext(requestContext);
log.debug("Retrieving properties for analytics with billing information");

Comment on lines 225 to +227
map.put(AnalyticsConstants.API_METHOD, requestContext.getRequestMethod());
map.put(AnalyticsConstants.BILLING_CUSTOMER_ID, billingCustomerId);
map.put(AnalyticsConstants.BILLING_SUBSCRIPTION_ID, billingSubscriptionId);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 4

Suggested change
map.put(AnalyticsConstants.API_METHOD, requestContext.getRequestMethod());
map.put(AnalyticsConstants.BILLING_CUSTOMER_ID, billingCustomerId);
map.put(AnalyticsConstants.BILLING_SUBSCRIPTION_ID, billingSubscriptionId);
map.put(AnalyticsConstants.API_METHOD, requestContext.getRequestMethod());
map.put(AnalyticsConstants.BILLING_CUSTOMER_ID, billingCustomerId);
map.put(AnalyticsConstants.BILLING_SUBSCRIPTION_ID, billingSubscriptionId);
if (log.isDebugEnabled()) {
log.debug("Added billing details to analytics properties - customerId: " +
(billingCustomerId.isEmpty() ? "not-set" : "set") +
", subscriptionId: " + (billingSubscriptionId.isEmpty() ? "not-set" : "set"));
}

Comment on lines 283 to +284
infoDTO.setSubscriberTenantDomain(app.getTenantDomain());
infoDTO.setBillingCustomerId(sub.getBillingCustomerId());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 5

Suggested change
infoDTO.setSubscriberTenantDomain(app.getTenantDomain());
infoDTO.setBillingCustomerId(sub.getBillingCustomerId());
infoDTO.setSubscriberTenantDomain(app.getTenantDomain());
if (log.isDebugEnabled()) {
log.debug("Setting billing information for subscription: customerId={}, subscriptionId={}",
sub.getBillingCustomerId() != null ? "[REDACTED]" : "null",
sub.getBillingSubscriptionId() != null ? "[REDACTED]" : "null");
}
infoDTO.setBillingCustomerId(sub.getBillingCustomerId());

Comment on lines 173 to +175
newSubscription.setVersionRange(subscription.getVersionRange());
newSubscription.setBillingCustomerId(subscription.getBillingCustomerId());
newSubscription.setBillingSubscriptionId(subscription.getBillingSubscriptionId());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 6

Suggested change
newSubscription.setVersionRange(subscription.getVersionRange());
newSubscription.setBillingCustomerId(subscription.getBillingCustomerId());
newSubscription.setBillingSubscriptionId(subscription.getBillingSubscriptionId());
newSubscription.setVersionRange(subscription.getVersionRange());
newSubscription.setBillingCustomerId(subscription.getBillingCustomerId());
newSubscription.setBillingSubscriptionId(subscription.getBillingSubscriptionId());
log.debug("Added billing information for subscription: {} with customerId: {} and subscriptionId: {}",
newSubscription.getCacheKey(), subscription.getBillingCustomerId(), subscription.getBillingSubscriptionId());

Copy link

@wso2-engineering wso2-engineering bot left a comment

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
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5
#### Log Improvement Suggestion No: 6

Adding missing file

adding re generated file

adding re generated file

fixing formatting issue
@HiranyaKavishani HiranyaKavishani changed the base branch from choreo to monetization-feature January 29, 2026 11:00
@HiranyaKavishani HiranyaKavishani changed the base branch from monetization-feature to choreo January 29, 2026 11:00
@HiranyaKavishani HiranyaKavishani changed the base branch from choreo to monetization-feature January 29, 2026 11:02
@HiranyaKavishani HiranyaKavishani merged commit c0d6f33 into wso2:monetization-feature Jan 29, 2026
3 of 4 checks passed
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.

1 participant