|
6 | 6 |
|
7 | 7 | import { NativeModules } from 'react-native'; |
8 | 8 | import { DdSdkConfiguration, DdSdkType, DdLogsType, DdTraceType, DdRumType } from './types'; |
| 9 | +import {InternalLog} from "./InternalLog" |
| 10 | +import {SdkVerbosity} from "./SdkVerbosity"; |
9 | 11 |
|
10 | 12 | class DdLogsWrapper implements DdLogsType { |
11 | 13 |
|
12 | | - private nativeLogs: DdLogsType = NativeModules.DdLogs; |
| 14 | + private nativeLogs: DdLogsType = NativeModules.DdLogs; |
13 | 15 |
|
14 | | - debug(message: string, context: object = {}): Promise<void> { |
15 | | - return this.nativeLogs.debug(message, context); |
16 | | - } |
| 16 | + debug(message: string, context: object = {}): Promise<void> { |
| 17 | + InternalLog.log("Tracking debug log “" + message + "”", SdkVerbosity.DEBUG); |
| 18 | + return this.nativeLogs.debug(message, context); |
| 19 | + } |
17 | 20 |
|
18 | | - info(message: string, context: object = {}): Promise<void> { |
19 | | - return this.nativeLogs.info(message, context); |
20 | | - } |
| 21 | + info(message: string, context: object = {}): Promise<void> { |
| 22 | + InternalLog.log("Tracking info log “" + message + "”", SdkVerbosity.DEBUG); |
| 23 | + return this.nativeLogs.info(message, context); |
| 24 | + } |
21 | 25 |
|
22 | | - warn(message: string, context: object = {}): Promise<void> { |
23 | | - return this.nativeLogs.warn(message, context); |
24 | | - } |
| 26 | + warn(message: string, context: object = {}): Promise<void> { |
| 27 | + InternalLog.log("Tracking warn log “" + message + "”", SdkVerbosity.DEBUG); |
| 28 | + return this.nativeLogs.warn(message, context); |
| 29 | + } |
25 | 30 |
|
26 | | - error(message: string, context: object = {}): Promise<void> { |
27 | | - return this.nativeLogs.error(message, context); |
28 | | - } |
| 31 | + error(message: string, context: object = {}): Promise<void> { |
| 32 | + InternalLog.log("Tracking error log “" + message + "”", SdkVerbosity.DEBUG); |
| 33 | + return this.nativeLogs.error(message, context); |
| 34 | + } |
29 | 35 |
|
30 | 36 | } |
31 | 37 |
|
32 | 38 | class DdTraceWrapper implements DdTraceType { |
33 | 39 |
|
34 | | - private nativeTrace: DdTraceType = NativeModules.DdTrace; |
| 40 | + private nativeTrace: DdTraceType = NativeModules.DdTrace; |
35 | 41 |
|
36 | | - startSpan(operation: string, context: object = {}, timestampMs: number = Date.now()): Promise<string> { |
37 | | - return this.nativeTrace.startSpan(operation, context, timestampMs); |
38 | | - } |
39 | | - |
40 | | - finishSpan(spanId: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
41 | | - return this.nativeTrace.finishSpan(spanId, context, timestampMs); |
42 | | - } |
| 42 | + startSpan(operation: string, context: object = {}, timestampMs: number = Date.now()): Promise<string> { |
| 43 | + let spanId = this.nativeTrace.startSpan(operation, context, timestampMs); |
| 44 | + InternalLog.log("Starting span “" + operation + "” #" + spanId, SdkVerbosity.DEBUG); |
| 45 | + return spanId |
| 46 | + } |
43 | 47 |
|
| 48 | + finishSpan(spanId: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 49 | + InternalLog.log("Finishing span #" + spanId, SdkVerbosity.DEBUG); |
| 50 | + return this.nativeTrace.finishSpan(spanId, context, timestampMs); |
| 51 | + } |
44 | 52 | } |
45 | 53 |
|
46 | 54 | class DdRumWrapper implements DdRumType { |
47 | 55 |
|
48 | | - private nativeRum: DdRumType = NativeModules.DdRum; |
49 | | - |
50 | | - startView(key: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
51 | | - return this.nativeRum.startView(key, name, context, timestampMs); |
52 | | - } |
53 | | - |
54 | | - stopView(key: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
55 | | - return this.nativeRum.stopView(key, context, timestampMs); |
56 | | - } |
57 | | - |
58 | | - startAction(type: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
59 | | - return this.nativeRum.startAction(type, name, context, timestampMs); |
60 | | - } |
61 | | - |
62 | | - stopAction(context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
63 | | - return this.nativeRum.stopAction(context, timestampMs); |
64 | | - } |
65 | | - |
66 | | - addAction(type: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
67 | | - return this.nativeRum.addAction(type, name, context, timestampMs); |
68 | | - } |
69 | | - |
70 | | - startResource(key: string, method: string, url: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
71 | | - return this.nativeRum.startResource(key, method, url, context, timestampMs); |
72 | | - } |
73 | | - |
74 | | - stopResource(key: string, statusCode: number, kind: string, size: number = -1, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
75 | | - return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs); |
76 | | - } |
77 | | - |
78 | | - addError(message: string, source: string, stacktrace: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
79 | | - let updatedContext: any = context; |
80 | | - updatedContext["_dd.error.source_type"] = "react-native"; |
81 | | - return this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs); |
82 | | - } |
83 | | - |
84 | | - addTiming(name: string): Promise<void> { |
85 | | - return this.nativeRum.addTiming(name); |
86 | | - } |
87 | | - |
| 56 | + private nativeRum: DdRumType = NativeModules.DdRum; |
| 57 | + |
| 58 | + startView(key: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 59 | + InternalLog.log("Starting RUM View “" + name + "” #" + key, SdkVerbosity.DEBUG); |
| 60 | + return this.nativeRum.startView(key, name, context, timestampMs); |
| 61 | + } |
| 62 | + |
| 63 | + stopView(key: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 64 | + InternalLog.log("Stopping RUM View #" + key, SdkVerbosity.DEBUG); |
| 65 | + return this.nativeRum.stopView(key, context, timestampMs); |
| 66 | + } |
| 67 | + |
| 68 | + startAction(type: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 69 | + InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG); |
| 70 | + return this.nativeRum.startAction(type, name, context, timestampMs); |
| 71 | + } |
| 72 | + |
| 73 | + stopAction(context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 74 | + InternalLog.log("Stopping current RUM Action", SdkVerbosity.DEBUG); |
| 75 | + return this.nativeRum.stopAction(context, timestampMs); |
| 76 | + } |
| 77 | + |
| 78 | + addAction(type: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 79 | + InternalLog.log("Adding RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG); |
| 80 | + return this.nativeRum.addAction(type, name, context, timestampMs); |
| 81 | + } |
| 82 | + |
| 83 | + startResource(key: string, method: string, url: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 84 | + InternalLog.log("Starting RUM Resource #" + key + " " + method + ": " + url, SdkVerbosity.DEBUG); |
| 85 | + return this.nativeRum.startResource(key, method, url, context, timestampMs); |
| 86 | + } |
| 87 | + |
| 88 | + stopResource(key: string, statusCode: number, kind: string, size: number = -1, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 89 | + InternalLog.log("Stopping RUM Resource #" + key + " status:" + statusCode, SdkVerbosity.DEBUG); |
| 90 | + return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs); |
| 91 | + } |
| 92 | + |
| 93 | + addError(message: string, source: string, stacktrace: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> { |
| 94 | + InternalLog.log("Adding RUM Error “" + message + "”", SdkVerbosity.DEBUG); |
| 95 | + let updatedContext: any = context; |
| 96 | + updatedContext["_dd.error.source_type"] = "react-native"; |
| 97 | + return this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs); |
| 98 | + } |
| 99 | + |
| 100 | + addTiming(name: string): Promise<void> { |
| 101 | + InternalLog.log("Adding timing “" + name + "” to RUM View", SdkVerbosity.DEBUG); |
| 102 | + return this.nativeRum.addTiming(name); |
| 103 | + } |
88 | 104 | } |
89 | 105 |
|
90 | 106 | const DdSdk: DdSdkType = NativeModules.DdSdk; |
|
0 commit comments