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

Allowing filtering/formatting of Stackdriver logs #17

Closed
joshburkart opened this issue Mar 15, 2018 · 6 comments
Closed

Allowing filtering/formatting of Stackdriver logs #17

joshburkart opened this issue Mar 15, 2018 · 6 comments
Assignees
Labels
api: logging Issues related to the googleapis/python-logging API. backend priority: p3 Desirable enhancement or fix. May not be included in next release. type: docs Improvement to the documentation for an API.
Milestone

Comments

@joshburkart
Copy link

Hello,

I'm using the instructions here to send Python logging module logs to Stackdriver. Thanks for making this so easy! However, doing this naively seems to make all logs from potentially many jobs/VMs/etc. get merged together in the Stackdriver UI. When I filter to e.g. a specific VM, none of the logs show up (screenshot) -- I have to set the filtering to "Global" to see them (screenshot). Am I doing something wrong?

Also, what about logging things like files, line numbers, etc.? Is this possible? Does Stackdriver respect formatting I apply using the Python logging API? What about automatic links to files in connected code repos etc. -- any info available on that?

Thanks!

@tseaver
Copy link
Contributor

tseaver commented Mar 16, 2018

@liyanhui1228 Can you point @joshburkart in the right direction?

@joshburkart
Copy link
Author

I figured this out (I think) -- I now make calls to the metadata endpoint to determine info about the current VM, then pass these as labels when making logging handlers. Rough code snippet in case it's useful to someone:

import logging as pylogging

from google.cloud import logging as cloudlogging

...

handler = cloudlogging.handlers.CloudLoggingHandler(
    <stackdriver_client>,
    resource=cloudlogging.resource.Resource(
        # See e.g. https://cloud.google.com/monitoring/api/resources
        # for more info on codified Stackdriver "Resources".
        type='gce_instance',
        labels=<gce_instance labels retrieved from metadata endpoint>,
    ),
    labels=<any extra labels>,
)

logger = pylogging.getLogger('whatever')
logger.addHandler(handler)

(I think this should be added to the documentation or something, though...)

@tseaver
Copy link
Contributor

tseaver commented Mar 26, 2018

@liyanhui1228 I'm not sure where such an example should go: who manages the snippets / examples used in the cloud.google.com docs?

@tseaver
Copy link
Contributor

tseaver commented Oct 18, 2018

@dazuma Can you help direct this to the right target for updating the API docs?

@tseaver
Copy link
Contributor

tseaver commented Dec 5, 2018

@JustinBeckwith, @theacodes can either of you point me to the person / team responsible for managing the cloud.google.com/logging docs samples?

@plamut plamut transferred this issue from googleapis/google-cloud-python Feb 5, 2020
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/python-logging API. label Feb 5, 2020
@plamut plamut added type: docs Improvement to the documentation for an API. backend labels Feb 5, 2020
@daniel-sanche daniel-sanche added this to the v2.4.0 milestone Feb 4, 2021
@daniel-sanche daniel-sanche self-assigned this Feb 5, 2021
@daniel-sanche daniel-sanche added the priority: p3 Desirable enhancement or fix. May not be included in next release. label Feb 5, 2021
@daniel-sanche
Copy link
Contributor

As of #200, the resource should be auto-detected for each GCP environment. It sounds like that was the ask for this issue, so I'll close this. Feel free to re-open if there are any remaining concerns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/python-logging API. backend priority: p3 Desirable enhancement or fix. May not be included in next release. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

No branches or pull requests

6 participants