How to use the tracing.addAsyncListener function in tracing

To help you get started, we’ve selected a few tracing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graalvm / graaljs / test / simple / test-asynclistener-error-throw-in-error.js View on Github external
function runChild() {
  var cntr = 0;

  var key = tracing.addAsyncListener({
    error: function onError() {
      cntr++;
      throw new Error('onError');
    }
  });

  process.on('unhandledException', function() {
    // Throwing in 'error' should bypass unhandledException.
    process.exit(2);
  });

  process.on('exit', function() {
    // Make sure that we can still write out to stderr even when the
    // process dies.
    process._rawDebug(checkStr);
  });
github graalvm / graaljs / test / simple / test-asynclistener-run-error-once.js View on Github external
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var net = require('net');
var tracing = require('tracing');

var errMsg = 'net - error: server connection';
var cntr = 0;
var al = tracing.addAsyncListener({
  error: function(stor, er) {
    cntr++;
    process._rawDebug('Handling error: ' + er.message);
    assert.equal(errMsg, er.message);
    return true;
  }
});

process.on('exit', function(status) {
  tracing.removeAsyncListener(al);

  console.log('exit status:', status);
  assert.equal(status, 0);
  console.log('cntr:', cntr);
  assert.equal(cntr, 1);
  console.log('ok');
github graalvm / graaljs / test / simple / test-asynclistener-remove-inflight.js View on Github external
var common = require('../common');
var assert = require('assert');
var tracing = require('tracing');

var set = 0;
var asyncNoHandleError = {
  before: function() {
    set++;
  },
  after: function() {
    set++;
  }
}

var key = tracing.addAsyncListener(asyncNoHandleError);

process.nextTick(function() { });

tracing.removeAsyncListener(key);

process.on('exit', function(code) {
  // If the exit code isn't ok then return early to throw the stack that
  // caused the bad return code.
  if (code !== 0)
    return;

  // Calling removeAsyncListener *after* a callback is scheduled
  // should not affect the handler from responding to the callback.
  assert.equal(set, 2);
  console.log('ok');
});
github graalvm / graaljs / test / simple / test-asynclistener-remove-before.js View on Github external
var common = require('../common');
var assert = require('assert');
var tracing = require('tracing');
var set = 0;

var asyncNoHandleError = {
  before: function() {
    set++;
  },
  after: function() {
    set++;
  }
}

var key = tracing.addAsyncListener(asyncNoHandleError);

tracing.removeAsyncListener(key);

process.nextTick(function() { });

process.on('exit', function(code) {
  // If the exit code isn't ok then return early to throw the stack that
  // caused the bad return code.
  if (code !== 0)
    return;

  // The async handler should never be called.
  assert.equal(set, 0);
  console.log('ok');
});
github graalvm / graaljs / test / simple / test-asynclistener-error-throw-in-before.js View on Github external
var once = 0;

var results = [];
var handlers = {
  before: function() {
    throw 1;
  },
  error: function(stor, err) {
    // Error handler must be called exactly *once*.
    once++;
    assert.equal(err, 1);
    return true;
  }
}

var key = tracing.addAsyncListener(handlers);

var uncaughtFired = false;
process.on('uncaughtException', function(err) {
  uncaughtFired = true;

  // Process should propagate error regardless of handlers return value.
  assert.equal(once, 1);
});

process.nextTick(function() { });

tracing.removeAsyncListener(key);

process.on('exit', function(code) {
  // If the exit code isn't ok then return early to throw the stack that
  // caused the bad return code.
github graalvm / graaljs / test / simple / test-asynclistener-error-throw-in-after.js View on Github external
var once = 0;

var results = [];
var handlers = {
  after: function() {
    throw 1;
  },
  error: function(stor, err) {
    // Error handler must be called exactly *once*.
    once++;
    assert.equal(err, 1);
    return true;
  }
}

var key = tracing.addAsyncListener(handlers);

var uncaughtFired = false;
process.on('uncaughtException', function(err) {
  uncaughtFired = true;

  assert.equal(once, 1);
});

process.nextTick(function() { });

tracing.removeAsyncListener(key);

process.on('exit', function(code) {
  // If the exit code isn't ok then return early to throw the stack that
  // caused the bad return code.
  if (code !== 0)
github graalvm / graaljs / test / simple / test-asynclistener-error-throw-in-before-multiple.js View on Github external
}

var handlers1 = {
  before: function() {
    throw 2;
  },
  error: function(stor, err) {
    // Must catch *other* handlers throw by error callback.
    assert.equal(err, 1);
    once++;
    return true;
  }
}

var listeners = [
  tracing.addAsyncListener(handlers),
  tracing.addAsyncListener(handlers1)
];

var uncaughtFired = false;
process.on('uncaughtException', function(err) {
  uncaughtFired = true;

  // Both error handlers must fire.
  assert.equal(once, 2);
});

process.nextTick(function() { });

for (var i = 0; i < listeners.length; i++)
  tracing.removeAsyncListener(listeners[i]);
github graalvm / graaljs / test / simple / test-asynclistener-error-net.js View on Github external
error: function(value, er) {
    var idx = errorMsgs.indexOf(er.message);
    caught++;

    process._rawDebug('Handling error: ' + er.message);

    if (-1 < idx)
      errorMsgs.splice(idx, 1);
    else
      throw new Error('Message not found: ' + er.message);

    return true;
  }
};

var listener = tracing.addAsyncListener(callbacksObj);

process.on('exit', function(code) {
  tracing.removeAsyncListener(listener);

  if (code > 0)
    return;

  if (errorMsgs.length > 0)
    throw new Error('Errors not fired: ' + errorMsgs);

  assert.equal(caught, expectCaught);
  process._rawDebug('ok');
});


// Net
github graalvm / graaljs / test / simple / test-asynclistener-remove-in-before.js View on Github external
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var tracing = require('tracing');
var done = false;
var callbacks = {
  before: function() {
    tracing.removeAsyncListener(listener);
  },
  after: function() {
    done = true;
  }
};

var listener = tracing.addAsyncListener(callbacks);

process.nextTick(function() {});

process.on('exit', function(status) {
  tracing.removeAsyncListener(listener);
  assert.equal(status, 0);
  assert.ok(done);
});
github graalvm / graaljs / test / simple / test-asynclistener-remove-inflight-error.js View on Github external
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var tracing = require('tracing');

var set = 0;
var asyncNoHandleError = {
  error: function() {
    set++;
  }
}

var key = tracing.addAsyncListener(asyncNoHandleError);

process.nextTick(function() {
  throw 1;
});

tracing.removeAsyncListener(key);

var uncaughtFired = false;
process.on('uncaughtException', function() {
  uncaughtFired = true;

  // Throwing should call the error handler once, then propagate to
  // uncaughtException
  assert.equal(set, 1);
});

tracing

A placeholder for the tracing module in core

MIT
Latest version published 11 years ago

Package Health Score

40 / 100
Full package analysis

Popular tracing functions