question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Collect non 200 responses

See original GitHub issue

Hello,

I’m not sure if this is currently possible, but if it is, please instruct me how. I want to see what uris failed with which statusCode, which for me is basically any status different from 200.

I’m currently trying with this:

module.exports.logErrors = function logArtilleryErrors(requestParams, response, context, ee, next) {
    if (response.statusCode !== 200) {
        ee.emit('nonOkResponse', {uri: requestParams.uri, statusCode: response.statusCode})
    }
    next();
}

But nothing appears on the log. What I’m doing wrong?

Regards

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
CRathod1220commented, Oct 17, 2022

Hey you can save the error log record in csv file format as well Step 1: Just install : npm i csv-writer

Step 2 : go to node_modules/artillery_plugin_expect/index.js file and add the below code in function(expectationsPluginCheckExpectations)

Changes in function

requestExpectations.results.forEach((e) => { if (e.ok) { events.emit(‘counter’, plugins.expect.ok, 1); events.emit(‘counter’, plugins.expect.ok.${e.type}, 1); } else { events.emit(‘counter’, plugins.expect.failed, 1); events.emit(‘counter’, plugins.expect.failed.${e.type}, 1);

 <-- add the below code in else part 
  console.log('error',res).  
  console.log('statusMessage',res.statusMessage) 
  console.log('statusCode',res.statusCode) 
  console.log('timings start',res.timings.start)
  console.log('timings end',res.timings.end) 
  console.log('requestUrl',res.requestUrl) 
  console.log('options',res.request.options.name) 
  console.log('options',res.request.options.url.origin) 

  const data = [       
    {
      host: res.request.options.url.origin,
      request: res.request.options.name,
      url:res.requestUrl,
      statusCode: res.statusCode,
      statusMessage: res.statusMessage
    }
  ];
  saveConsoleLogResult(data). <-- call the function to save error log in csv

}

});

// end here

Step 3 : **And Then create function saveConsoleLogResult and add the below code **

const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: 'result.csv',
header: [
  {id: 'host', title: 'Host'},
  {id: 'request', title: 'Request'},
  {id: 'url', title: 'URL'},
  {id: 'statusCode', title: 'StatusCode'},
  {id: 'statusMessage', title: 'Message'},
]
});

function saveConsoleLogResult(data){
csvWriter
.writeRecords(data)
.then(()=> console.log('The CSV file was written successfully'));
}
0reactions
hassycommented, Dec 5, 2018

@paraspatidar there’s nothing special about how Artillery sends its traffic, so using Wireshark as normal should just work. It would be good to have an example blog post perhaps, but having it as part of the documentation would be out-of-scope for that reason.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix URLs with canonical to non-200 - Sitechecker
Canonical to non-200 issue means that URL contain a canonical link element where the canonical URL returned a server response other than 200...
Read more >
HTTP response status codes - MDN Web Docs - Mozilla
Successful responses ( 200 – 299 ); Redirection messages ( 300 – 399 ); Client error responses ( 400 – 499 ); Server...
Read more >
Empty list, HTTP status code 200 vs 204 vs 404 - API Handyman
While 200 OK being a valid and the most common answer, returning a 204 No Content could make sense as there is absolutely...
Read more >
Create request with POST, which response codes 200 or 201 ...
The 201 (Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created....
Read more >
HTTP Status Codes: All 63 explained - including FAQ & Video
In some cases a HTTP response code might be descriptive enough to understand its meaning. 200 OK probably means that everything went okay....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found