Performance Monitoring은 앱의 성능을 모니터링하는 데 도움이 되는 trace를 수집합니다. trace는 앱에서 두 시점 간에 캡처된 성능 데이터 보고서입니다.
Performance Monitoring에서 자동으로 수집하는 네트워크 요청 trace에는 앱의 네트워크 요청이 대부분 포함됩니다. 그러나 일부 요청이 보고되지 않거나 다른 라이브러리를 사용하여 네트워크를 요청하는 경우도 있습니다. 이러한 경우 Performance Monitoring API를 사용하여 커스텀 네트워크 요청 trace를 수동으로 계측할 수 있습니다. 커스텀 네트워크 요청 trace는 Apple 및 Android 앱에서만 지원됩니다.
커스텀 네트워크 요청 trace의 기본 측정항목은 Performance Monitoring에서 자동으로 수집하는 네트워크 요청 trace와 동일하며, 이는 구체적으로 응답 시간, 응답 및 요청 페이로드 크기, 성공률입니다. 커스텀 네트워크 요청 trace는 커스텀 측정항목 추가를 지원하지 않습니다.
코드에서는 Performance Monitoring SDK에서 제공하는 API를 사용하여 커스텀 네트워크 요청 trace의 시작과 끝을 정의합니다.
커스텀 네트워크 요청 trace는 Performance Monitoring에서 자동으로 캡처한 네트워크 요청과 함께 Firebase Console에 표시됩니다(trace 테이블의 네트워크 요청 하위 탭에 있음).
커스텀 네트워크 요청 trace 추가
Performance MonitoringHttpMetric API를 사용하여 특정 네트워크 요청을 모니터링하는 커스텀 네트워크 요청 trace를 추가합니다.
Performance Monitoring에서 커스텀 네트워크 요청을 수동으로 계측하려면 다음과 유사한 코드를 추가합니다.
Kotlin
valurl=URL("https://www.google.com")valmetric=Firebase.performance.newHttpMetric("https://www.google.com",FirebasePerformance.HttpMethod.GET,)metric.trace{valconn=url.openConnection()asHttpURLConnectionconn.doOutput=trueconn.setRequestProperty("Content-Type","application/json")try{valoutputStream=DataOutputStream(conn.outputStream)outputStream.write(data)}catch(ignored:IOException){}// Set HttpMetric attributessetRequestPayloadSize(data.size.toLong())setHttpResponseCode(conn.responseCode)printStreamContent(conn.inputStream)conn.disconnect()}
[null,null,["최종 업데이트: 2025-08-21(UTC)"],[],[],null,["# Add custom monitoring for specific network requests (Apple & Android apps)\n\n\u003cbr /\u003e\n\niOS+ Android Flutter \n\n\u003cbr /\u003e\n\nPerformance Monitoring collects *traces* to help you monitor the performance of your app. A\ntrace is a report of performance data captured between two points in time in\nyour app.\n\nThe\n[network request traces automatically collected by Performance Monitoring](/docs/perf-mon/network-traces)\ninclude most network requests for your app. However, some requests might not be\nreported or you might use a different library to make network requests. In these\ncases, you can use the Performance Monitoring API to manually instrument\n***custom network request traces***. Custom network request traces are only\nsupported for Apple and Android apps.\n\nThe default metrics for a custom network request trace are the same as those for\nthe network request traces automatically collected by Performance Monitoring, specifically\nresponse time, response and request payload size, and success rate. Custom\nnetwork request traces do not support adding custom metrics.\n\nIn your code, you define the beginning and the end of a custom network request\ntrace using the APIs provided by the Performance Monitoring SDK.\n\nCustom network request traces appear in the Firebase console alongside the\nnetwork requests that Performance Monitoring captures automatically\n(in the *Network requests* subtab of the traces table).\n\nAdd custom network request traces\n---------------------------------\n\nUse the Performance Monitoring HTTPMetric API\n([Swift](/docs/reference/swift/firebaseperformance/api/reference/Classes/HTTPMetric)\n\\|\n[Obj-C](/docs/reference/ios/firebaseperformance/api/reference/Classes/FIRHTTPMetric))\nto add custom network request traces to monitor specific network requests.\n\nTo manually instrument custom network requests in Performance Monitoring, add code similar\nto the following: \n\n### Swift\n\n\n**Note:** This Firebase product is not available on macOS, Mac Catalyst, watchOS targets. \n\n guard let metric = HTTPMetric(url: \"https://www.google.com\", httpMethod: .get) else { return }\n\n metric.start()\n guard let url = URL(string: \"https://www.google.com\") else { return }\n let request: URLRequest = URLRequest(url:url)\n let session = URLSession(configuration: .default)\n let dataTask = session.dataTask(with: request) { (urlData, response, error) in\n if let httpResponse = response as? HTTPURLResponse {\n metric.responseCode = httpResponse.statusCode\n }\n metric.stop()\n }\n dataTask.resume()\n\n### Objective-C\n\n\n**Note:** This Firebase product is not available on macOS, Mac Catalyst, watchOS targets. \n\n @property (nonatomic) FIRHTTPMetric *metric;\n\n - (void)beginManualNetworkInstrumentation {\n self.metric =\n [[FIRHttpMetric alloc] initWithURL:[NSURL URLWithString:@\"https://www.google.com\"]\n HTTPMethod:FIRHTTPMethodGET];\n\n [self.metric start];\n\n NSURLRequest *request =\n [NSURLRequest requestWithURL:[NSURL URLWithString:@\"https://www.google.com\"]];\n NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request\n delegate:self];\n [connection resume];\n }\n\n - (void)connection:(NSURLConnection *)connection\n didReceiveResponse:(NSURLResponse *) response {\n NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response\n self.metric.responseCode = httpResponse.statusCode;\n [self.metric stop];\n }\n\nCustom network request traces also support adding custom attributes\n([Swift](/docs/reference/swift/firebaseperformance/api/reference/Protocols/PerformanceAttributable#setvalue_:forattribute:) \\|\n[Obj-C](/docs/reference/ios/firebaseperformance/api/reference/Protocols/FIRPerformanceAttributable#-setvalue:forattribute:))\nbut not custom metrics.\n\nNext steps\n----------\n\n- [Set up alerts](/docs/perf-mon/alerts) for network requests that are degrading the performance of your app. For example, you can configure an email alert for your team if the *response time* for a specific URL pattern exceeds a threshold that you set."]]