@@ -4,6 +4,12 @@ export function startTrace(name: string): FirebaseTrace {
44 return new FirebaseTrace ( FIRPerformance . startTraceWithName ( name ) ) ;
55}
66
7+ export function startHttpMetric ( url : string , method : string ) {
8+ const httpMetric = FIRHTTPMetric . alloc ( ) . initWithURLHTTPMethod ( NSURL . URLWithString ( url ) , getHttpMethodFromString ( method ) ) ;
9+ httpMetric . start ( ) ;
10+ return new FirebaseHttpMetric ( httpMetric ) ;
11+ }
12+
713export class FirebaseTrace {
814 constructor ( private nativeTrace : FIRTrace ) {
915 }
@@ -32,3 +38,41 @@ export class FirebaseTrace {
3238 this . nativeTrace . stop ( ) ;
3339 }
3440}
41+
42+ export class FirebaseHttpMetric {
43+ constructor ( private nativeHttpMetric : FIRHTTPMetric ) {
44+ }
45+
46+ setRequestPayloadSize ( size : number ) {
47+ this . nativeHttpMetric . requestPayloadSize = size ;
48+ }
49+
50+ setHttpResponseCode ( responseCode : number ) {
51+ this . nativeHttpMetric . responseCode = responseCode ;
52+ }
53+
54+ stop ( ) : void {
55+ this . nativeHttpMetric . stop ( ) ;
56+ }
57+ }
58+
59+ function getHttpMethodFromString ( method : string ) : FIRHTTPMethod {
60+ switch ( method ) {
61+ case 'GET' :
62+ return FIRHTTPMethod . GET ;
63+ case 'PUT' :
64+ return FIRHTTPMethod . PUT ;
65+ case 'POST' :
66+ return FIRHTTPMethod . POST ;
67+ case 'DELETE' :
68+ return FIRHTTPMethod . DELETE ;
69+ case 'HEAD' :
70+ return FIRHTTPMethod . HEAD ;
71+ case 'PATCH' :
72+ return FIRHTTPMethod . PATCH ;
73+ case 'OPTIONS' :
74+ return FIRHTTPMethod . OPTIONS ;
75+ default :
76+ return null ;
77+ }
78+ }
0 commit comments