How to use the continuation-local-storage.createNamespace function in continuation-local-storage

To help you get started, we’ve selected a few continuation-local-storage 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 logerzhu / simple-graphql / src / sequelize / __tests__ / sequelize.js View on Github external
// @flow
import Sequelize from 'sequelize'
import cls from 'continuation-local-storage'

const namespace = cls.createNamespace('my-db-namespace')
Sequelize['useCLS'](namespace)

const sequelize = new Sequelize('clinic', 'tester', 'password', {
  host: 'localhost',
  dialect: 'sqlite',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },
  // SQLite only
  storage: ':memory:',
  logging: (str) => console.log(str),
  define: {
    underscored: true,
github motdotla / node-lambda / lib / main.js View on Github external
context.getRemainingTimeInMillis = () => {
      const currentTime = new Date()
      return timeout - (currentTime - startTime)
    }

    // The following three functions are deprecated in AWS Lambda.
    // Since it is sometimes used by other SDK,
    // it is a simple one that does not result in `not function` error
    context.succeed = (result) => console.log(JSON.stringify(result))
    context.fail = (error) => console.log(JSON.stringify(error))
    context.done = (error, results) => {
      console.log(JSON.stringify(error))
      console.log(JSON.stringify(results))
    }

    const nameSpace = createNamespace('AWSXRay')
    nameSpace.run(() => {
      nameSpace.set('segment', new AWSXRay.Segment('annotations'))
      const result = handler(event, context, callback)
      if (result != null) {
        Promise.resolve(result).then(
          resolved => {
            console.log('Result:')
            console.log(JSON.stringify(resolved))
          },
          rejected => {
            console.log('Error:')
            console.log(rejected)
          }
        )
      }
    })
github strongloop / loopback / server / current-context.js View on Github external
loopback.createContext = function(scopeName) {
    // Make the namespace globally visible via the process.context property
    process.context = process.context || {};
    var ns = process.context[scopeName];
    if (!ns) {
      ns = cls.createNamespace(scopeName);
      process.context[scopeName] = ns;
      // Set up loopback.getCurrentContext()
      loopback.getCurrentContext = function() {
        return ns && ns.active ? ns : null;
      };

      chain(juggler);
      chain(remoting);
    }
    return ns;
  };
github yurishkuro / opentracing-tutorial / nodejs / lesson04 / solution / hello-context.js View on Github external
var ns = require('continuation-local-storage').createNamespace('myNameSpace');
require('cls-bluebird')( ns );
// Promise is now patched to maintain CLS context

const assert = require('assert');
const initTracer = require('../../lib/tracing').initTracer;
const request = require('request-promise');
const { Tags, FORMAT_HTTP_HEADERS } = require('opentracing');

function sayHello(helloTo, greeting) {

    const span = tracer.startSpan('say-hello');
    span.setTag('hello-to', helloTo);

    span.setBaggageItem('greeting', greeting)

    ns.run( () => {
github cesardeazevedo / sails-hook-sequelize-blueprints / test / fixtures / sampleapp / api / hooks / sequelize / index.js View on Github external
module.exports = function(sails) {
  global['Sequelize'] = require('sequelize');
  Sequelize.cls = require('continuation-local-storage').createNamespace('sails-sequelize-postgresql');
  return {
    initialize: function(next) {
      this.initAdapters();
      this.initModels();

      var connection, migrate, sequelize;
      sails.log.verbose('Using connection named ' + sails.config.models.connection);
      connection = sails.config.connections[sails.config.models.connection];
      if (connection == null) {
        throw new Error('Connection \'' + sails.config.models.connection + '\' not found in config/connections');
      }
      if (connection.options == null) {
        connection.options = {};
      }
      connection.options.logging = sails.log.verbose; //A function that gets executed everytime Sequelize would log something.
github ratneshsinghparihar / Node-Data / security / auth / principalContext.ts View on Github external
static getSession() {
        if (PrincipalContext.session != null && PrincipalContext.session != 'undefined') {
            //cls = require('continuation-local-storage').getNamespace;
            PrincipalContext.session = cls.getNamespace('session');
        } else {
            console.log('creating session from principal context');
            //cls = require('continuation-local-storage').createNamespace;
            PrincipalContext.session = cls.createNamespace('session');
        }
        return PrincipalContext.session;
    }
github eclipse-iofog / Controller / src / utils / sequelize.js View on Github external
*  *
 *  * This program and the accompanying materials are made available under the
 *  * terms of the Eclipse Public License v. 2.0 which is available at
 *  * http://www.eclipse.org/legal/epl-2.0
 *  *
 *  * SPDX-License-Identifier: EPL-2.0
 *  *******************************************************************************
 *
 */

const Sequelize = require('sequelize');
const appConfig = require('./../config');
const cls = require('continuation-local-storage');
const logger = require('./../logger');

let namespace = cls.createNamespace('fog-controller-namespace');

Sequelize.useCLS(namespace);

const Op = Sequelize.Op;
const operatorsAliases = {
  $eq: Op.eq,
  $ne: Op.ne,
  $gte: Op.gte,
  $gt: Op.gt,
  $lte: Op.lte,
  $lt: Op.lt,
  $not: Op.not,
  $in: Op.in,
  $notIn: Op.notIn,
  $is: Op.is,
  $like: Op.like,
github aws / aws-xray-sdk-node / packages / core / lib / context_utils.js View on Github external
enableAutomaticMode: function enableAutomaticMode() {
    cls_mode = true;
    cls.createNamespace(NAMESPACE);

    logger.getLogger().debug('Overriding AWS X-Ray SDK mode. Set to automatic mode.');
  },
github logv / superfluous / superfluous / core / server / context.js View on Github external
* @submodule Server
 */

"use strict";

var domain = require('domain');

var __defaults = {};
var package_json = require_core("../package.json");
var config = require_core("server/config");
var app_name = package_json.name;
var USE_CLS = config.use_cls;

var ns;
if (USE_CLS) {
  ns = require("continuation-local-storage").createNamespace('superfluous');
}

var __id = 0;
module.exports = function(key, val) {
  if (typeof val !== "undefined") {
    module.exports.get()[key] = val;
  } else {
    return module.exports.get()[key];
  }
};

var context = module.exports;
_.extend(module.exports, {
  /**
   * Sets the current context in use
   *
github stellar-deprecated / stex / lib / initializers / cls.js View on Github external
Initializer.add('startup', 'stex.cls', ['stex.config'], function(stex) {
  var namespaceName = stex.conf.get('cls-namespace') || "org.stellar.stex";
  var namespace = createNamespace(namespaceName);
  patchBluebird(namespace);

  stex.cls = {
    get: function(name) {
      var namespace = getNamespace(namespaceName);
      return namespace.get(name);
    },
    getNamespace: function () {
      return getNamespace(namespaceName);
    }
  }
});

continuation-local-storage

userland implementation of https://github.com/joyent/node/issues/5243

BSD-2-Clause
Latest version published 7 years ago

Package Health Score

74 / 100
Full package analysis