Skip to content

Publish Custom Attributes With Analytics

Choreo Connect provides default set of attributes with the analytics data when an API invocation happens. In addition to that, users can add custom analytics data with an analytics event due to this feature. If there are specific request headers, response headers, and response trailers relevant to the event, users can retrieve those values and use them with Choreo Connect analytics. This guide will explain the steps required to do it.


This feature is only available with ELK based Analytics. Only Request headers (headers sent to the upstream), Response headers (headers coming from the upstream), and Response trailers can be used with this feature.

Creating The Custom Analytics Data Provider JAR

You need to create a new Java Maven project to obtain this JAR.

There is an existing sample project available here. If you wish to use that sample instead of developing the sample from scratch, you can ignore the steps of creating the sample and start from here.

Configuring the pom.xml file

  1. Add the wso2-nexus repository to the pom.xml file.

        <name>WSO2 internal Repository</name>
    2. Add relevant dependencies.



  • You need to add org.wso2.carbon.apimgt.common.analytics_<COMPENENT_VERSION>.jar to the local m2 mannually and provide path to the local m2 as mentioned below.
    1. Add the above .jar files to the local m2 manually.
      mvn install:install-file -Dfile=<PATH_TO_FILE>/org.wso2.carbon.apimgt.common.analytics_<COMPENENT_VERSION>.jar -DgroupId=org.wso2.carbon.apimgt -Dversion=<COMPENENT_VERSION> -Dpackaging=jar
    2. Point local m2 repository in project pom
          <id> local-maven-repo </id>
          <url> file://home/user/.m2/repository </url>
      Follow the same URL pattern when providing the repository URL.

Implementing the required class

AnalyticsCustomDataProvider Implementation Class

Analytics with custom attributes feature can be customized by implementing the AnalyticsCustomDataProvider interface. Therefore, it is required to implement a class from the AnalyticsCustomDataProvider interface. By overriding the getCustomProperties method it is possible to push custom analytics data. From Choreo Connect analytics implementation, all the header values (request, response headers, response trailers) relevant to the request will be sent in a HashMap. Therefore, by processing it you can obtain the required headers.

Build the project JAR addition to the Enforcer

  • Build the project using the following command.

    mvn clean install
  • Obtain the relevant JAR from target folder and mount it to the {CC_HOME}/resources/enforcer/dropins folder.

Creating The Custom Reporter JAR to log analytics data

  1. In order to log the custom attributes for the event occurrences, you need to add the Custom Reporter JAR to the dropins folder. You can follow the Step 1.1 explained here to obtain the JAR. Similar to the above after obtaining the JAR mount it to the enforcer/dropins folder.

    1. Configure the file with the following configurations.

      1. Add a new logger to the Enforcer by adding the following configuration. = = TRACE = ENFORCER_ACCESS_LOG
      2. Append the newly added logger as indicated below.

      loggers = org-wso2-analytics-publisher, other_available_loggers...
    2. Update the <CHOREO-CONNECT_HOME>/docker-compose/choreo-connect(-with-apim)/conf/config.toml file with the following configurations.

          enabled = true
          type = "ELK"
          enabled = true
          requestHeaders = ["request_headers_to_pass_from_router_to_enforcer"]
          responseHeaders = ["response_headers_to_pass_from_router_to_enforcer"]
          responseTrailers = ["response_trailers_to_pass_from_router_to_enforcer"]
          "" = "fully qualified class name of the customDataProvider"

Obtaining Custom Attributes with Analytics

  1. Enable Choreo Connect analytics.
  2. Initiate an event to publish analytics data.
  3. In the Enforcer logs you will see the relevant attribute related to the API invocation under the properties field.

      choreo-connect-with-apim-enforcer-1  | ... Info -