Help with Global variable '${__user.login}'

I´m trying to use the Global variable ‘${__user.login}’ in the query editor and it doesn´t rule. I actually use v9.1.2 Grafana version.

When I use a login like “Name”, Query do exactly I want, but if login is “” Query doesn´t give me any result. I’ve tried with ‘${}’ and nothing.

I’m creating a new user with the same ‘Name’, ‘Email’, ‘Username’ and ‘Password’, like “” in order to prove different options of the Global variable ‘$__user’ . How could I use an email in a expression in my query? Where is my mistake?

My query is: SELECT “MID”, “CID” FROM “CID_Table” WHERE CID=‘${__user.login}’

Thanks for any help


I’ve changed my query to a new one:
SELECT “MID”, “CID” FROM “CID_Table” WHERE CID =~ /${__user.login}/

Is there a known issue for using the user global variable inside a loki query?

when querying
| RecipientEmail = ${__user.login}
the query inspector shows:
| RecipientEmail = 1

I am expecting ${__user.login} to equal the current user’s email.

${} is the ID of the current user. ${__user.login} is the login handle of the current user. ${} is the email for the current user.

Hello, I’ve tried using both user.login and and get the same behavior.
After writing out my query via code and then click on the query builder,
My Loki query gets truncated from

… | RecipientEmail = ‘${__user.login}’


Label: RecipientEmail
Operator: =
Value: ${__user}

${} is returned in the query instpector


all return 1 in the query inspector

what version of grafana are you on?

Othern than I see the rest because they have been filled in for that user in settings.

@yosiasz thanks for the screenshot! am using 9.3.6

I am able to use ${} as Panel title (was unaware I could do this!)

But when i use the variable in my Loki query… it still does not filter my data

(it does filter my data when i enter my email as a string)

1 Like

What does Loki documentation sayabout filters using variables? Could be a bug in Loki

Please show us how you are using it?

Grafana Loki Template Documentation states:

# Use interval and range variables
You can use some global built-in variables in query variables: `$__interval`, `$__interval_ms`, `$__range`, `$__range_s`, and `$__range_ms`.

For more information, refer to [Global built-in variables]

Loki docs do not state that we can use the built in $__user global variable. It explicitly states the one can use the interval and range vars.

In my loki query, I am able to see that the following global variables are available:

$__from and $__to

The following global variables all render my


I have added email logs to grafana loki and I am trying to create a dashboard that only displays the current user’s email logs. My query looks like this:

{job="my-email-logs"} | json | Recipient=`${}`
1 Like

Hey there. Did you figure out the solution?

I’m also trying to use ${__user.login} variable with Loki but it’s not really working as I expected.

Since we do not have access to your grafana we can’t be sure what its not working means

You need quotes around it. Try ‘${__user.login}’