Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-675 Add tracer.startRootSpan() API #236

Merged
merged 1 commit into from
Sep 1, 2020

Conversation

ncreated
Copy link
Member

@ncreated ncreated commented Sep 1, 2020

What and why?

📦 This PR adds the startRootSpan() API to Datadog.Tracer.

This API enables using setActive() span in asynchronous jobs, e.g.:

func makeAPIRequest(on queue: DispatchQueue, completion: @escaping () -> Void) {
    let requestSpan = tracer
        .startRootSpan(operationName: "request")
        .setActive() // set active, so the asynchronous job can continue the trace without the span reference

    queue.asyncAfter(deadline: .now() + 1) {
        let responseDecodingSpan = tracer.startSpan(operationName: "response decoding")
        responseDecodingSpan.finish()
        requestSpan.finish()
        completion()
    }
}

makeAPIRequest(on: queue) {}
makeAPIRequest(on: queue) {}

which results with two root "request" spans, each having "response decoding" child span.

How?

New API was introduced:

/// Start a new root span with the given operation name.
/// - Parameters:
///   - operationName: the operation name for the newly-started span
///   - tags:          a set of tag keys and values per `OTSpan#setTag:value:`, or `nil` to start with
///                    an empty tag map
///   - startTime:     an explicitly specified start timestamp for the `OTSpan`, or `nil` to use the
///                    current walltime
/// - returns:         a valid Span instance; it is the caller's responsibility to call `finish()`.
func startRootSpan(
    operationName: String,
    tags: [String: Encodable]?,
    startTime: Date?
) -> OTSpan

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference

@ncreated ncreated requested a review from a team as a code owner September 1, 2020 15:10
@ncreated ncreated self-assigned this Sep 1, 2020
Copy link
Contributor

@buranmert buranmert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. setActive() can be called both on normal and root spans, correct?
  2. are we gonna add this to the OpenTracing/Telemetry API (the original repo) as well?

@ncreated
Copy link
Member Author

ncreated commented Sep 1, 2020

  • setActive() can be called both on normal and root spans, correct?

Yes. Regular span can become the active span in the current execution context. Same for the root span.

  • are we gonna add this to the OpenTracing/Telemetry API (the original repo) as well?

Not for OT, as there's no activity in opentracing-swift for many months which is why we decided to put the OT code in our repo. Not sure if there's startRootSpan() concept in OTel - @nachoBonafonte ?

@nachoBonafonte
Copy link
Contributor

In OTel, there is a span builder, and it has a setNoParent() method, that basically makes a span a root span when is built

@ncreated ncreated merged commit 40b7c77 into rum Sep 1, 2020
@ncreated ncreated deleted the ncreated/RUMM-675-add-start-root-span-API branch September 1, 2020 16:07
@ncreated ncreated mentioned this pull request Sep 2, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants