generated from dankinsoid/iOSLibraryTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5f8245
commit 3ed7acf
Showing
8 changed files
with
104 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,60 @@ | ||
import Metrics | ||
import HTTPTypes | ||
import Foundation | ||
import HTTPTypes | ||
import Metrics | ||
|
||
func updateTotalRequestsMetrics( | ||
for request: HTTPRequestComponents | ||
for request: HTTPRequestComponents | ||
) { | ||
Counter( | ||
label: "api_client_requests_total", | ||
dimensions: dimensions(for: request) | ||
).increment() | ||
Counter( | ||
label: "api_client_requests_total", | ||
dimensions: dimensions(for: request) | ||
).increment() | ||
} | ||
|
||
func updateTotalResponseMetrics( | ||
for request: HTTPRequestComponents, | ||
successful: Bool | ||
for request: HTTPRequestComponents, | ||
successful: Bool | ||
) { | ||
Counter( | ||
label: "api_client_responses_total", | ||
dimensions: dimensions(for: request) + [("successful", successful.description)] | ||
).increment() | ||
if !successful { | ||
updateTotalErrorsMetrics(for: request) | ||
} | ||
Counter( | ||
label: "api_client_responses_total", | ||
dimensions: dimensions(for: request) + [("successful", successful.description)] | ||
).increment() | ||
if !successful { | ||
updateTotalErrorsMetrics(for: request) | ||
} | ||
} | ||
|
||
func updateTotalErrorsMetrics( | ||
for request: HTTPRequestComponents? | ||
for request: HTTPRequestComponents? | ||
) { | ||
Counter( | ||
label: "api_client_errors_total", | ||
dimensions: dimensions(for: request) | ||
).increment() | ||
Counter( | ||
label: "api_client_errors_total", | ||
dimensions: dimensions(for: request) | ||
).increment() | ||
} | ||
|
||
func updateHTTPMetrics( | ||
for request: HTTPRequestComponents?, | ||
status: HTTPResponse.Status?, | ||
duration: Double, | ||
successful: Bool | ||
for request: HTTPRequestComponents?, | ||
status: HTTPResponse.Status?, | ||
duration: Double, | ||
successful: Bool | ||
) { | ||
var dimensions = dimensions(for: request) | ||
dimensions.append(("status", status?.code.description ?? "undefined")) | ||
dimensions.append(("successful", successful.description)) | ||
Timer( | ||
label: "http_client_request_duration_seconds", | ||
dimensions: dimensions, | ||
preferredDisplayUnit: .seconds | ||
) | ||
.recordSeconds(duration) | ||
var dimensions = dimensions(for: request) | ||
dimensions.append(("status", status?.code.description ?? "undefined")) | ||
dimensions.append(("successful", successful.description)) | ||
Timer( | ||
label: "http_client_request_duration_seconds", | ||
dimensions: dimensions, | ||
preferredDisplayUnit: .seconds | ||
) | ||
.recordSeconds(duration) | ||
} | ||
|
||
private func dimensions( | ||
for request: HTTPRequestComponents? | ||
for request: HTTPRequestComponents? | ||
) -> [(String, String)] { | ||
[ | ||
("method", request?.method.rawValue ?? "undefined"), | ||
("path", request?.urlComponents.path ?? "undefined") | ||
] | ||
[ | ||
("method", request?.method.rawValue ?? "undefined"), | ||
("path", request?.urlComponents.path ?? "undefined"), | ||
] | ||
} |