-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Request Tracking #6323
Comments
I believe this is currently not possible. Whilst you can use a middleware to set a request id like so: import cuid from 'cuid';
const generateRequestId = () => cuid();
const app = express()
app.use((req, res, next) => {
req.requestId = generateRequestId()
next();
});
app.use(new ParseServer({ ...options })); Unfortunately you cannot access it from within the cloud functions. We'd be able to consider a PR - this section is roughly where a change would be made. We need to consider what |
Thanks @omairvaiyani for considering it. As a hack I can get the generated requestId in cloud function also with the below code
But the problem is not just getting requestId in cloud function but to forward that requestId in subsequent parse calls. |
Whilst this is not a direct fix for your problem, I tend to see the use of inter-server cloud function calls as an architectural problem. Ideally, as your codebase grows, you should aim to only use const doA = async (params, options) => {
const doBResponse = await doB({ foo: params.foo }, options);
return { outcome: doBResponse.outcome };
};
const doB = async (params, options) => {
const outcome = await _internalFunc(params.foo, options.sessionToken)
return { outcome };
};
const cloudFunctionWrapper = (func) => {
return async (request) => {
return await func(request.params, { sessionToken: request.user.getSessionToken() })
}
}
Parse.Cloud.define('doA', cloudFunctionWrapper(doA));
Parse.Cloud.define('doA', cloudFunctionWrapper(doB)); With this pattern, which can be infinitely further abstracted to suit your application's needs, can allow you to have a far greater degree of control in your application layer. If you're looking at request tracking, chances are you're scaling up - treat the Parse Cloud SDK as a support layer for your API, rather than the entire API itself. |
The above mentioned case was just an example, we don't actually call a cloud-function from another cloud-function. But if cloud-function saves some object then beforeSave and afterSave trigger doesn't have information about source of origin. |
is solving this issue also solves the problem with opentracing with parse-server as I need to have spans in every function because parse is not internally passing information about the function which made call to another function. I feel the feature I need is somehow related to what is reported by @yog27ray . If someone works on this feature can you also add some information related to which function made a call to another function. @omairvaiyani needs your views on it if this thing is feasible or not? |
I would say it's feasible but needs a substantial RFC as it covers many areas, not just functions. If this is a big use-case for your project/organisation, I'm sure we'd be very open to a well thought out discussion around what information should be captured and transmitted between cloud function calls, save hooks, etc. |
@omairvaiyani I don't have much information about the code base but as per my understanding in order to implement opentracing jaeger-client. I would suggest following changes In the system.
If the above proposed solution looks good then I can also create PR for the same. |
Alternatively we can just provide some option to get request headers in all hooks and option to pass new headers while making Parse.Cloud.run, save(), find(), first(), etc. Jaeger Integration can be done in the user who need it. |
You will be able to pass a context dictionary when you save an object: #6459. The context is accessible in beforeSave / afterSave. I can imagine this could be extended to cloud function calls in another PR, and gradually extended across all methods to a unified context. In such a context you could provide a request ID. The feature is expected to be included in the next parse server release. If you do a quick PR for cloud function calls (or what it is that you specifically need) you could get your feature very soon. |
What functionality do you want to achieve? If you want to expose Sent with GitHawk |
@mtrezza, Yes I missed query function will create PR for the same also. |
This is also (in some way) related to #6744 which introduces the new http header Worth mentioning that load balancers usually allow to append a trace ID http header to an incoming request, so that could also be used to trace internal calls by passing them on internally. For inspiration, you can take a look at AWS ELB or nginx how they augment the trace ID each time it passes through the load balancer. |
I am unable to track down the main start point of any api request made to parse-server.
For Example:
If I get some error while making query in User table defined Cloud function "A". I am unable to trace back wheather client started requested from Cloud function "A" or "B" or "C".
What I am looking is an option to pass requestId that I can trace back. Like I can pass sessionToken if I can also pass requestId along with the request options passed during
Parse.Cloud.run
orParseQuery.find
orParseQuery.findAll
orParseObject.save
. I can just log the requestId from option to trace back source of origin.The text was updated successfully, but these errors were encountered: