How to customize `tracesToLogs` query text pattern?

Hi all,

We are using Loki + Tempo combo in .NET solution via OTEL collector. Works great separately. Logging is done in JSON format. TraceID and SpanID are set as attributes on log records.
Fragment from OTEL config:

loki/json:
endpoint: “http://loki:3100/loki/api/v1/push
tls:
insecure: true
format: json
labels:
attributes:
traceid: “traceid”
spanid: “spanid”
resource:
“service.name”: “service_name”
“service.instance.id”: “service_instance_id”
“traceid”: “traceid”
“spanid”: “spanid”

Now we need to connect these two. I was able to configure tracesToLogs feature and see button to open logs for the span.

However query text that is passed over to Loki is incorrect and I can’t search by it.

Query that is send to Loki now:

{} | = “…{traceid}…”

Query that is working (need to modify query above to get it working):

{ service_name ~= “…{app name}…” } | json | traceid = “…{traceid}…”

How are we able to customize query text passed from Tempo over to Loki?

Many thanks!

Can you share your trace to logs config?

It looks like you don’t have tags configured or the configured tags don’t match any attributes on your spans.

Oh right, I do have tags commented out.
Added it back but still seems like there is some misconfiguration.
Hardly can find any real-life configuration online.

Here is my config:

jsonData:
tracesToLogs:
datasourceUid: ‘Loki’
tags: [‘service_name’]
mappedTags: [{ key: ‘otel.library.name’, value: ‘service_name’ }]
mapTagNamesEnabled: true
spanStartTimeShift: ‘1h’
spanEndTimeShift: ‘1h’
filterByTraceID: true
filterBySpanID: true
lokiSearch:
datasourceUid: ‘Loki’

This is how it looks in Grafana (query in Loki is modified manually to return some records):

Looks like you’ve got tags configured correctly now. The config is a bit more confusing when viewing it as code vs in the UI. Tags and mappedTags are mutually exclusive properties. If mapTagNamesEnabled is true, the query will be built based off of the mappedTags.

The config looks correct, you’ll just need to adjust the tag values based on what makes sense for your span attributes and log labels.