Tempo: link logs with traceid

Hey there,

can someone explain me how I get this Button:

I have the traceid in my scraped logs. This traces are also in tempo but somehow Grafana won’t detect the connection and doesn’t display this button.

Thanks Tom

Hi :wave: You can achieve this by configuring a derived field in the Loki datasource.

Check out the Grafana docs: Loki | Grafana Labs

1 Like

Thanks again :slight_smile:

Can you tell me why it looks like a placeholder and not a value when I deploy it via grafana helmchart?

Clicking the tempo button then results in tempo opening without a query.

image

If I write the same value manually in this field it works properly:
image

datasources = [
            {
              name      = "Loki"
              type      = "loki"
              uid       = "loki"
              url       = "http://loki-distributed-gateway.loki.svc.cluster.local"
              isDefault = true
              jsonData = {
                 derivedFields =[{
                   datasourceUid = "tempo"
                   matcherRegex = "tid=(\\w+)"
                   name = "TraceID"
                   url = "$${__value.raw}"
                 }]
              }
            }]

I’m not entirely familiar with the Grafana helm chart and how datasources are loaded.

Your config seems to match the example here, the only difference I see is that the docs use single quotes:

'$${__value.raw}'

while you use double:

"$${__value.raw}"

Not sure if this matters, but might be worth trying.

1 Like

Thanks for your reply :slight_smile:
Single quotes don’t work in terraform :confused:

But I see in the configmap that the value ${__value.raw} is set correctly.

Weird… we don’t use the helm charts internally (AFAIK), but I can share part of the configmaps we use. Your configmap should look similar.

So this is a Loki datasource in a configmap from our internal infrastructure. I’ve kept all fields for context, but only the part under derivedFields should matter.

    apiVersion: 1
    datasources:
      - access: proxy
        editable: false
        isDefault: false
        jsonData:
            derivedFields:
              - datasourceUid: tempo
                matcherRegex: (?:traceID|trace_id|tid)=(\w+)
                name: TraceID
                url: $${__value.raw}
            httpMethod: GET
        name: Loki
        type: loki
        url: http://<loki>
        version: 1

Ok, thanks a lot!!! Apparently, we had to escape the $ signs once more because terraform escape a $ sign with a $ sign :smiley:

Your configuration file gave us the right tip.

1 Like

Oh right, because Terraform interprets "${...}" as string interpolation :sweat_smile: Glad you figured it out :smiley:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.