Skip to content

[PATCH] [bug] Fix ignored at argument in two instances of withSpan #139

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

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Tracing/Tracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public func withSpan<T, Instant: TracerInstant>(
) rethrows -> T {
try InstrumentationSystem.legacyTracer.withAnySpan(
operationName,
at: DefaultTracerClock.now,
at: instant(),
context: context(),
ofKind: kind,
function: function,
Expand Down Expand Up @@ -339,7 +339,7 @@ public func withSpan<T, Instant: TracerInstant>(
) async rethrows -> T {
try await InstrumentationSystem.legacyTracer.withAnySpan(
operationName,
at: DefaultTracerClock.now,
at: instant(),
context: context(),
ofKind: kind,
function: function,
Expand Down
16 changes: 16 additions & 0 deletions Tests/TracingTests/TracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,22 @@ final class TracerTests: XCTestCase {
tracer.withAnySpan("", context: .topLevel) { _ in }
}

func testWithSpanShouldNotMissPropagatingInstant() {
let tracer = TestTracer()
InstrumentationSystem.bootstrapInternal(tracer)
defer {
InstrumentationSystem.bootstrapInternal(nil)
}

let clock = DefaultTracerClock()

let instant = clock.now
withSpan("span", at: instant) { _ in }

let span = tracer.spans.first!
XCTAssertEqual(span.startTimestampNanosSinceEpoch, instant.nanosecondsSinceEpoch)
}

#if swift(>=5.7.0)
// @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
/// Helper method to execute async operations until we can use async tests (currently incompatible with the generated LinuxMain file).
Expand Down