Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Consider tracer.withSpan() { ... } convenience APIs #98

Open
ktoso opened this issue Jul 27, 2020 · 0 comments
Open

Consider tracer.withSpan() { ... } convenience APIs #98

ktoso opened this issue Jul 27, 2020 · 0 comments

Comments

@ktoso
Copy link
Collaborator

ktoso commented Jul 27, 2020

We can consider tracer.withSpan { ... } APIs for fluent synchronous usage so calling end is less annoying.


its good to know there is an error but I dont htink theres much user could do about it and logger/tracer should help and not make life difficult

last but not least, I think its good to provide some helpers with closures containing deferred "ends", something like https://github.com/pokryfka/aws-xray-sdk-swift/blob/master/Sources/AWSXRayRecorder/Recorder%2BHelpers.swift

no need to end explicitly:

recorder.segment(name: "Segment 2", context: context) { segment in
    try? segment.subsegment(name: "Subsegment 2.1") { segment in
        _ = segment.subsegment(name: "Subsegment 2.1.1 with Result") { _ -> String in
            usleep(100_000)
            return "Result"
        }
        try segment.subsegment(name: "Subsegment 2.1.2 with Error") { _ in
            usleep(200_000)
            throw ExampleError.test
        }
    }
}

note that it does not throw but it does rethrow so no need to try subsegment "Subsegment 2.1.1 "

Originally posted by @pokryfka in #96 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant