Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom analytics data #4078

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gayaldassanayake
Copy link

Purpose

Fixes https://github.com/wso2-enterprise/wso2-mi-internal/issues/995
Fixes #4050

Goals

$ subject

Approach

Introduced a AnalyticsCustomDataProvider interface that can be implemented by external parties.

public class SampleCustomDataProvider implements AnalyticsCustomDataProvider {
    @Override
    public Map<String, Object> getCustomProperties(MessageContext messageContext) {
        Map<String, Object> properties = new HashMap<>();
        Mediator mediator = messageContext.getMainSequence();
        properties.put("mediator", mediator.getMediatorName());

        properties.put("messageId", messageContext.getMessageID());
        return properties;
    }
}

By adding it to the lib directory and specifying its path in the deployment.toml, we can add custom analytics data.

# deployment.toml
[analytics]
enabled=true
custom_data_provider_class = "org.wso2.ei.SampleCustomDataProvider"
10:16:13,408 [-] [message-flow-reporter-1-tenant--1234]  INFO ElasticStatisticsPublisher SYNAPSE_ANALYTICS_DATA {"serverInfo":{"hostname":"gayald.local","serverName":"localhost","ipAddress":"10.100.8.92","id":"localhost"},"timestamp":"2025-03-11T04:42:26.981Z","schemaVersion":1,"payload":{"metadata":{"messageId":"urn:uuid:bed56cd0-18ce-4e1a-87bd-01544d24d35d","mediator":"SequenceMediator"},"entityType":"API","failure":false,"latency":48,"messageId":"urn:uuid:bed56cd0-18ce-4e1a-87bd-01544d24d35d","correlation_id":"4dd2d624-72c3-4aa2-a871-846080a70594","apiDetails":{"method":"POST","apiContext":"/helloworldapi","api":"HelloWorldAPI","transport":"http","subRequestPath":"/signup"},"faultResponse":false,"entityClassName":"org.apache.synapse.api.API"}}

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 [email protected] 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.

@@ -1627,7 +1627,7 @@
<version.jaxb.api>2.4.0-b180830.0359</version.jaxb.api>
<com.sun.jaxb.version>2.3.0</com.sun.jaxb.version>
<com.sun.jaxb.impl.version>2.3.1</com.sun.jaxb.impl.version>
<synapse.version>4.0.0-wso2v216</synapse.version>
<synapse.version>4.0.0-wso2v217-SNAPSHOT</synapse.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not mention snapshot version. Once the synapse version is released with the fix, we can upgrade it here.

updatingLog.setElasticMetadata(dataUnit.getElasticMetadata());
private void setElasticMetaData(BasicStatisticDataUnit dataUnit, StatisticsLog statisticsLog) {
if (dataUnit.getElasticMetadata() == null) {
dataUnit.generateElasticMetadata(dataUnit.getMessageContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we are generating metadata here? Was that logic there before too?

AnalyticsCustomDataProvider customDataProvider = AnalyticsDataProviderHolder.getAnalyticsCustomDataProvider();
if (customDataProvider != null) {
if (elasticMetadata.getAnalyticsMetadata() == null) {
dataUnit.getMessageContext().setProperty(ANALYTICS_METADATA, new HashMap<String, Object>());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can dataunit message context null?

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.

Add support to publish custom attributes to ELK based Analytics
2 participants