node.jsexpressauthenticationgrafanagrafana-loki

Connect pino-loki to Grafana (basic authentication)


I'm using the pino-loki library in my express app. I'm trying to send the logs to grafana, but I'm getting authentication errors using basicAuth.

in Grafana a loki data source was auto-generated for me grafanacloud-myapi-logs enter image description here

(this is also where I get the host url: https://logs-prod-006.grafana.net. Does this look right?)

where I have added a service account that I created and given admin permissions to: enter image description here

Then, in the Grafana dashboard I go to service accounts and select "MyApi" with ID "sa-1-myapi" and generate a token enter image description here

Finally, I use this service account id and token to auth with

{
            username: 'sa-1-myapi',
            password: 'generated_token'
}

But I'm getting a 401 response- enter image description here

I'm completely stuck here. Does anyone know what I'm doing wrong? How can I authenticate with pino-loki?


Solution

  • Figured it out.

    1.) Go to your org page. To go there login to https://grafana.com/products/cloud/ and it'll redirect you to https://grafana.com/orgs[yourorg]

    2.) On the left pane under GRAFANA CLOUD, click your application

    3.) Click Loki "send logs", it'll send you to this page where you can generate an api key

    generate api key btn

    4.) Generate the api key, it should give you the correct username too. Make sure it has the scope to write logs (in Grafana Data Source settings). Done