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 · 2 comments
Labels
1 - triaged Task makes sense, is well defined, and is ready to be worked on
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 added the 1 - triaged Task makes sense, is well defined, and is ready to be worked on label 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged Task makes sense, is well defined, and is ready to be worked on
Projects
None yet
Development

No branches or pull requests

2 participants