55
66import { Platform } from 'react-native' ;
77
8- let NewRelic : any = null ;
8+ /**
9+ * Type definitions for New Relic SDK
10+ * Based on newrelic-react-native-agent API
11+ */
12+ interface NewRelicSDK {
13+ setUserId ?: ( userId : string ) => void ;
14+ setAttribute ?: ( name : string , value : string | number | boolean ) => void ;
15+ recordError ?: ( error : Error ) => void ;
16+ logDebug ?: ( message : string , attributes ?: Record < string , unknown > ) => void ;
17+ logInfo ?: ( message : string , attributes ?: Record < string , unknown > ) => void ;
18+ logWarning ?: ( message : string , attributes ?: Record < string , unknown > ) => void ;
19+ logError ?: ( message : string , attributes ?: Record < string , unknown > ) => void ;
20+ recordCustomEvent ?: ( eventName : string , attributes ?: Record < string , unknown > ) => void ;
21+ recordBreadcrumb ?: ( name : string , attributes ?: Record < string , unknown > ) => void ;
22+ }
23+
24+ let NewRelic : NewRelicSDK | null = null ;
925
1026// Initialize New Relic reference
1127try {
@@ -24,7 +40,7 @@ export enum LogLevel {
2440
2541interface LogOptions {
2642 /** Additional attributes to attach to the log */
27- attributes ?: Record < string , any > ;
43+ attributes ?: Record < string , unknown > ;
2844 /** Whether to only send to New Relic (skip console) */
2945 newRelicOnly ?: boolean ;
3046}
@@ -35,7 +51,7 @@ interface LogOptions {
3551class Logger {
3652 private isNewRelicAvailable : boolean ;
3753 private userId : string | null = null ;
38- private sessionAttributes : Record < string , any > = { } ;
54+ private sessionAttributes : Record < string , unknown > = { } ;
3955
4056 constructor ( ) {
4157 this . isNewRelicAvailable = NewRelic !== null ;
@@ -57,7 +73,7 @@ class Logger {
5773 /**
5874 * Set session-level attributes that will be included in all logs
5975 */
60- setSessionAttributes ( attributes : Record < string , any > ) : void {
76+ setSessionAttributes ( attributes : Record < string , unknown > ) : void {
6177 this . sessionAttributes = { ...this . sessionAttributes , ...attributes } ;
6278
6379 // Set each attribute in New Relic
@@ -197,7 +213,7 @@ class Logger {
197213 /**
198214 * Record a custom event in New Relic
199215 */
200- recordEvent ( eventName : string , attributes ?: Record < string , any > ) : void {
216+ recordEvent ( eventName : string , attributes ?: Record < string , unknown > ) : void {
201217 if ( this . isNewRelicAvailable && NewRelic . recordCustomEvent ) {
202218 NewRelic . recordCustomEvent ( eventName , attributes ) ;
203219 }
@@ -223,7 +239,7 @@ class Logger {
223239 /**
224240 * Record a breadcrumb (useful for tracking user flow)
225241 */
226- breadcrumb ( name : string , attributes ?: Record < string , any > ) : void {
242+ breadcrumb ( name : string , attributes ?: Record < string , unknown > ) : void {
227243 if ( this . isNewRelicAvailable && NewRelic . recordBreadcrumb ) {
228244 NewRelic . recordBreadcrumb ( name , attributes ) ;
229245 }
0 commit comments