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

ActivityContextManager drops an active span when a first child span ends #420

Closed
PavelChernyshov opened this issue Jun 5, 2023 · 0 comments
Assignees

Comments

@PavelChernyshov
Copy link

PavelChernyshov commented Jun 5, 2023

Hi,

I've noticed a strange behavior, which I believe is not right.

Consider the following code:

func testContextPropagationTwoSequentialChildSpans() {
        let parentSpan = defaultTracer.spanBuilder(spanName: "Parent").setActive(true).startSpan()
        OpenTelemetry.instance.contextProvider.setActiveSpan(parentSpan)

        let child1 = defaultTracer.spanBuilder(spanName: "child1").startSpan()
        child1.end()

        let child2 = defaultTracer.spanBuilder(spanName: "child2").startSpan()
        child2.end()

        parentSpan.end()

        XCTAssertEqual(parentSpan.context.traceId, child1.context.traceId)
        XCTAssertEqual(parentSpan.context.traceId, child2.context.traceId) <<<Fails here
    }

I would expect the second child span to share the context with the parent, but in reality it's a root one.

The test is available here

I'm not ready to contribute a patch at this point, os.activity is kind of new to me and I haven't dug deep enough into ActivityContextManager to be sure not to break something else.

However, this is what I observed:

  • When child1 ends it clears contextMap.
  • When child2 is started ActivityContextManager.getCurrentContextValue(forKey:) returns nil.

Other things here that raise my brow:

  • I would expect .setActive(_ active: Bool) to work for the DefaultTracer implementation as well.

Thanks, Pavel.

@PavelChernyshov PavelChernyshov changed the title ActivityContext ActivityContextManager drops an active span, when a sub-span ends Jun 5, 2023
@PavelChernyshov PavelChernyshov changed the title ActivityContextManager drops an active span, when a sub-span ends ActivityContextManager drops an active span when a sub-span ends Jun 5, 2023
@PavelChernyshov PavelChernyshov changed the title ActivityContextManager drops an active span when a sub-span ends ActivityContextManager drops an active span when a first child span ends Jun 5, 2023
@nachoBonafonte nachoBonafonte self-assigned this Jun 29, 2023
@bryce-b bryce-b closed this as completed Oct 26, 2023
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 a pull request may close this issue.

3 participants