<commit_before>var uuid = require('node-uuid');

module.exports = function(addHandler) {
  addHandler('request', function(env, next) {
    env.requestId = uuid.v4();
    env.sequenceNumber = 0;
    env.printTrace = function(name, message) {
      var request = env.request;
      var response = env.response;
      var target = env.target;

      var log = {
        name: name,
        requestId: env.requestId,
        sequenceNumber: ++env.sequenceNumber,
        timestamp: new Date(),
        message: message,
        env: {
          request: {
            method: request.method,
            url: request.url,
            headers: request.headers,
            body: request.body
          },
          response: {
            statusCode: response.statusCode,
            url: response.url,
            headers: response.headers,
            body: response.body
          }
        }
      };
      
      console.log('TRACE: ' + JSON.stringify(log));
    };
    env.trace = function(name, cb) {
      var start = +Date.now();
      cb();
      var message = 'Duration (' + name + '): ' + (+Date.now() - start) + 'ms';
      env.printTrace(name, message);
    };

    next(env);<commit_msg>Fixing response header logging in tracer.<commit_after>var uuid = require('node-uuid');

module.exports = function(addHandler) {
  addHandler('request', function(env, next) {
    env.requestId = uuid.v4();
    env.sequenceNumber = 0;
    env.printTrace = function(name, message) {
      var request = env.request;
      var response = env.response;
      var target = env.target;

      var log = {
        name: name,
        requestId: env.requestId,
        sequenceNumber: ++env.sequenceNumber,
        timestamp: new Date(),
        message: message,
        env: {
          request: {
            method: request.method,
            url: request.url,
            headers: request.headers,
            body: request.body
          },
          response: {
            statusCode: response.statusCode,
            url: response.url,
            headers: response._headers,
            body: response.body
          }
        }
      };
      
      console.log('TRACE: ' + JSON.stringify(log));
    };
    env.trace = function(name, cb) {
      var start = +Date.now();
      cb();
      var message = 'Duration (' + name + '): ' + (+Date.now() - start) + 'ms';
      env.printTrace(name, message);
    };

    next(env);
{'fraction_non_alphanumeric': 0.13165497317375155, 'fraction_numerical': 0.0016508460586050352, 'mean_word_length': 1.8088064889918887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1237093', 'n_tokens_mistral': 688, 'n_tokens_neox': 684, 'n_words': 154}