0

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?

vivekveeramani
  • 144
  • 1
  • 12

2 Answers2

0

I was able to find Google gcloud documentation regarding write identity SINK that could probably help you to get more information on how to construct the command, but the one that is focused to write identity is:

https://cloud.google.com/logging/docs/export/configure_export_v2#gcloud_3

Other than these options there is also gcloud-python which is provided by the cloud team. Though it seems like it's not up-to-date with beta apis, logging being one of them.

gcloud-python

gcloud cli command code:

gcloud logging sinks describe --format='value(writerIdentity)' <SINK_NAME>

Additional documentation:

Developers_Google

Cloud_google

Python_SDK

Logging_Sink

0

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

vivekveeramani
  • 144
  • 1
  • 12