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

Offer @traced macro when macros gain function body replacement capabilities #125

Open
stevapple opened this issue May 25, 2023 · 4 comments · Fixed by apple/swift-distributed-tracing-extras#42
Milestone

Comments

@stevapple
Copy link
Contributor

stevapple commented May 25, 2023

Typically we trace at function level by wrapping the whole implementation in a span, as demonstrated by the sample.

func makeDinner() async throws -> Meal {
  try await withSpan("makeDinner") { _ in
    async let veggies = try chopVegetables()
    async let meat = marinateMeat()
    async let oven = preheatOven(temperature: 350)
    // ...
    return try await cook(veggies, meat, oven)
  }
}

It makes me think if we can have an @Traced macro attached to functions, which handles the span automatically for users. Eventually such macro should be configurable (explicit tracer, span name, extracting context from parameters, etc.), but AFAIK Swift macros seem not having such level of expressiveness yet.

@Traced
func makeDinner() async throws -> Meal {
  async let veggies = try chopVegetables()
  async let meat = marinateMeat()
  async let oven = preheatOven(temperature: 350)
  // ...
  return try await cook(veggies, meat, oven)
}
@ktoso
Copy link
Member

ktoso commented May 25, 2023

Yes, this is planned but we're missing macro functionality to pull it off.

We need "function body macros" -- once those ship we'll ship such macro in this library 👍

@ktoso ktoso added this to the x.x - future milestone May 25, 2023
@ktoso ktoso changed the title Macros for tracing a function — maybe in the extras package Offer @traced macro when macros gain function body replacement capabilities May 26, 2023
@ktoso
Copy link
Member

ktoso commented May 26, 2023

rdar://109247127

@porglezomp
Copy link
Contributor

Since function body macros ship with Swift 6.0 (swiftlang/swift#73765) is this unblocked now?

@ktoso
Copy link
Member

ktoso commented Nov 26, 2024

Additional info: Backed out the traced macro until we can figure out a policy about macros adoption in this package that would not hinder upgrades of the dependency for folks not even using the macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment