Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore: Prettify json log #18522

Closed
ventris opened this issue Aug 12, 2019 · 20 comments · Fixed by #36324
Closed

Explore: Prettify json log #18522

ventris opened this issue Aug 12, 2019 · 20 comments · Fixed by #36324
Assignees
Labels
area/explore area/logs prio/high Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/feature-request
Milestone

Comments

@ventris
Copy link

ventris commented Aug 12, 2019

What would you like to be added:
Some way to pretty print the searchable json logs in the explore ui. Either through an option in the configuration menu or a checkbox in the explore view itself to enable it globally for all json data.

Why is this needed:
Reading big chunks of json data is hard and its easy to get lost in it. If there was a way to prettify the data it would be much easier to review and find the thing that you are searching for in the log line.

Example:

Non prettified data:

{"log":"{\"type\":\"response\",\"@timestamp\":\"2019-08-12T20:06:43Z\",\"tags\":[],\"pid\":1,\"method\":\"get\",\"statusCode\":200,\"req\":{\"url\":\"/app/kibana\",\"method\":\"get\",\"headers\":{\"user-agent\":\"curl/7.29.0\",\"host\":\"localhost:5601\",\"accept\":\"*/*\"},\"remoteAddress\":\"127.0.0.1\",\"userAgent\":\"127.0.0.1\"},\"res\":{\"statusCode\":200,\"responseTime\":45,\"contentLength\":9},\"message\":\"GET /app/kibana 200 45ms - 9.0B\"}\n","stream":"stdout","time":"2019-08-12T20:06:43.183719829Z"}

Prettified data:

{
  "log": "{\"type\":\"response\",\"@timestamp\":\"2019-08-12T20:06:43Z\",\"tags\":[],\"pid\":1,\"method\":\"get\",\"statusCode\":200,\"req\":{\"url\":\"/app/kibana\",\"method\":\"get\",\"headers\":{\"user-agent\":\"curl/7.29.0\",\"host\":\"localhost:5601\",\"accept\":\"*/*\"},\"remoteAddress\":\"127.0.0.1\",\"userAgent\":\"127.0.0.1\"},\"res\":{\"statusCode\":200,\"responseTime\":45,\"contentLength\":9},\"message\":\"GET /app/kibana 200 45ms - 9.0B\"}\n",
  "stream": "stdout",
  "time": "2019-08-12T20:06:43.183719829Z"
}

One of the problems with this is that the log field has the log data with escaped " characters. This makes the inner json structure harder to prettify as one needs to take that in consideration when it is prettified.

Prettified data with unescaped ":

{  
  "log":{  
    "type":"response",
    "@timestamp":"2019-08-12T20:06:43Z",
    "tags":[  

    ],
    "pid":1,
    "method":"get",
    "statusCode":200,
    "req":{  
      "url":"/app/kibana",
      "method":"get",
      "headers":{  
        "user-agent":"curl/7.29.0",
        "host":"localhost:5601",
        "accept":"*/*"
      },
      "remoteAddress":"127.0.0.1",
      "userAgent":"127.0.0.1"
    },
    "res":{  
      "statusCode":200,
      "responseTime":45,
      "contentLength":9
    },
    "message":"GET /app/kibana 200 45ms - 9.0B"
  },
  "stream":"stdout",
  "time":"2019-08-12T20:06:43.183719829Z"
}
@daniellee daniellee changed the title Expore: Prettify json log Explore: Prettify json log Sep 9, 2019
@milandamen
Copy link

The absence of this feature is the only reason we still use Kibana for reading logs. When this feature gets implemented it would mean we could use just Grafana, which would be great.

@davkal davkal mentioned this issue Sep 24, 2019
16 tasks
@slim-bean
Copy link
Contributor

Would this issue also include a mechanism for selecting just certain fields out of the json object? Taking the above example being able to add to the query something like log.message and getting back just GET /app/kibana 200 45ms - 9.0B

@roidelapluie
Copy link
Collaborator

+1 @slim-bean would be awesome

@Fr33maan
Copy link

Fr33maan commented Jan 4, 2020

+1 Thie is actually pretty important for readability. I see that the TODO backlog is already pretty huge but hopes to see this landing soon

@jcdauchy
Copy link

jcdauchy commented Jan 19, 2020

Being table to select dispayed fields would be awesome. Don't know if this could be done also for Loki datasource ? One raison we cannot switch from Kibana to Explore/Logpanel on grafana is this missing fields selection feature :(

@Fr33maan
Copy link

Fr33maan commented Jan 19, 2020 via email

@jcdauchy
Copy link

jcdauchy commented Jan 19, 2020

I understand that loki uses only labels as "index". But why do you need to display all labels and fields as they seem to be already "parsed" as show in the details of each line ?

@aocenas aocenas moved this from To do to Backlog features in Observability (deprecated, use Observability Squad) Jan 21, 2020
@Guchman
Copy link

Guchman commented Feb 23, 2020

There are two reasons why we still need to use Kibana:
selecting fields to display in log view and select fast filters by labels. It's really necessary to have before grafana will be good not only for metrics:(

@jcerrada
Copy link

+1 I'd be really good to have this feature.

@fredr
Copy link
Collaborator

fredr commented Jul 14, 2020

Would this issue also include a mechanism for selecting just certain fields out of the json object? Taking the above example being able to add to the query something like log.message and getting back just GET /app/kibana 200 45ms - 9.0B

I made a POC/Proposal/discussion starter for something like that in pr #26178

@aocenas
Copy link
Member

aocenas commented Oct 15, 2020

Also interesting issue with nested string fields that user also may want formatted #27964

@muhmud
Copy link

muhmud commented Dec 3, 2020

Any movement on this issue? It's makes debugging Java pretty painful...

@smbrd
Copy link

smbrd commented Dec 23, 2020

Lack of that feature is a deal breaker for our company to move from Sumo Logic.

@aciokler
Copy link

aciokler commented Jan 4, 2021

Any updates on this feature? This is really needed for our company. Reading java stack traces is almost impossible without some kind of formatting.

@zhagan
Copy link

zhagan commented Jan 4, 2021

I also need this ASAP!

@devnerCO
Copy link

devnerCO commented Jan 4, 2021

Any updates on this? Reading Java logs in Grafana is not fun

@Paul414762
Copy link

Our team needs this! It's impossible to read the json output we have. We end up having to copy and paste the json into some other tool. We're wasting a ton of time and adding frustration!

@BitProcessor
Copy link
Contributor

BitProcessor commented Mar 17, 2021

So how about this ?
Seems to have been on the roadmap for 7.0, we're at 7.4 now?
Roadmap: #15999

@Elfo404
Copy link
Member

Elfo404 commented Mar 17, 2021

As a first step we can try to parse and prettify the first level of each log entry. We can then see what would be needed to better improve readability for log entries.

@Elfo404 Elfo404 added the prio/high Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Mar 17, 2021
@ivanahuckova
Copy link
Member

ivanahuckova commented Apr 14, 2021

I think that we could, as a first step, just check if message is JSON.parsable. And if it is, we can use JSON.stringify(JSON.parse(message), undefined, 2) so it shows in the following way:

image

Not sure if any library would be faster than these native js functions. Also, not sure if we want to do it automatically for all parsable messages, or if we want to add button/switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/explore area/logs prio/high Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/feature-request