# How to customize \`tracesToLogs\` query text pattern?

**URL:** <https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880>\
**Category:** Grafana Tempo\
**Tags:** templating, loki\
**Created:** [June 8, 2022, 3:53pm UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880 "2022-06-08T15:53:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![valdisiljuconoks](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/valdisiljuconoks/32/23659_2.png) [@valdisiljuconoks](https://community.grafana.com/u/valdisiljuconoks)\
**Post date:** [June 8, 2022, 3:53pm UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880/1 "2022-06-08T15:53:18Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![cblindsey3](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/cblindsey3/32/23661_2.png) [@cblindsey3](https://community.grafana.com/u/cblindsey3)\
**Post date:** [June 8, 2022, 5:42pm UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880/2 "2022-06-08T17:42:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![valdisiljuconoks](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/valdisiljuconoks/32/23659_2.png) [@valdisiljuconoks](https://community.grafana.com/u/valdisiljuconoks)\
**Post date:** [June 8, 2022, 11:03pm UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880/3 "2022-06-08T23:03:38Z")

</div>

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):

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/d/4d81e0459bf6b0a30b023a37e71876d11df0f905.png)

---

<div class="post-metadata">

**Author:** ![anon20547134](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@anon20547134](https://community.grafana.com/u/anon20547134)\
**Post date:** [June 9, 2022, 12:37am UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880/4 "2022-06-09T00:37:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![julian3503](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@julian3503](https://community.grafana.com/u/julian3503)\
**Post date:** [May 8, 2023, 3:09pm UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880/5 "2023-05-08T15:09:17Z")

</div>

@anon20547134 - this is a little off topic, but can you point me at where the yaml configuration is documented? I have been totally unable to find documentation anywhere for this, and without finding this question it would have been pretty challenging to figure out what the appropriate config was.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/grafana/original/2X/e/ef5308cc58c9e5a13187b5012eb99f406928462f.png) [@system](https://community.grafana.com/u/system)\
**Post date:** [May 7, 2024, 3:10pm UTC](https://community.grafana.com/t/how-to-customize-tracestologs-query-text-pattern/66880/6 "2024-05-07T15:10:07Z")

</div>

Closed on May 7, 2024, 3:10pm UTC

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