Skip to content

Commit

Permalink
fix trace format
Browse files Browse the repository at this point in the history
  • Loading branch information
chaolee50 committed Jul 5, 2022
1 parent bb4760e commit 308aa8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
MutableDataFrame,
Vector,
} from '@grafana/data';
import { SLSDataSourceOptions, SlsLog, SLSQuery } from './types';
import { SLSDataSourceOptions, SLSQuery } from './types';
import { DataSourceWithBackend, getBackendSrv, getTemplateSrv } from '@grafana/runtime';
import _ from 'lodash';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -75,13 +75,17 @@ function transTags(result: Map<string, Vector>, i: number): TraceKeyValuePair[]

function transLogs(result: Map<string, Vector>, i: number): TraceLog[] {
let traceLogs: TraceLog[] = [];
const slsLogs = JSON.parse(result.get('logs')?.get(i)) as SlsLog[];
const slsLogs = JSON.parse(result.get('logs')?.get(i)) as Object[];
for (const slsLog of slsLogs) {
const attributeArray = Array.from(Object.entries(slsLog.attribute), ([name, value]) => valueToTag(name, value));
traceLogs.push({
timestamp: slsLog.time / 1000000,
fields: attributeArray,
});
const logMap = new Map(Object.entries(slsLog));
const attributeArray = Array.from(Object.entries(slsLog), ([name, value]) => valueToTag(name, value));
let time = logMap.get('time');
if (time !== undefined) {
traceLogs.push({
timestamp: Number(time) / 1000000,
fields: attributeArray,
});
}
}
return traceLogs;
}
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export interface SLSSecureJsonData {
accessKeySecret?: string;
}

export declare type SlsLog = {
time: number;
attribute: Map<string, string>;
name: string;
};
// export declare type SlsLog = {
// time: number;
// attribute: Map<string, string>;
// name: string;
// };

0 comments on commit 308aa8c

Please sign in to comment.