-
Notifications
You must be signed in to change notification settings - Fork 40
consider TracerSpan assoc type -> Span #111
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
Conversation
@ktoso can you give an example for this?
|
Sources/Tracing/Tracer.swift
Outdated
@@ -59,7 +59,7 @@ extension Tracer { | |||
function: String = #function, | |||
file fileID: String = #fileID, | |||
line: UInt = #line | |||
) -> any Span { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to be explicit here? Where is the conflict coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah here I can likely just do Span, that's right.
In a TracerProtocol
we sometimes had to be explicit.
I can give this a cleanup pass
@@ -48,7 +48,7 @@ public struct NoOpTracer: LegacyTracerProtocol { | |||
// no-op | |||
} | |||
|
|||
public struct NoOpSpan: Span { | |||
public struct NoOpSpan: Tracing.Span { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one annoying spot, people MUST write Tracing.Span here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about swapping TracerSpan
and Span
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, what do @tomerd @fabianfett @Lukasa think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find this to annoying. The tough part here is really only on the tracer implementers. TracerSpan is on all the users. If we want to keep the pain small, the first group should deal with it, not the second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's on implementors to do the dance, I don't mind either I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer TracerSpan
to [Tracing.]Span
here. Swift’s name lookup is still tricky now (see https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482 for the context). If the client happens to have a top-level Tracing
type, it will completely lose access to Tracing.Span
. Not to say TracerSpan
is shorter by two ASCII characters:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree with the argument here. Using Tracing.Span
is an escape hatch, when you define the Span type inside a Tracer. If you implement a Tracer
you must import Tracing
. If you then introduce a local type Tracing
, you are screwed anyway. Rule number one of Swift namespaces: Don't name a type like a module you import.
If we look at it from the perspective of a tracing user, it is much nicer to write Span
everywhere instead of using TracerSpan
. The argument you make, that Swift namespace lookup sometimes isn't working correctly (by breaking Rule number one of Swift namespaces: Don't name a type like a module you import) does apply to Span
as it does to TracerSpan
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A typical tracing user doesn’t use either [Tracing.]Span
or Tracer.Span
, as the Tracer.Span
type can be inferred from Tracer.startSpan
.
Both Span
and TracerSpan
can cause some confusion with Tracer.Span
, but the fact that Span
is ambiguous, despite being possible to work around and comfort the compiler, will inevitably troubles code review.
Given that the type name is not used very often, I would still suggest the longer but less error-prone TracerSpan
.
**Motivation:** Users who use generic `Tracer` end up having to spell `Tracer.TracerSpan`. We could help those situations by renaming the associated type. However at the cost of causing name conflicts where the Span implementation must qualify that it is implementing `Tracing.Span`. This may or may not be worth it -- discuss. **Modifications:** `associatedtype TracerSpan: Span` -> `associatedtype Span: Tracing.Span`
c6b69c0
to
aee8645
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the change!
Yeah I think this will be fine. I'll merge tomorrow probably tho |
Let's give this a shot -- thank you for the discussion @stevapple and @fabianfett, I think Fabian made a good point and we can try this out in the next beta. I think it'll work out fine. |
e7b6aa8
to
bdffc42
Compare
bdffc42
to
09706c0
Compare
Something @fabianfett requested we give another look at.
Resolves #110 but we should discuss this more -- it comes with a confusing tradeoff for implementers of spans I suppose. Please discuss. I'm on the fence, it is nice to not have
Tracer.TracerSpan
but the tradeoff is some potential confusion hmmmMotivation:
Users who use generic
Tracer
end up having to spellTracer.TracerSpan
.We could help those situations by renaming the associated type. However at the cost of causing name conflicts where the Span implementation must qualify that it is implementing
Tracing.Span
.This may or may not be worth it -- discuss.
Modifications:
associatedtype TracerSpan: Span
->associatedtype Span: Tracing.Span