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

I am unable to find the ctx arguments here where in I am trying to bind the context from my end #5

Closed
kirankdeveloper opened this issue Jun 27, 2019 · 11 comments

Comments

@kirankdeveloper
Copy link

ns.bindEmitter(ctx.req)

@kirankdeveloper
Copy link
Author

I am unable to find the ctx arguments here where in I am trying to bind the context from my end:
Code snippet I am using:

app.use(function* (next) {
let koaMiddleWare = rTracer.koaMiddleware();
koaMiddleWare.bind(this.request.ctx, arguments);
yield koaMiddleWare;
yield next;
});

@puzpuzpuz
Copy link
Owner

Could you describe what you're trying to achieve with this wrapper generator function? A sample script would also help.

@aigoncharov
Copy link
Collaborator

@kirankdeveloper could you also provide a stack trace?

@kirankdeveloper
Copy link
Author

@keenondrums my library only accept the generator function so i have to use this way now somehow i am able to pass context to koaMiddleware function. This is my code now.

let koaMiddleWare = rTracer.koaMiddleware({
useHeader: true,
headerName: 'test-header'
});
yield koaMiddleWare(this.request.ctx, next);

However now my next issue is i want to access request id in another file call log.js which doesn't have access to request object. I am reading like this const requestId = rTracer.id(); but requestd is undefined here..

I think cls context losing somewhere because of that i am not able to get it. could you please guide me more about this.

@puzpuzpuz
Copy link
Owner

@kirankdeveloper if you're using Koa, then app.use() should accept the middleware from cls-rtracer as is (see this doc section):

app.use(rTracer.koaMiddleware({
  useHeader: true,
  headerName: 'test-header'
})

You can also check this sample for a more complete example.

@kirankdeveloper
Copy link
Author

@puzpuzpuz I am using the older version of koa and for me if I try that way it is giving me an error that it expects generator function. rtracer.koaMiddleware returns a Promise so I am trying as following

app.use(function* (next) {
let koaMiddleWare = rTracer.koaMiddleware({
useHeader: true,
headerName: 'test-header'
});
yield koaMiddleWare(this.request.ctx, next);
});

This also seems to be working fine however I am unable to receive const rid = rTracer.id() on integration with my loggers

@rishikapadia1
Copy link

@puzpuzpuz Looks like this library is not supported for an older version of Koa, Is there any hack which I can try to make this library work on older Koa (1.1.2)?

@puzpuzpuz
Copy link
Owner

@kirankdeveloper I see. Which version of Koa are you using?

@rishikapadia1 At the moment only Koa v2 is supported. But if there is a demand for Koa v1 support, I can implement it. Going to create a separate issue for this enhancement.

@puzpuzpuz puzpuzpuz mentioned this issue Jun 29, 2019
@rishikapadia1
Copy link

@puzpuzpuz We (I and @kirankdeveloper) upgraded koa library and this is working great, you can close or resolve this issue. Thanks for your quick response.

@puzpuzpuz
Copy link
Owner

@kirankdeveloper @rishikapadia1 glad that you found a workaround. In any case, there is already the 1.2.0 release that include Koa v1 support.

@kirankdeveloper
Copy link
Author

@puzpuzpuz Thank you for quickly responding on this. Nicely done!

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

4 participants