Search code examples
pythonlogginggoogle-cloud-platformstackdriver

GCP Stackdriver custom tags


I am working on an application that sends logs to GCP StackDriver. I want to put custom "tags" (or summary fields) natively on my log entry. I am looking for a solution that doesn't rely on defining custom summary fields in the console, as those are not permanent, and not project-wide.

I realized that some logger have tags displayed. For example, GCF logs will show its execution_id. Using the following snippet, I can verify that the tags displayed depend on the name of the logger:

from google.cloud import logging

client = logging.Client()

client.logger(name="custom").log_text("foobar", labels={"execution_id": "foo"})
client.logger(name="cloudfunctions.googleapis.com%2Fcloud-functions").log_text("foobar", labels={"execution_id": "foo"})

if you filter your logs on "foobar", you will see that only the second entry has "foo" as a tag. enter image description here

That tag matches the label.execution_id specified in the code. The problem is, I cannot add custom labels, if I add another label that is not execution_id, it is not displayed as a tag (but still found in the log body).

It looks like each monitored resources has its own set of tag, ie: BigQuery resources use protoPayload.authenticationInfo.principalEmail as tag. But I cannot find a way to specify my own resources.

Does anybody has some experience with that kind of issue?

Thanks in advance


Solution

  • I've filed a Feature Request on your behalf to the product team, they'll evaluate the possibility to implement the functionality that fits your use case, you can follow up on this PIT [1], where you will be able to receive further updates from the team as well.

    Keep in mind that there is no ETA, nor guarantee that this will be implemented. However, please feel free to ask for updates directly on the PIT, I would appreciate if you give my answer as accepted, if it was helpful for you.

    [1]https://issuetracker.google.com/172667238