Skip to content

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

Merged
merged 2 commits into from
Apr 21, 2023
Merged

consider TracerSpan assoc type -> Span #111

merged 2 commits into from
Apr 21, 2023

Conversation

ktoso
Copy link
Member

@ktoso ktoso commented Mar 30, 2023

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 hmmm

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

@fabianfett
Copy link
Member

@ktoso can you give an example for this?

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.

@@ -59,7 +59,7 @@ extension Tracer {
function: String = #function,
file fileID: String = #fileID,
line: UInt = #line
) -> any Span {
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member Author

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

Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

@stevapple stevapple Apr 9, 2023

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:)

Copy link
Member

@fabianfett fabianfett Apr 13, 2023

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.

Copy link
Contributor

@stevapple stevapple Apr 13, 2023

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`
@ktoso ktoso force-pushed the wip-tracer-rename-again branch from c6b69c0 to aee8645 Compare April 7, 2023 08:28
Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

Love the change!

@ktoso
Copy link
Member Author

ktoso commented Apr 13, 2023

Yeah I think this will be fine. I'll merge tomorrow probably tho

@ktoso
Copy link
Member Author

ktoso commented Apr 19, 2023

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.

@ktoso ktoso enabled auto-merge (squash) April 19, 2023 09:46
@ktoso ktoso force-pushed the wip-tracer-rename-again branch from e7b6aa8 to bdffc42 Compare April 21, 2023 06:30
@ktoso ktoso force-pushed the wip-tracer-rename-again branch from bdffc42 to 09706c0 Compare April 21, 2023 06:35
@ktoso ktoso merged commit 3d152af into main Apr 21, 2023
@ktoso ktoso deleted the wip-tracer-rename-again branch April 21, 2023 06:39
@ktoso ktoso added this to the 1.0.0-beta.2 milestone Apr 21, 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 this pull request may close these issues.

Rename TracerProtocol.TracerSpan -> TracerProtocol.Span
3 participants