Skip to content

Add test for start_observe with external parent span#102

Closed
Copilot wants to merge 3 commits into
fix/fastapifrom
copilot/sub-pr-101
Closed

Add test for start_observe with external parent span#102
Copilot wants to merge 3 commits into
fix/fastapifrom
copilot/sub-pr-101

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 26, 2026

Root-span detection now treats start_observe spans as Basalt roots when a non-Basalt parent span exists (e.g., from FastAPI/httpx instrumentation). Existing tests didn't cover this case.

Changes

  • Added test_start_observe_with_external_parent_span: Verifies that start_observe correctly establishes a Basalt root when an external OpenTelemetry span exists as parent but ROOT_SPAN_CONTEXT_KEY is not set

The test simulates the scenario where framework instrumentation creates a parent span, then asserts:

  • basalt.root attribute is set to True
  • ROOT_SPAN_CONTEXT_KEY is attached to the context
# Simulate external instrumentation (FastAPI, httpx, etc.)
external_tracer = provider.get_tracer("external.instrumentation")
external_span = external_tracer.start_span("external_http_request")
external_context = trace.set_span_in_context(external_span)
otel_context.attach(external_context)

# start_observe should treat this as a new Basalt root
with StartObserve(name="test_basalt_root", feature_slug="test_feature") as span:
    assert span._span.attributes.get("basalt.root") is True
    assert otel_context.get_value(ROOT_SPAN_CONTEXT_KEY) is not None

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 26, 2026 13:45
Co-authored-by: CorentinGS <43623834+CorentinGS@users.noreply.github.com>
Co-authored-by: CorentinGS <43623834+CorentinGS@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on feat: examples pull request Add test for start_observe with external parent span Jan 26, 2026
Copilot AI requested a review from CorentinGS January 26, 2026 13:47
@CorentinGS CorentinGS deleted the branch fix/fastapi January 28, 2026 16:01
@CorentinGS CorentinGS closed this Jan 28, 2026
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.

2 participants