How to send GCP logs to OpenObserve

Managing and analyzing logs effectively is crucial for any organization running applications on Google Cloud Platform (GCP). One powerful way to handle GCP logs is by sending them to OpenObserve via Google Cloud Pub/Sub via Log Router Sink. This allows you to create real-time log processing workflows and integrate logs with various downstream systems. In this blog post, we will walk through the steps to set up a Log Router Sink to send GCP logs to Pub/Sub and create a subscription to the topic with a push endpoint.
Google cloud logs -> Log router sink -> Pub/Sub -> OpenObserve
Before we begin, ensure you have the following:
First, we need a Pub/Sub topic to which the logs will be sent. You can create a Pub/Sub topic using the GCP Console or the gcloud
command-line tool.
gcloud pubsub topics create my-log-topic
Next, we need to create a subscription to the Pub/Sub topic. This subscription will have a push endpoint that sends logs to OpenObserve.
Get OpenObserve GCP endpoint URL from the ingestion page. Here is a screenshot:
Now create the subscription:
gcloud pubsub subscriptions create my-log-subscription \
--topic=my-log-topic \
--push-endpoint=https://api.openobserve.ai/gcp/myorg/mystream/_sub?API-Key=aBJhYkqhdEBvcub2JzZXJ2ZS5haTp0YUtKZEJRbVc1ZkNLSnFS
A Log Router Sink will route logs from Cloud Logging to the Pub/Sub topic. To create a sink, follow these steps:
logName: "projects/YOUR_PROJECT_ID/logs/"
You can also create a sink using the gcloud
tool:
gcloud logging sinks create my-log-sink \
pubsub.googleapis.com/projects/YOUR_PROJECT_ID/topics/my-log-topic \
--log-filter='logName: "projects/YOUR_PROJECT_ID/logs/"'
The Log Router needs permission to publish messages to the Pub/Sub topic. This involves granting the Pub/Sub Publisher role to the Log Router service account.
serviceAccount:cloud-logs@YOUR_PROJECT_ID.iam.gserviceaccount.com
gcloud pubsub topics add-iam-policy-binding my-log-topic \
--member=serviceAccount:cloud-logs@YOUR_PROJECT_ID.iam.gserviceaccount.com \
--role=roles/pubsub.publisher
If you have all set up correctly, logs from GCP should now be sent to the Pub/Sub topic and pushed to the OpenObserve.
By following these steps, you have successfully set up a Log Router Sink to send GCP logs to Pub/Sub and created a subscription with a push endpoint to OpenObserve. This integration allows you to create robust log processing pipelines and integrate with various other GCP services and third-party tools.
Happy logging!
Feel free to ask any questions or share your thoughts in the comments below. If you found this guide helpful, don’t forget to share it with your network!