ApodiniCollector
combines Collector with the Apodini framework used to create web services. it allows you to create trace spans, record metrics, and provide them to Prometheus instances.
Apodini Collector provides integration in Apodini to configure and create trace spans in the web service. You can create a TracerConfiguration
that defines global settings for the traces in the WebService
configuration.
import Apodini
import ApodiniCollector
import ArgumentParser
import Foundation
@main
struct ExampleWebService: WebService {
@Option var jaegerCollectorURL = URL(string: "http://localhost:14250")! // swiftlint:disable:this force_unwrapping
var configuration: Apodini.Configuration {
TracerConfiguration(
serviceName: "example",
jaegerURL: jaegerCollectorURL
)
// ...
}
var content: some Component {
Group("metrics") {
MetricsHandler()
}
// ...
}
}
By using Apodini Collector, you can access the current tracer using the Apodini @Environment
: @Environment(\.tracer) var tracer: Tracer
Apodini Collector exposes the tracing API defined in Collector and allows you to propargate the spans in HTTPRequests of AsyncHTTPClient or propargated in Apodini Responses
:
var request = try HTTPClient.Request(url: "http://ase.in.tum.de/schmiedmayer")
let span = tracer.span(name: "Example")
span.propagate(in: &request)
In addition spans can be retrieved from AsyncHTTPClient responses or the Apodini connection context:
import Apodini
import ApodiniCollector
struct ExampleHandler: Handler {
@Environment(\.tracer) var tracer: Tracer
@Environment(\.connection) var connection: Connection
func handle() -> String {
let span = tracer.span(name: "location", from: connection)
// ...
}
Apodini Collector exports the metrics creation API defined by the Collector framework.
In addition to exporting the Collector API surface Apodini Collector provides a MetricsHandler
Handler
enabling Prometheus instances to retrieve metrics information from the web service instance:
import Apodini
import ApodiniCollector
@main
struct ExampleWebService: WebService {
var configuration: Apodini.Configuration {
// ...
}
var content: some Component {
Group("metrics") {
MetricsHandler()
}
// ...
}
}
Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.
This project is licensed under the MIT License. See License for more information.