2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"io/ioutil" 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 17:00:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"net/url" 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"os" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"time" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/getsentry/sentry-go" 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/go-kit/log" 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/frontendlogging" 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/response" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/routing" 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/log/level" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/models" 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/plugins" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/setting" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/stretchr/testify/assert" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/stretchr/testify/require" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  SourceMapReadRecord  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									dir   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									path  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  logScenarioFunc  func ( c  * scenarioContext ,  logs  map [ string ] interface { } ,  sourceMapReads  [ ] SourceMapReadRecord )  
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  logSentryEventScenario ( t  * testing . T ,  desc  string ,  event  frontendlogging . FrontendSentryEvent ,  fn  logScenarioFunc )  {  
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									t . Run ( desc ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  logcontent  =  make ( map [ string ] interface { } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										logcontent [ "logger" ]  =  "frontend" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										newfrontendLogger  :=  log . Logger ( log . LoggerFunc ( func ( keyvals  ... interface { } )  error  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  i  :=  0 ;  i  <  len ( keyvals ) ;  i  +=  2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												logcontent [ keyvals [ i ] . ( string ) ]  =  keyvals [ i + 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										origHandler  :=  frontendLogger . GetLogger ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-07 23:00:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										frontendLogger . Swap ( level . NewFilter ( newfrontendLogger ,  level . AllowInfo ( ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sourceMapReads  :=  [ ] SourceMapReadRecord { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										t . Cleanup ( func ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-07 23:00:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											frontendLogger . Swap ( origHandler ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-13 16:52:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sc  :=  setupScenarioContext ( t ,  "/log" ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 17:00:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cdnRootURL ,  e  :=  url . Parse ( "https://storage.googleapis.com/grafana-static-assets" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . NoError ( t ,  e ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cfg  :=  & setting . Cfg { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											StaticRootPath :  "/staticroot" , 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 17:00:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											CDNRootURL :      cdnRootURL , 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										readSourceMap  :=  func ( dir  string ,  path  string )  ( [ ] byte ,  error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											sourceMapReads  =  append ( sourceMapReads ,  SourceMapReadRecord { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												dir :   dir , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												path :  path , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  strings . Contains ( path ,  "error" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  nil ,  errors . New ( "epic hard drive failure" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  strings . HasSuffix ( path ,  "foo.js.map" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												f ,  err  :=  ioutil . ReadFile ( "./frontendlogging/test-data/foo.js.map" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  f ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  nil ,  os . ErrNotExist 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// fake plugin route so we will try to find a source map there
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 17:53:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										pm  :=  fakePluginStaticRouteResolver { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											routes :  [ ] * plugins . StaticRoute { 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Directory :  "/usr/local/telepathic-panel" , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 17:53:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													PluginID :   "telepathic" , 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										sourceMapStore  :=  frontendlogging . NewSourceMapStore ( cfg ,  & pm ,  readSourceMap ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										loggingHandler  :=  NewFrontendLogMessageHandler ( sourceMapStore ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										handler  :=  routing . Wrap ( func ( c  * models . ReqContext )  response . Response  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											sc . context  =  c 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											c . Req . Body  =  mockRequestBody ( event ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 20:44:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											c . Req . Header . Add ( "Content-Type" ,  "application/json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  loggingHandler ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										sc . m . Post ( sc . url ,  handler ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										sc . fakeReqWithParams ( "POST" ,  sc . url ,  map [ string ] string { } ) . exec ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										fn ( sc ,  logcontent ,  sourceMapReads ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  TestFrontendLoggingEndpoint ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ts ,  err  :=  time . Parse ( "2006-01-02T15:04:05.000Z" ,  "2020-10-22T06:29:29.078Z" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									t . Run ( "FrontendLoggingEndpoint" ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										request  :=  sentry . Request { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											URL :  "http://localhost:3000/" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Headers :  map [ string ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"User-Agent" :  "Chrome" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										user  :=  sentry . User { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Email :  "geralt@kaermorhen.com" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ID :     "45" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										event  :=  sentry . Event { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											EventID :    "123" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Level :      sentry . LevelError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Request :    & request , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Timestamp :  ts , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										errorEvent  :=  frontendlogging . FrontendSentryEvent { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Event :  & event , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Exception :  & frontendlogging . FrontendSentryException { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Values :  [ ] frontendlogging . FrontendSentryExceptionValue { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Type :   "UserError" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Value :  "Please replace user and try again" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Stacktrace :  sentry . Stacktrace { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															Frames :  [ ] sentry . Frame { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "foofn" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "foo.js" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    123 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     23 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "barfn" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "bar.js" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    113 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     231 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										logSentryEventScenario ( t ,  "Should log received error event" ,  errorEvent , 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											func ( sc  * scenarioContext ,  logs  map [ string ] interface { } ,  sourceMapReads  [ ] SourceMapReadRecord )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Equal ( t ,  200 ,  sc . resp . Code ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "logger" ,  "frontend" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "url" ,  errorEvent . Request . URL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "user_agent" ,  errorEvent . Request . Headers [ "User-Agent" ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "event_id" ,  errorEvent . EventID ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "original_timestamp" ,  errorEvent . Timestamp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "stacktrace" ,  ` UserError :  Please  replace  user  and  try  again 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  at  foofn  ( foo . js : 123 : 23 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  at  barfn  ( bar . js : 113 : 231 ) ` ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . NotContains ( t ,  logs ,  "context" ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										messageEvent  :=  frontendlogging . FrontendSentryEvent { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Event :  & sentry . Event { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												EventID :    "123" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Level :      sentry . LevelInfo , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Request :    & request , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Timestamp :  ts , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :    "hello world" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												User :       user , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Exception :  nil , 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										logSentryEventScenario ( t ,  "Should log received message event" ,  messageEvent , 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											func ( sc  * scenarioContext ,  logs  map [ string ] interface { } ,  sourceMapReads  [ ] SourceMapReadRecord )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Equal ( t ,  200 ,  sc . resp . Code ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Len ( t ,  logs ,  10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "logger" ,  "frontend" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "msg" ,  "hello world" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "lvl" ,  level . InfoValue ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "logger" ,  "frontend" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "url" ,  messageEvent . Request . URL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "user_agent" ,  messageEvent . Request . Headers [ "User-Agent" ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "event_id" ,  messageEvent . EventID ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "original_timestamp" ,  messageEvent . Timestamp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . NotContains ( t ,  logs ,  "stacktrace" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . NotContains ( t ,  logs ,  "context" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "user_email" ,  user . Email ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "user_id" ,  user . ID ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-12-10 17:50:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										eventWithContext  :=  frontendlogging . FrontendSentryEvent { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Event :  & sentry . Event { 
							 
						 
					
						
							
								
									
										
										
										
											2020-12-10 17:50:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												EventID :    "123" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Level :      sentry . LevelInfo , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Request :    & request , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Timestamp :  ts , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :    "hello world" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												User :       user , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Contexts :  map [ string ] interface { } { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													"foo" :  map [ string ] interface { } { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														"one" :    "two" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														"three" :  4 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													"bar" :  "baz" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Exception :  nil , 
							 
						 
					
						
							
								
									
										
										
										
											2020-12-10 17:50:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										logSentryEventScenario ( t ,  "Should log event context" ,  eventWithContext , 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											func ( sc  * scenarioContext ,  logs  map [ string ] interface { } ,  sourceMapReads  [ ] SourceMapReadRecord )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Equal ( t ,  200 ,  sc . resp . Code ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "context_foo_one" ,  "two" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "context_foo_three" ,  "4" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "context_bar" ,  "baz" ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										errorEventForSourceMapping  :=  frontendlogging . FrontendSentryEvent { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Event :  & event , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Exception :  & frontendlogging . FrontendSentryException { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Values :  [ ] frontendlogging . FrontendSentryExceptionValue { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Type :   "UserError" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Value :  "Please replace user and try again" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Stacktrace :  sentry . Stacktrace { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															Frames :  [ ] sentry . Frame { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "foofn" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "http://localhost:3000/public/build/moo/foo.js" ,  // source map found and mapped, core
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "foofn" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "http://localhost:3000/public/plugins/telepathic/foo.js" ,  // plugin, source map found and mapped
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "explode" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "http://localhost:3000/public/build/error.js" ,  // reading source map throws error
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "wat" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "http://localhost:3000/public/build/bar.js" ,  // core, but source map not found on fs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "nope" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "http://localhost:3000/baz.js" ,  // not core or plugin, wont even attempt to get source map
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "fake" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "http://localhost:3000/public/build/../../secrets.txt" ,  // path will be sanitized
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 17:00:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Function :  "cdn" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Filename :  "https://storage.googleapis.com/grafana-static-assets/grafana-oss/pre-releases/7.5.0-11925pre/public/build/foo.js" ,  // source map found and mapped
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Lineno :    3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Colno :     10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										logSentryEventScenario ( t ,  "Should load sourcemap and transform stacktrace line when possible" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											errorEventForSourceMapping ,  func ( sc  * scenarioContext ,  logs  map [ string ] interface { } ,  sourceMapReads  [ ] SourceMapReadRecord )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Equal ( t ,  200 ,  sc . resp . Code ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Len ( t ,  logs ,  9 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assertContextContains ( t ,  logs ,  "stacktrace" ,  ` UserError :  Please  replace  user  and  try  again 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-04 14:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  at  ?  ( core | webpack : ///./some_source.ts:2:2)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  at  ?  ( telepathic | webpack : ///./some_source.ts:3:2)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  at  explode  ( http : //localhost:3000/public/build/error.js:3:10)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  at  wat  ( http : //localhost:3000/public/build/bar.js:3:10)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  at  nope  ( http : //localhost:3000/baz.js:3:10)
 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-11 17:00:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  at  fake  ( http : //localhost:3000/public/build/../../secrets.txt:3:10)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  at  ?  ( core | webpack : ///./some_source.ts:3:2)`)
 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-18 20:53:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . Len ( t ,  sourceMapReads ,  6 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/staticroot" ,  sourceMapReads [ 0 ] . dir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "build/moo/foo.js.map" ,  sourceMapReads [ 0 ] . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/usr/local/telepathic-panel" ,  sourceMapReads [ 1 ] . dir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/foo.js.map" ,  sourceMapReads [ 1 ] . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/staticroot" ,  sourceMapReads [ 2 ] . dir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "build/error.js.map" ,  sourceMapReads [ 2 ] . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/staticroot" ,  sourceMapReads [ 3 ] . dir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "build/bar.js.map" ,  sourceMapReads [ 3 ] . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/staticroot" ,  sourceMapReads [ 4 ] . dir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "secrets.txt.map" ,  sourceMapReads [ 4 ] . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "/staticroot" ,  sourceMapReads [ 5 ] . dir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "build/foo.js.map" ,  sourceMapReads [ 5 ] . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-06 22:28:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  assertContextContains ( t  * testing . T ,  logRecord  map [ string ] interface { } ,  label  string ,  value  interface { } )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									assert . Contains ( t ,  logRecord ,  label ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									assert . Equal ( t ,  value ,  logRecord [ label ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-12 19:29:43 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}