@@ -4,55 +4,15 @@ import LokiTransport from "winston-loki";
44import { AuthInfo } from "./graphql/fetchAuthInfoFromGraphQL" ;
55import { getDeviceId } from "./getDeviceId" ;
66import { randomUUID } from "crypto" ;
7- import StackUtils from "stack-utils " ;
7+ import { formatTags , Tags } from "./formatTags " ;
88
99const GRAFANA_USER = "909360" ;
1010const GRAFANA_PUBLIC_TOKEN =
1111 "glc_eyJvIjoiOTEyOTQzIiwibiI6IndyaXRlLW90ZWwtcmVwbGF5LWNsaSIsImsiOiJ0UnFsOXV1a2QyQUI2NzIybDEzSkRuNDkiLCJtIjp7InIiOiJwcm9kLXVzLWVhc3QtMCJ9fQ==" ; // write-only permissions.
1212const GRAFANA_BASIC_AUTH = `${ GRAFANA_USER } :${ GRAFANA_PUBLIC_TOKEN } ` ;
1313const HOST = "https://logs-prod-006.grafana.net" ;
1414
15- const stackUtils = new StackUtils ( { cwd : process . cwd ( ) , internals : StackUtils . nodeInternals ( ) } ) ;
16-
17- function anonymizeStackTrace ( stack : string ) : string {
18- return stack
19- . split ( "\n" )
20- . map ( line => {
21- const frame = stackUtils . parseLine ( line ) ;
22- if ( frame && frame . file ) {
23- const relativePath = frame . file . includes ( "node_modules" )
24- ? frame . file . substring ( frame . file . indexOf ( "node_modules" ) )
25- : frame . file ;
26- return line . replace ( frame . file , relativePath ) ;
27- }
28- return line ;
29- } )
30- . join ( "\n" ) ;
31- }
32-
33- export function formatTags ( tags ?: Tags ) {
34- if ( ! tags ) {
35- return ;
36- }
37-
38- return Object . entries ( tags ) . reduce ( ( result , [ key , value ] ) => {
39- if ( value instanceof Error ) {
40- result [ key ] = {
41- // Intentionally keeping this for any extra properties attached in `Error`
42- ...( value as any ) ,
43- errorName : value . name ,
44- errorMessage : value . message ,
45- errorStack : anonymizeStackTrace ( value . stack ?? "" ) ,
46- } ;
47- } else {
48- result [ key ] = value ;
49- }
50- return result ;
51- } , { } as Record < string , unknown > ) ;
52- }
53-
5415type LogLevel = "error" | "warn" | "info" | "debug" ;
55- export type Tags = Record < string , unknown > ;
5616
5717class Logger {
5818 private deviceId : string ;
0 commit comments