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
Not showing resource.labels.function_name
nor labels."execution_id"
#91
Comments
Actually, it's just occurred to me that const logMetadata = {
resource: {
type: 'cloud_function',
labels: {
function_name: process.env.FUNCTION_NAME ,
project: process.env.GCLOUD_PROJECT,
region: process.env.FUNCTION_REGION
},
},
}; ...and I'll have to get the |
Thanks for opening this issue. I agree with your assessment of the issue that you would need to supply the labels in question. I have re-opened this issue as a feature request since it would be good to determine if these labels should be applied automatically if/when available. However, it is good that, even if the labels are not applied automatically, they can still be applied manually to get the desired functionality. |
Thanks @DominicKramer , it'll be especially nice to see |
@DominicKramer : Is there any workaround to manually add |
Talking with the GCF team and after doing some experimentation, I have found that the following can be used to obtain the metadata requested (this code uses the preferred environment variables first): const logMetadata = {
resource: {
type: 'cloud_function',
labels: {
function_name: process.env.K_SERVICE || process.env.FUNCTION_NAME,
project: process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT,
region: process.env.GOOGLE_CLOUD_REGION || process.env.FUNCTION_REGION,
executionId: req.header('Function-Execution-Id')
},
},
}; That is, with experimentation, I found that the request header has the execution ID. However, I didn't see the use of the header to get the execution ID documented, and so it is not official supported. This is a viable solution, if you have access to the request object at the point where you are creating logs. |
PR #276 is open that addresses this issue. However, the PR does not contain code to auto-populate the execution id since the logger does not have access to the current request object. Further, this would be hard to get because a log statement need not be invoked in an execution path that involves a request object. |
We do have this capability through the |
@ofrobots That's a great point. For express users we can automatically include the |
@opyate I have an update in It looks, however, that for Node 6 and Node 8 uses of Google Cloud Functions, the function name metadata should be available in the logs via PR 400. Try the newest version of Also, in the GCP logs the |
@DominicKramer thanks, I'll wait for googleapis/nodejs-logging#400 to get released. |
@opyate thanks for your patience with us getting this out. I've looked at the cloud functions docs for triggering from Firestore, and I don't see a way to get |
We were looking at this more, and thought we could use the express middleware (PR #278) to add the Fortunately we thought of an easier approach for you. The |
I'm going to close this issue since |
Thanks, but the reason I want to use this package was to get structured logging. |
Still struggling to get the
https://cloud.google.com/functions/docs/monitoring/logging#writing_logs
Given that the official documentation actually suggests using something other than console.log, can this issue get re-opened? |
I would also like to use structured logging and not getting the execution_id with Winston. Would be great to have this re-opened. |
@opyate were you ever able to find a solution to this ? I've resorted to using winston to be able to set severity, but have now lost the labels that were pushed by CF by default |
+1 |
Environment details
@google-cloud/logging-winston
version: 0.9.0Steps to reproduce
Audit
entry, but withoutresource.labels.function_name
andlabels."execution_id"
I'd like to see my Winston log entry have these attributes as if I used regular
console.log
:The text was updated successfully, but these errors were encountered: