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 “name@name.es” Query doesn´t give me any result. I’ve tried with ‘${__user.email}’ and nothing.

I’m creating a new user with the same ‘Name’, ‘Email’, ‘Username’ and ‘Password’, like “name@name.es” 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

Solved!

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

hello,
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.

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

Hello, I’ve tried using both user.login and user.email 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}’

to

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

${__dashboard.name} is returned in the query instpector

${__user.id}
${____user.email}
${____user.login}

all return 1 in the query inspector

what version of grafana are you on?

Othern than user.id 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 ${__user.email} 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:

$__dashboard
$__from and $__to
$__interval
$__interval_ms
$__org
$__user 
$__user.id
$__range

The following global variables all render my user.id:

$__user.email
$__user.login

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=`${__user.email}`
1 Like