Skip to content

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

Open
apple/swift-distributed-tracing-extras
#42

Description

@stevapple

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

Activity

  1. ktoso commented on May 25, 2023

    @ktoso
    Member

    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 👍

  2. added this to the x.x - future milestone on May 25, 2023
  3. changed the title [-]Macros for tracing a function — maybe in the `extras` package[/-] [+]Offer @traced macro when macros gain function body replacement capabilities[/+] on May 26, 2023
  4. ktoso commented on May 26, 2023

    @ktoso
    Member

    rdar://109247127

  5. porglezomp commented on Aug 22, 2024

    @porglezomp
    Contributor

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

  6. reopened this on Nov 26, 2024
  7. ktoso commented on Nov 26, 2024

    @ktoso
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions