-
Notifications
You must be signed in to change notification settings - Fork 34
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
Trace logs not populating in Gen 2 Cloud Functions #697
Comments
Testing as the documentation mentions, the trace is the same for all the executions, is there a way to get traces in a dynamically way? |
That is part of what we're unable to determine. Gen 1 CFs took care of this for us automatically. We think it is possible to grab the value in |
Can you share the code that worked in gen1? Was it also in Node18? I was testing this and the only solution that works for me also works in gen2. It is based on googleapis/cloud-trace-nodejs#1076:
It is required to call tracer.runInRootSpan in each function. Note that this works for event functions as well - you can access trace context through |
Hi, thanks for getting back to me on this. In our gen1 cloud functions, we are running in Node18 as well but do not have any special configuration. It worked for us out of the box with just the basic bunyan logger setup. No need to even require trace-agent in our gen1 functions. I tried out your code and got positive results as well, so thank you very much! We will continue testing with your recommendations and see how it goes. I do have a question about the trace-agent options. When you say |
Oh do you mean a setup like this:
? I see that this in fact adds trace to the logs in gen1, but not in gen2. The reason for that is simple: the logger here does not care about traces on its own and does not use Since gen2 allows concurrent requests it is not possible to deduce which request the log relates to so it sends them to cloud logging without it, therefore it is necessary to set it up in the code. I wrote the previous snippet to show how to manually work with Instead maybe just set the trace manually using a child logger, again in a similar way as in that winston issue:
Just to answer your question the recommendation was from the linked GitHub issue in the gist. The goal here was to avoid buffering as cloud functions can limit the CPU when there are no requests, which would delay or even break some API calls. |
Hello, I tested the gen2 traces with your original suggestion and did not run into any problems tracing concurrent requests. I made a function with a timeout and then hit the function several times while the first request was still processing. All the requests were started concurrently and assigned unique traceIds that I was able to use in the GCP logging. I did not try the child logger tracing because of that, but do you think that is still necessary? I am still testing the trace-agent usage for event driven functions and hope to get back to you about that soon! Thanks! |
Oh one thing I forgot to mention. When we have identical or very similar requests come in, it seems like theyre assigned the same trace Id. |
Ok, I agree (and also tested) that the solution with using trace-agent works as it automatically keeps track of all the concurrent executions and identifies which context each one belongs to (which was my concern that it would fail to). However you may want to consider the second solution because "The same trace" issue is a separate issue and is not related to this library at all so I would suggest to keep that discussion in the GCP support case. In short Cloud Functions will only assign the trace id if it is not already given in the header. Please check if whatever client is calling the function is not sending any of those headers. For instance if the client has @google-cloud/trace-agent running then it will automatically set those headers when calling any API . |
Hi @jeffw-bicycle , regarding the same trace Id issue, when forcing requests to be traced,
Here TRACE_ID is expected to be unique between different requests. Refer How to force a request to be traced for more details. So I would suggest to specify different TRACE_ID in Also, I am wondering with the trace-agent runInRootSpan solution, are you still running into trace missing issues for Gen2 functions? |
Closing the issue as Logger doesn't provide special handling for traceId between gen1 and gen2. Trace logs can still be enabled in gen2 by setting up trace context in code. It is also suggested to set up different |
Hello, we recently upgraded a GCP Cloud Function from Gen 1 to Gen 2 and our bunyan logging no longer contains trace logs when viewing in Log Explorer. This was working out of the box for us in Gen 1. Gen 1 logs would contain a trace ID like
trace: "projects/ourproject/traces/12345abcde
, but the trace property doesnt show up in Gen 2 logs.We have tried implementing
@google-cloud/trace-agent
as described in the documentation here to no effect.Environment details
@google-cloud/logging-bunyan
version: 4.2.2@google-cloud/trace-agent
version: 7.1.2firebase-functions
version: 4.4.0Steps to reproduce
NOTE: It looks like
nodejs-logging-winston
had a similar issue in the past googleapis/nodejs-logging-winston#287The text was updated successfully, but these errors were encountered: