<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Expand Tags values in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229389#M367</link>
    <description>&lt;P&gt;the change I did was in line 4&lt;/P&gt;
&lt;P&gt;changed this&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| parse toString(ts), """(('['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key| (LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key)"""&lt;/LI-CODE&gt;
&lt;P&gt;to this&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| parse toString(ts), """(('['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)| (LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key)"""&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What that line does is it parses the string of tags into context, key and value field. So how the pattern works basically it tries to pars the tag context, tag key, and tag value from the string.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case it doesn't match (there is no context) it should parse the key-value of the tag. and here was the issue. the initial pattern wanted to match &amp;amp; parse the full key, in case there is no context. but actually it should try to match &amp;amp; parse the tag key and tag value. so I just removed following snippet from the middle of line 4&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;|LD:tag_key|&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 Nov 2023 16:15:47 GMT</pubDate>
    <dc:creator>sinisa_zubic</dc:creator>
    <dc:date>2023-11-20T16:15:47Z</dc:date>
    <item>
      <title>Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229327#M359</link>
      <description>&lt;P&gt;Guys, I need some help. I have my process group entities with some tags and I need to put two fields in one, one is the value of the tag "[Kubernetes]componentid:" and the other, the value of the tag, "env". I can't seem to put the two together. I've tried a few things, but it didn't work. Can anyone help?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch dt.entity.process_group, from:now() - 1h
|fields entity.name, id, primeiraVisualizacao = lifetime[start], getDate = now(), tags
|expand tags
|fieldsAdd idComponent = replaceString(tags,"[Kubernetes]componentid:", "")
|filter (matchesPhrase(tags,"[Kubernetes]componentid"))
//|filter matchesPhrase(tags,"env:")
| sort primeiraVisualizacao desc
| limit 6000&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 13:16:29 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229327#M359</guid>
      <dc:creator>RPbiaggio</dc:creator>
      <dc:date>2023-11-20T13:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229364#M360</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/67564"&gt;@RPbiaggio&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you looking for something like this&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;fetch dt.entity.process_group, from:now() - 1h
|fields entity.name, id, primeiraVisualizacao = lifetime[start], getDate = now(), tags
|expand tags, alias:ts
| parse toString(ts), """(('['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key| (LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key)"""
| fieldsAdd componentId = if (tag_key == "componentid" and tag_context == "Kubernetes", tag_value)
| fieldsAdd environment = if (tag_key == "env", tag_value)
| summarize { 
  componentId = takeAny(componentId), 
  environment = takeAny(environment), 
  primeiraVisualizacao = takeAny(primeiraVisualizacao)}, by:{id}
| filter isNotNull(componentId) and isNotNull(environment)
| fieldsAdd myNewField = concat(componentId, ":", environment)
| sort primeiraVisualizacao desc
| limit 6000&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically I am first adding 2 new fields (environmentid and environment) after expanding a parsing the tags array. Then I need to summarize (group) the records by process group id.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;BR /&gt;Sini&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 14:56:50 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229364#M360</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-11-20T14:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229371#M361</link>
      <description>&lt;P&gt;Hi, &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/38283"&gt;@sinisa_zubic&lt;/a&gt;!!&lt;BR /&gt;This is exactly what I need, but for example, my "env" tag still doesn't appear. See this example where I added the tag manually. It does not return information in the DQL result.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RPbiaggio_2-1700494224402.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/15696i404C531DC79D1273/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RPbiaggio_2-1700494224402.png" alt="RPbiaggio_2-1700494224402.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RPbiaggio_1-1700494198457.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/15695iF98A696157051F0B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RPbiaggio_1-1700494198457.png" alt="RPbiaggio_1-1700494198457.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 15:31:16 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229371#M361</guid>
      <dc:creator>RPbiaggio</dc:creator>
      <dc:date>2023-11-20T15:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229377#M362</link>
      <description>&lt;P&gt;not sure why you have in line number 11 an "OR" instead of "AND". I have added that one because I am assuming that process groups with tag "componentid" must have tag "env".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but anyway, there might be some wired characters part of the tag and therefore the query is not working.&lt;BR /&gt;can you maybe execute following query and let me know the result? basically it should only show the 2 relevant tags for the process group you have highlighted. And please share the result in "Raw" view in notebooks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;fetch dt.entity.process_group
