python-3.xgoogle-cloud-logginggoogle-cloud-python

How to get writerIdentity for a given Sink using Cloud Logging Python SDK


I'm trying to get the writerIdentity for a given Log router Sink. I'm able to get it using the gcloud cli : gcloud logging sinks describe --format='value(writerIdentity)' <sink-name>

But for some reason the Python SDK equivalent (shown below) returns None for all my sinks:

from google.cloud import logging_v2 as logging
logging_client = logging.Client()
for i in logging_client.list_sinks(): 
    print(i, i.name, i.writer_identity)

Am I missing something?


Solution

  • For anyone running into this issue using Python SDK to retrieve writer identity I was missing a step. Apparently, while using the Python SDK we need to reload the sink configuration in order to get the writer identity. Following is the working solution:

    from google.cloud import logging_v2 as logging
    logging_client = logging.Client()
    for i in logging_client.list_sinks(): 
        i.reload()
        print(i, i.name, i.writer_identity)
    

    sink.reload source code