@@ -40,35 +40,38 @@ export function preprocessLogs(res: QueryLogsRes, query: LightstepQuery) {
4040 preferredVisualisationType : 'logs' ,
4141 } ,
4242 fields : [
43+ // time, content, and level are required by the Grafana panel, all other
44+ // fields are considered custom fields
4345 { name : 'time' , type : FieldType . time } ,
4446 { name : 'content' , type : FieldType . string } ,
4547 { name : 'level' , type : FieldType . string } ,
46- { name : 'severity' , type : FieldType . string } ,
4748 ] ,
4849 } ) ;
4950
5051 res . data . attributes . logs . forEach ( ( [ timestamp , log ] ) => {
51- let tags = { } ;
52- if ( 'tags' in log && log . tags !== null && typeof log . tags === 'object' ) {
53- tags = log . tags ;
54- Object . entries ( log . tags ) . forEach ( ( [ key , value ] ) => {
55- // Add every log tag to the set of detected fields once
56- if ( ! detectedFields . has ( key ) ) {
57- detectedFields . set ( key , true ) ;
58- frame . addField ( {
59- name : key ,
60- type : getFieldTypeForValue ( value ) ,
61- } ) ;
62- }
63- } ) ;
64- }
52+ const { body, Body, event, ...customFields } = log ;
53+
54+ const transformedFields : Record < string , unknown > = { } ;
55+ Object . entries ( customFields ) . forEach ( ( [ key , value ] ) => {
56+ // Add every field to the set of detected fields once
57+ if ( ! detectedFields . has ( key ) ) {
58+ detectedFields . set ( key , true ) ;
59+ frame . addField ( {
60+ name : key ,
61+ type : getFieldTypeForValue ( value ) ,
62+ } ) ;
63+ }
64+
65+ // Complex fields (objects, arrays) aren't supported by Grafana, so we
66+ // need to stringify them
67+ transformedFields [ key ] = typeof value === 'object' ? JSON . stringify ( value ) : value ;
68+ } ) ;
6569
6670 frame . add ( {
6771 time : timestamp ,
68- content : log . event ,
72+ content : body ?? Body ?? event ?? '' ,
6973 level : getLevel ( log ) ,
70- severity : log . severity ,
71- ...tags ,
74+ ...transformedFields ,
7275 } ) ;
7376 } ) ;
7477
0 commit comments