| filter id == "PROCESS_GROUP-2AD8E1DA4761BD8E"
| expand tags
| filter contains(tags,"environmentid") or contains(tags,"env")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 15:50:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229377#M362</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-11-20T15:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229381#M363</link>
      <description>&lt;P&gt;I put the "OR" just to give me a result, it was blank with both conditions. Both tags must actually exist.&lt;/P&gt;&lt;P&gt;Below is the result, as requested.&lt;/P&gt;&lt;P&gt;fetch dt.entity.process_group | filter id == "PROCESS_GROUP-2AD8E1DA4761BD8E" | expand tags | filter contains(tags,"[Kubernetes]componentid") or contains(tags,"env")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "records": [
    {
      "entity.name": "",
      "id": "PROCESS_GROUP-2AD8E1DA4761BD8E",
      "tags": "[Kubernetes]componentid:97ffed68873361906431ca240cbb3524"
    },
    {
      "entity.name": "",
      "id": "PROCESS_GROUP-2AD8E1DA4761BD8E",
      "tags": "env:DSV"
    },
    {
      "entity.name": "",
      "id": "PROCESS_GROUP-2AD8E1DA4761BD8E",
      "tags": "[Kubernetes]tags.datadoghq.com/env:dsv"
    }
  ],
  "metadata": {
    "grail": {
      "canonicalQuery": "fetch dt.entity.process_group\n| filter id == \"PROCESS_GROUP-2AD8E1DA4761BD8E\"\n| expand tags\n| filter contains(tags, \"[Kubernetes]componentid\") OR contains(tags, \"env\")",
      "timezone": "America/Sao_Paulo",
      "query": "fetch dt.entity.process_group | filter id == \"PROCESS_GROUP-2AD8E1DA4761BD8E\" | expand tags | filter contains(tags,\"[Kubernetes]componentid\") or contains(tags,\"env\")",
      "scannedRecords": 1,
      "dqlVersion": "V1_0",
      "scannedBytes": 4397,
      "analysisTimeframe": {
        "start": "2023-11-20T13:56:26.696Z",
        "end": "2023-11-20T15:56:26.696Z"
      },
      "locale": "",
      "executionTimeMilliseconds": 38,
      "notifications": [],
      "queryId": "0b7f4384-814b-4ec2-b9e9-29878c83f650",
      "sampled": false
    }
  },
  "types": [
    {
      "mappings": {
        "entity.name": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "tags": {
          "type": "string"
        }
      },
      "indexRange": [
        0,
        2
      ]
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:02:06 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229381#M363</guid>
      <dc:creator>RPbiaggio</dc:creator>
      <dc:date>2023-11-20T16:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229383#M364</link>
      <description>&lt;P&gt;I think I found the culprit, the DPL pattern was not correct. I have copied it &lt;A href="https://docs.dynatrace.com/docs/shortlink/grail-querying-monitored-entities#entity-tags" target="_self"&gt;from help&lt;/A&gt;, but for the one special case it doesn't work. I will trigger a documentation update.&lt;/P&gt;
&lt;P&gt;Can you try this query now&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;fetch dt.entity.process_group, from:now() - 1h
|fields entity.name, id, primeiraVisualizacao = lifetime[start], getDate = now(), tags
|expand tags, alias:ts
| parse toString(ts), """(('['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)| (LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key)"""
| fieldsAdd componentId = if (tag_key == "componentid" and tag_context == "Kubernetes", tag_value)
| fieldsAdd environment = if (tag_key == "env", tag_value)
| summarize { 
  tags = takeAny(tags),
  componentId = takeAny(componentId), 
  environment = takeAny(environment), 
  primeiraVisualizacao = takeAny(primeiraVisualizacao)}, by:{id}
| filter isNotNull(componentId) and isNotNull(environment)
| fieldsAdd myNewField = concat(componentId, ":", environment)
| sort primeiraVisualizacao desc
| limit 6000&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:07:36 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229383#M364</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-11-20T16:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229384#M365</link>
      <description>&lt;P&gt;When it includes another tag (tags.datadoghq.com/env) that will be discontinued, which is from Datadog, it returned the value. This "env" tag will not have a context like the other, that is, it will not have "Kubernetes".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RPbiaggio_0-1700496252104.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/15697i75281322162FE545/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RPbiaggio_0-1700496252104.png" alt="RPbiaggio_0-1700496252104.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:05:58 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229384#M365</guid>
      <dc:creator>RPbiaggio</dc:creator>
      <dc:date>2023-11-20T16:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229386#M366</link>
      <description>&lt;P&gt;Now it works perfectly. Thanks for your help. Could you tell me what change you made? I appreciate the help.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RPbiaggio_0-1700496474827.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/15698i4D024B8E6908C575/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RPbiaggio_0-1700496474827.png" alt="RPbiaggio_0-1700496474827.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:08:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229386#M366</guid>
      <dc:creator>RPbiaggio</dc:creator>
      <dc:date>2023-11-20T16:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Expand Tags values</title>
      <link>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229389#M367</link>
      <description>&lt;P&gt;the change I did was in line 4&lt;/P&gt;
&lt;P&gt;changed this&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| parse toString(ts), """(('['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key| (LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key)"""&lt;/LI-CODE&gt;
&lt;P&gt;to this&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| parse toString(ts), """(('['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)| (LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)|LD:tag_key)"""&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What that line does is it parses the string of tags into context, key and value field. So how the pattern works basically it tries to pars the tag context, tag key, and tag value from the string.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;['LD:tag_context ']' LD:tag_key (!&amp;lt;&amp;lt;'\\' ':') LD:tag_value)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case it doesn't match (there is no context) it should parse the key-value of the tag. and here was the issue. the initial pattern wanted to match &amp;amp; parse the full key, in case there is no context. but actually it should try to match &amp;amp; parse the tag key and tag value. so I just removed following snippet from the middle of line 4&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;|LD:tag_key|&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:15:47 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Expand-Tags-values/m-p/229389#M367</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-11-20T16:15:47Z</dc:date>
    </item>
  </channel>
</rss>

