Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having issues on aws.. #65

Open
walshe opened this issue May 13, 2021 · 0 comments
Open

having issues on aws.. #65

walshe opened this issue May 13, 2021 · 0 comments

Comments

@walshe
Copy link

walshe commented May 13, 2021

locally cls-hooked seems to be working fine. I have amiddleware:

``
app.use((req, res, next) => {

      //Create new CLS contect for each request
      //At this point CLS puts the new context in a map of contexts by current execution ID.
      session.run( () => {
        next();
      });
    })

I set some things further down in another middleware:

session.set("sub", req.auth.sub); if(req.headers['X-Amzn-Trace-Id']){ session.set('X-Amzn-Trace-Id', req.headers['X-Amzn-Trace-Id']); }

and I access it in a logging service:

const jsonFormatter = (logEntry) => {

  const session = getNamespace('session');
  
  const sub = session.get("sub");
  let json = (sub ) ? Object.assign({ sub: sub }, logEntry) : logEntry;
  
  const amazonTraceId = session.get('X-Amzn-Trace-Id')
  json = (amazonTraceId ) ? Object.assign({ 'X-Amzn-Trace-Id': amazonTraceId }, json) : json;

  logEntry[MESSAGE] = JSON.stringify(json); queotes etc
  return logEntry;

that works fine..

but on aws ecs/fargate I get an error on the session.get():

``
TypeError: Cannot read property 'get' of undefined

  | 2021-05-13T16:37:49.193+01:00 | at Format.jsonFormatter [as transform] (/usr/src/app/service/logging-service.js:25:23)
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant