Search code examples
loggingwso2wso2-esbwso2-api-managerwso2-enterprise-integrator

Why "CorrelationId" field does not exist in wso2 apim API Log?


According to performance problem we don't enable correlationlog according to Enabling Correlation Logs . Now, We need to use API Log of wso2-apim. but in logs, we don't see correlationID. we can search in logs with correlationId and If we don't have this feature, we cannot search log of specific api call easily. In document of WSO2-APIM, correlationId must exist by default according to this page:

[2022-02-08 15:09:45,235]  INFO {API_LOG} pizzashack - {"headers":["accept=application/json","Accept-Encoding=gzip, deflate, br","Accept-Language=en-US,en;q=0.9","activityid=64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","Connection=keep-alive","Content-Length=185","Content-Type=application/json","Host=localhost:8243","Internal-Key=eyJraWQiOiJnYXRld2F5X2NlcnRpZmljYXRlX2FsaWFzIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJhZG1pbkBjYXJib24uc3VwZXIiLCJpc3MiOiJodHRwczpcL1wvbG9jYWxob3N0Ojk0NDNcL29hdXRoMlwvdG9rZW4iLCJrZXl0eXBlIjoiUFJPRFVDVElPTiIsInN1YnNjcmliZWRBUElzIjpbeyJzdWJzY3JpYmVyVGVuYW50RG9tYWluIjpudWxsLCJuYW1lIjoiUGl6emFTaGFja0FQSSIsImNvbnRleHQiOiJcL3Bpenphc2hhY2tcLzEuMC4wIiwicHVibGlzaGVyIjoiYWRtaW4iLCJ2ZXJzaW9uIjoiMS4wLjAiLCJzdWJzY3JpcHRpb25UaWVyIjpudWxsfV0sImV4cCI6MTY0NDM3MjgyNywidG9rZW5fdHlwZSI6IkludGVybmFsS2V5IiwiaWF0IjoxNjQ0MzEyODI3LCJqdGkiOiI4OTJkODEwZS0xZmUxLTQ4OTItOTVjOS0xMDE5M2I3MzYwM2YifQ.Uvh6a11Cs3RakrvT0G8IvGm78-I512AeJ0r4N4xFydEVdAbGKZRkA_Z6Ox2U2pEClNPnvm8lXCwuIGtAQfmApl5bRGmOJtj-5UjiEYNUnPcefewOZc7ObJ6ct3hHK0jbHrlVwP1OREf5yyRQJdBxT9EImOQjz4uDe0gGD8jydyODE51_d-6hPLa4qkAQijlsGlKyqw1-j5YHfFWBpb3an3et5tvNTTdM428QyFPBvB7K-aLVrNaZdpwmv3F3T-F394SgyiN0sdyeDBomZm_x0JQWrN_AGJ7WIlcNGJ0Y4NCKXQjPI2i0LmRRtpCs4WMJGkovDYTxeWpQpm3lA2ksEw","Origin=https://localhost:9443","Referer=https://localhost:9443/","sec-ch-ua=\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\"","sec-ch-ua-mobile=?0","sec-ch-ua-platform=\"Linux\"","Sec-Fetch-Dest=empty","Sec-Fetch-Mode=cors","Sec-Fetch-Site=same-site","User-Agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"sourceIP":"127.0.0.1","payload":"{\n  \"customerName\": \"customer\",\n  \"delivered\": true,\n  \"address\": \"address\",\n  \"pizzaType\": \"regular\",\n  \"creditCardNumber\": \"0000-0000-0000-0000\",\n  \"quantity\": 1,\n  \"orderId\": \"001\"\n}","verb":"POST","correlationId":"64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","apiTo":"pizzashack/1.0.0/order","flow":"REQUEST_IN"}
[2022-02-08 15:09:45,238]  INFO {API_LOG} pizzashack - {"headers":["accept=application/json","Accept-Encoding=gzip, deflate, br","Accept-Language=en-US,en;q=0.9","activityid=64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","Connection=keep-alive","Content-Length=185","Content-Type=application/json","Host=localhost:8243","Origin=https://localhost:9443","Referer=https://localhost:9443/","sec-ch-ua=\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\"","sec-ch-ua-mobile=?0","sec-ch-ua-platform=\"Linux\"","Sec-Fetch-Dest=empty","Sec-Fetch-Mode=cors","Sec-Fetch-Site=same-site","User-Agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"],"sourceIP":"127.0.0.1","payload":"{\n  \"customerName\": \"customer\",\n  \"delivered\": true,\n  \"address\": \"address\",\n  \"pizzaType\": \"regular\",\n  \"creditCardNumber\": \"0000-0000-0000-0000\",\n  \"quantity\": 1,\n  \"orderId\": \"001\"\n}","verb":"POST","correlationId":"64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","apiTo":"pizzashack/1.0.0/order","flow":"REQUEST_OUT"}
[2022-02-08 15:09:45,357]  INFO {API_LOG} pizzashack - {"headers":["Connection=keep-alive","Content-Type=application/json","Date=Tue, 08 Feb 2022 09:39:45 GMT","Keep-Alive=timeout=60","Location=https://localhost:9443/am/sample/pizzashack/v1/api/order/c952947d-52cf-403f-b2bb-bec7e26c0252","Server=WSO2 Carbon Server","Transfer-Encoding=chunked"],"payload":"{\"orderId\":\"c952947d-52cf-403f-b2bb-bec7e26c0252\",\"pizzaType\":\"regular\",\"quantity\":1,\"customerName\":\"customer\",\"creditCardNumber\":\"0000-0000-0000-0000\",\"address\":\"address\",\"delivered\":true}","verb":"POST","correlationId":"64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","apiTo":"pizzashack/1.0.0/order","flow":"RESPONSE_IN","statusCode":201}
[2022-02-08 15:09:45,358]  INFO {API_LOG} pizzashack - {"headers":["Access-Control-Allow-Headers=authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction,apikey,Internal-Key,Authorization","Access-Control-Allow-Methods=POST","Access-Control-Allow-Origin=*","Access-Control-Expose-Headers=","activityid=64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","Connection=keep-alive","Content-Type=application/json","Date=Tue, 08 Feb 2022 09:39:45 GMT","Keep-Alive=timeout=60","Location=https://localhost:9443/am/sample/pizzashack/v1/api/order/c952947d-52cf-403f-b2bb-bec7e26c0252","Server=WSO2 Carbon Server","Transfer-Encoding=chunked"],"payload":"{\"orderId\":\"c952947d-52cf-403f-b2bb-bec7e26c0252\",\"pizzaType\":\"regular\",\"quantity\":1,\"customerName\":\"customer\",\"creditCardNumber\":\"0000-0000-0000-0000\",\"address\":\"address\",\"delivered\":true}","verb":"POST","correlationId":"64b0b90d-7c24-4b7b-9000-1d0b78eb04c4","apiTo":"pizzashack/1.0.0/order","flow":"RESPONSE_OUT","statusCode":201}

But our logs does not contain correlationID:

[2023-03-13 12:25:35,783]  INFO {API_LOG} PizzaShackAPI - {"headers":["accept=application/json","Accept-Encoding=gzip, deflate, br","Accept-Language=fa,fa-IR;q=0.9,en-US;q=0.8,en;q=0.7","activityid=dc11715c-ab60-439f-99dd-68ec7bcee10e","Connection=keep-alive","Host=localhost:8243","Internal-Key=eyJraWQiOiJnYXRld2F5X2NlcnRpZmljYXRlX2FsaWFzIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJhZG1pbkBjYXJib24uc3VwZXIiLCJpc3MiOiJodHRwczpcL1wvbG9jYWxob3N0Ojk0NDNcL29hdXRoMlwvdG9rZW4iLCJrZXl0eXBlIjoiUFJPRFVDVElPTiIsInN1YnNjcmliZWRBUElzIjpbeyJzdWJzY3JpYmVyVGVuYW50RG9tYWluIjpudWxsLCJuYW1lIjoiUGl6emFTaGFja0FQSSIsImNvbnRleHQiOiJcL3Bpenphc2hhY2tcLzEuMC4wIiwicHVibGlzaGVyIjoiYWRtaW4iLCJ2ZXJzaW9uIjoiMS4wLjAiLCJzdWJzY3JpcHRpb25UaWVyIjpudWxsfV0sImV4cCI6MTY3ODc1NzcyNiwidG9rZW5fdHlwZSI6IkludGVybmFsS2V5IiwiaWF0IjoxNjc4Njk3NzI2LCJqdGkiOiIzNmIxNzNmMC04ZTI1LTQzNGYtODc1YS1mZmZiZWM0OTdlNmYifQ.hOo3PJHDq9D0wbIG1Y5gZh29f26wLyWD2S0skERxFy5-Mms-Z0VuFKIjxrZz_zrukkBKku78yvExrvFr3r3XeN7PI1LVYsBhmLfdyeRmaR2Dc8oV4TRc_OSUP40x5zZivP4zPjgZg_M6jeLa2qDjkr1pVWnMqnNdD-h-XLMIc4WGIEcN2hm-_PVFFF-0IbIW0ToBJuuBG8vsIY0GsQ8JJkA_iW7ruJmUUMu-z7ucrnPUsvABUfVeKG_-1WvHt-klNJl5_Rh9MSQ0BWJX5NTna2-0ldD6_iuS0Ugmeq5IBmwzSUXG8NlmwPRdFMMgHmMd85_gfTIV1JvYkmsB2eFlUg","Origin=https://localhost:9443","Referer=https://localhost:9443/","sec-ch-ua=\"Chromium\";v=\"110\", \"Not A(Brand\";v=\"24\", \"Google Chrome\";v=\"110\"","sec-ch-ua-mobile=?0","sec-ch-ua-platform=\"Windows\"","Sec-Fetch-Dest=empty","Sec-Fetch-Mode=cors","Sec-Fetch-Site=same-site","User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"],"sourceIP":"0:0:0:0:0:0:0:1","payload":"<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body/><\/soapenv:Envelope>","verb":"GET","apiTo":"pizzashack/1.0.0/menu","flow":"REQUEST_IN"}
[2023-03-13 12:25:35,818]  INFO {API_LOG} PizzaShackAPI - {"headers":["accept=application/json","Accept-Encoding=gzip, deflate, br","Accept-Language=fa,fa-IR;q=0.9,en-US;q=0.8,en;q=0.7","activityid=dc11715c-ab60-439f-99dd-68ec7bcee10e","Connection=keep-alive","Host=localhost:8243","Origin=https://localhost:9443","Referer=https://localhost:9443/","sec-ch-ua=\"Chromium\";v=\"110\", \"Not A(Brand\";v=\"24\", \"Google Chrome\";v=\"110\"","sec-ch-ua-mobile=?0","sec-ch-ua-platform=\"Windows\"","Sec-Fetch-Dest=empty","Sec-Fetch-Mode=cors","Sec-Fetch-Site=same-site","User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"],"sourceIP":"0:0:0:0:0:0:0:1","payload":"<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body/><\/soapenv:Envelope>","verb":"GET","apiTo":"pizzashack/1.0.0/menu","flow":"REQUEST_OUT"}
[2023-03-13 12:25:36,492]  INFO {API_LOG} PizzaShackAPI - {"headers":["Connection=keep-alive","Content-Type=application/json","Date=Mon, 13 Mar 2023 08:55:35 GMT","Keep-Alive=timeout=60","Server=WSO2 Carbon Server","Transfer-Encoding=chunked"],"payload":"[{\"name\":\"BBQ Chicken Bacon\",\"description\":\"Grilled white chicken, hickory-smoked bacon and fresh sliced onions in barbeque sauce\",\"price\":\"19.99\",\"icon\":\"/images/6.png\"},{\"name\":\"Chicken Parmesan\",\"description\":\"Grilled chicken, fresh tomatoes, feta and mozzarella cheese\",\"price\":\"15.99\",\"icon\":\"/images/1.png\"},{\"name\":\"Chilly Chicken Cordon Bleu\",\"description\":\"Spinash Alfredo sauce topped with grilled chicken, ham, onions and mozzarella\",\"price\":\"22.99\",\"icon\":\"/images/10.png\"},{\"name\":\"Double Bacon 6Cheese\",\"description\":\"Hickory-smoked bacon, Julienne cut Canadian bacon, Parmesan, mozzarella, Romano, Asiago and and Fontina cheese\",\"price\":\"19.99\",\"icon\":\"/images/9.png\"},{\"name\":\"Garden Fresh\",\"description\":\"Slices onions and green peppers, gourmet mushrooms, black olives and ripe Roma tomatoes\",\"price\":\"23.99\",\"icon\":\"/images/3.png\"},{\"name\":\"Grilled Chicken Club\",\"description\":\"Grilled white chicken, hickory-smoked bacon and fresh sliced onions topped with Roma tomatoes\",\"price\":\"11.99\",\"icon\":\"/images/8.png\"},{\"name\":\"Hawaiian BBQ Chicken\",\"description\":\"Grilled white chicken, hickory-smoked bacon, barbeque sauce topped with sweet pine-apple\",\"price\":\"12.99\",\"icon\":\"/images/7.png\"},{\"name\":\"Spicy Italian\",\"description\":\"Pepperoni and a double portion of spicy Italian sausage\",\"price\":\"18.99\",\"icon\":\"/images/2.png\"},{\"name\":\"Spinach Alfredo\",\"description\":\"Rich and creamy blend of spinach and garlic Parmesan with Alfredo sauce\",\"price\":\"18.99\",\"icon\":\"/images/5.png\"},{\"name\":\"Tuscan Six Cheese\",\"description\":\"Six cheese blend of mozzarella, Parmesan, Romano, Asiago and Fontina\",\"price\":\"24.99\",\"icon\":\"/images/4.png\"}]","verb":"GET","apiTo":"pizzashack/1.0.0/menu","flow":"RESPONSE_IN","statusCode":200}
[2023-03-13 12:25:36,493]  INFO {API_LOG} PizzaShackAPI - {"headers":["Access-Control-Allow-Headers=authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction,apikey,Internal-Key,Authorization","Access-Control-Allow-Methods=GET","Access-Control-Allow-Origin=*","Access-Control-Expose-Headers=","activityid=dc11715c-ab60-439f-99dd-68ec7bcee10e","Connection=keep-alive","Content-Type=application/json","Date=Mon, 13 Mar 2023 08:55:35 GMT","Keep-Alive=timeout=60","Server=WSO2 Carbon Server","Transfer-Encoding=chunked"],"payload":"[{\"name\":\"BBQ Chicken Bacon\",\"description\":\"Grilled white chicken, hickory-smoked bacon and fresh sliced onions in barbeque sauce\",\"price\":\"19.99\",\"icon\":\"/images/6.png\"},{\"name\":\"Chicken Parmesan\",\"description\":\"Grilled chicken, fresh tomatoes, feta and mozzarella cheese\",\"price\":\"15.99\",\"icon\":\"/images/1.png\"},{\"name\":\"Chilly Chicken Cordon Bleu\",\"description\":\"Spinash Alfredo sauce topped with grilled chicken, ham, onions and mozzarella\",\"price\":\"22.99\",\"icon\":\"/images/10.png\"},{\"name\":\"Double Bacon 6Cheese\",\"description\":\"Hickory-smoked bacon, Julienne cut Canadian bacon, Parmesan, mozzarella, Romano, Asiago and and Fontina cheese\",\"price\":\"19.99\",\"icon\":\"/images/9.png\"},{\"name\":\"Garden Fresh\",\"description\":\"Slices onions and green peppers, gourmet mushrooms, black olives and ripe Roma tomatoes\",\"price\":\"23.99\",\"icon\":\"/images/3.png\"},{\"name\":\"Grilled Chicken Club\",\"description\":\"Grilled white chicken, hickory-smoked bacon and fresh sliced onions topped with Roma tomatoes\",\"price\":\"11.99\",\"icon\":\"/images/8.png\"},{\"name\":\"Hawaiian BBQ Chicken\",\"description\":\"Grilled white chicken, hickory-smoked bacon, barbeque sauce topped with sweet pine-apple\",\"price\":\"12.99\",\"icon\":\"/images/7.png\"},{\"name\":\"Spicy Italian\",\"description\":\"Pepperoni and a double portion of spicy Italian sausage\",\"price\":\"18.99\",\"icon\":\"/images/2.png\"},{\"name\":\"Spinach Alfredo\",\"description\":\"Rich and creamy blend of spinach and garlic Parmesan with Alfredo sauce\",\"price\":\"18.99\",\"icon\":\"/images/5.png\"},{\"name\":\"Tuscan Six Cheese\",\"description\":\"Six cheese blend of mozzarella, Parmesan, Romano, Asiago and Fontina\",\"price\":\"24.99\",\"icon\":\"/images/4.png\"}]","verb":"GET","apiTo":"pizzashack/1.0.0/menu","flow":"RESPONSE_OUT","statusCode":200}

Could Anybody help me please?


Solution

  • It seems like there is a bug in the code. The correlation ID is actually stored in a property called correlation_id in the messageContext. But in [1] we have defined a constant CORRELATION_ID which has the value Correlation-ID. Since the correlation_id is null, the log message body won't contain the ID.You may need to manually update the code in line [1] as follows and patch the product

    logMessage.put("correlationId", messageContext.getProperty("correlation_id"));
    

    After that you can see the correlationId in the log message as follows which is consistent through the Response_in, Response_out, Request_in, Request_out events,

    "verb":"GET","correlationId":"c1436232-b449-4fe6-b58b-710bbdab67ca","apiTo":"pizzashack/1.0.0/menu","flow":"REQUEST_IN"
    

    [1] - https://github.com/wso2/carbon-apimgt/blob/v9.20.74/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/logging/APILogHandler.java#L112