← Back to Guides
Profile image for Dan Ambrose

By Dan Ambrose

Published 17th April 2023

Send logs to Loki on Grafana Cloud from Northflank

Sending your Northflank logs to Grafana Cloud or any self-hosted Loki instance is simple. This guide will take you through the steps to integrate your Loki instance with Northflank.

This guide is targeted at Grafana Cloud, but you can add a self-hosted instance of Loki by following similar steps. Specific considerations for self-hosted instances are noted at the end of the guide.

Create your stack on Grafana Cloud

If you haven’t already, you’ll need to create your Grafana Cloud Stack in your Grafana Cloud dashboard.

Create a new Grafana Cloud Stack

The region can’t be changed once created. If possible, you should consider which region your Northflank workloads are running in and try to co-locate your Grafana Cloud Stack to reduce latency.

Create your Access Policy

You need to create an access policy for Northflank to be able to write logs to Grafana Cloud. Close the stack creation window and navigate to Access Policies under the security menu.

Creating a new access policy for Grafana Cloud

Create a new access policy and give it the logs write scope only.

After you have created the access policy, add a new token and save it somewhere secure.

Creating a new token on Grafana Cloud

Grafana Data Source

To add the log sink to Northflank, you need to get the URL and username for the Grafana Data Source.

On the Grafana Stack dashboard, click Details on the Loki card and note your URL and username, you will need these in the next step.

Viewing details for Loki on Grafana Cloud

Create your Loki sink on Northflank

Follow this link or navigate to the log sinks page in your team or user account settings and add a log sink.

Enter a recognisable name for the sink and select Loki as the sink type.

Fill in the fields with your corresponding information from Grafana Cloud, enter the URL and user from your Loki instance details. The password is your access policy token that you generated earlier.

Creating a new Loki log sink on Northflank for Grafana Cloud

You can target specific projects to forward logs from, and only containers running in the selected projects will have their logs forwarded, or leave this deselected to forward all logs from your account.

You can additionally forward logs from a linked CDN (like Fastly) or network mesh logs.

View your logs

Before your log sink is created Northflank tries to send a log line to your Loki instance to verify the credentials are correct. This appears as a log line consisting of validating log sink credentials.

Go back to your cloud stack dashboard and click Launch on Grafana.

Then click the Explore compass from the sidebar and select Loki as your data source to query using the dropdown.

Using the Query Builder, you should see the host label with value Northflank.

Exploring Northflank logs in Loki on Grafana Cloud

Logs from Northflank are labelled to help identify where log events come from so you can create queries and alerts for your Northflank hosted workloads.

A simple way to view all your logs from Northflank is to create a query with Host = “Northflank”.

Northflank log entries in Loki on Grafana Cloud

Building queries

To find out more about the Loki Query Logs, look at the LogQL docs.

Self-hosted Loki

Setting up your self hosted Loki is straightforward. Make sure your Loki instance is publicly exposed and then create your log sink with your Loki endpoint.

By default, Loki doesn’t come with any native authentication for incoming HTTP requests. Northflank supports Basic HTTP authentication and will add your credentials to the request headers. This is left optional but is recommended.

Update your log sink

If you want to modify your sink after creation, navigate to the log sink list and click on the sink to view its details.

You can update the project targets and sink data as well as pause/resume the sink.

Have questions or feedback? You can always reach out to our team.

Share this article with your network