apple / swift-distributed-tracing

Instrumentation library for Swift server applications
https://swiftpackageindex.com/apple/swift-distributed-tracing/main/documentation/tracing
Apache License 2.0
222 stars 30 forks source link

`addEvent` and `recordError` should take `clock` argument #119

Closed slashmo closed 1 year ago

slashmo commented 1 year ago

addEvent and its related recordError method should take a clock argument, defaulting to DefaultTracerClock(). This would allow us to mock the clock similarly to how we can already do it when calling Span.end().

ktoso commented 1 year ago

Agreed, on it :+1:

ktoso commented 1 year ago

in addEvent no, because the Event creation will have it:

    func addEvent(_ event: SpanEvent)
    public init<Instant: TracerInstant>(name: String,
                                    at instant: @autoclosure () -> Instant,
                                    attributes: SpanAttributes = [:])
    {

record error is a good call tho, added:


    func recordError<Instant: TracerInstant>(_ error: Error,
                                             attributes: SpanAttributes,
                                             at instant: @autoclosure () -> Instant)

    public func recordError(_ error: Error, attributes: SpanAttributes) {
        self.recordError(error, attributes: attributes, at: DefaultTracerClock.now)
    }