How to use the continuation-local-storage.getNamespace 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 alphagov / pay-selfservice / app / controllers / dashboard / dashboard-activity-controller.js View on Github external
try {
    const { fromDateTime, toDateTime } = getTransactionDateRange(period)

    const transactionsPeriodString = `fromDate=${encodeURIComponent(datetime(fromDateTime, 'date'))}&fromTime=${encodeURIComponent(datetime(fromDateTime, 'time'))}&toDate=${encodeURIComponent(datetime(toDateTime, 'date'))}&toTime=${encodeURIComponent(datetime(toDateTime, 'time'))}`

    logger.info(`[${correlationId}] successfully logged in`)

    if (isADirectDebitAccount(gatewayAccountId)) {
      // todo implement transaction list for direct debit
      return response(req, res, 'dashboard/index', Object.assign(model, {
        activityError: true
      }))
    }

    const namespace = getNamespace(clsXrayConfig.nameSpaceName)
    const clsSegment = namespace.get(clsXrayConfig.segmentKeyName)

    AWSXRay.captureAsyncFunc('ledgerClient_getTransactionSummary', function (subsegment) {
      LedgerClient.transactionSummary(gatewayAccountId, fromDateTime, toDateTime, { correlationId: correlationId })
        .then(result => {
          subsegment.close()
          response(req, res, 'dashboard/index', Object.assign(model, {
            activity: result,
            successfulTransactionsState: 'payment-success',
            fromDateTime,
            toDateTime,
            transactionsPeriodString
          }))
        })
        .catch((error, ledgerResponse) => {
          subsegment.close(error)
github otto-de-legacy / turing-microservice / turing-logging / lib / logger.js View on Github external
this.rewriters.push((level, msg, meta) => {
      const namespace = cls.getNamespace(config.get('turing:logging:namespace'));
      const request = namespace.get('request');
      const uuid = namespace.get('uuid');
      const metaFromConf = config.get('turing:logging:meta');

      if (uuid) {
        meta.uuid = uuid;
      }

      meta.caller = findCaller();

      if (request) {
        const headers = config.get('turing:logging:headers');
        headers.forEach((header) => {
          const value = request.headers[header];
          if (value) {
            meta[header] = value;
github alphagov / pay-selfservice / app / services / auth_service.js View on Github external
function deserializeUser (req, externalId, done) {
  const segment = new AWSXRay.Segment('deserialize')
  const namespace = getNamespace(clsXrayConfig.nameSpaceName)
  namespace.run(() => {
    namespace.set(clsXrayConfig.segmentKeyName, segment)
    AWSXRay.captureAsyncFunc('auth_service_deserializeUser', function (subSegment) {
      return userService.findByExternalId(externalId, req.headers[CORRELATION_HEADER] || '', subSegment)
        .then((user) => {
          segment.close()
          done(null, user)
        })
        .catch(err => {
          segment.close(err)
          logger.info(`[${req.correlationId}]: Failed to retrieve user, '${externalId}', from adminusers with statuscode: ${err.errorCode}`)
          done(err)
        })
    }, segment)
  })
}
github openzipkin / zipkin-js / packages / zipkin-context-cls / src / CLSContext.js View on Github external
constructor(namespace = 'zipkin') {
    this._session = getNamespace(namespace) || createNamespace(namespace);
    const defaultContext = this._session.createContext();
    this._session.enter(defaultContext);
  }
github EvaEngine / EvaEngine.js / src / services / namespace.js View on Github external
bind(...args) {
    return getNamespace(this.name).bind(...args);
  }
github openzipkin / zipkin-js / packages / zipkin / src / trace.js View on Github external
const {createNamespace, getNamespace} = require('continuation-local-storage');
const randomTraceId = require('./randomTraceId');
const Annotation = require('./annotation');
const TraceId = require('./TraceId');
const {now} = require('./time');
const {Some, None, fromNullable} = require('./option');

const trace = {};

const session = getNamespace('zipkin') || createNamespace('zipkin');
const defaultContext = session.createContext();
session.enter(defaultContext);

function State({id, terminal, tracers}) {
  this.id = id;
  this.terminal = terminal;
  this.tracers = tracers;
}
State.prototype.toString = function() {
  return `State(id=${this.id.toString()}, terminal=${this.terminal}, tracers=[${
    this.tracers.map(t => t.toString()).join(', ')
    }])`;
};

const defaultId = new TraceId({
  traceId: None,
github EvaEngine / EvaEngine.js / src / services / namespace.js View on Github external
get(key) {
    return getNamespace(this.name).get(key);
  }
github alphagov / pay-frontend / app / middleware / x_ray.js View on Github external
module.exports = (req, res, next) => {
  const namespace = getNamespace(clsXrayConfig.nameSpaceName)
  namespace.set(clsXrayConfig.segmentKeyName, req.segment)
  next()
}
github EvaEngine / EvaEngine.js / src / services / namespace.js View on Github external
set(key, value) {
    getNamespace(this.name).set(key, value);
    return this;
  }

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