Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Protocol to enable passing "context: CarriesBaggageContext"  #7

@ktoso

Description

@ktoso

Goals:

  • easily be used "in" frameworks without them having to "be" a (Baggage)Context
    • e.g. frameworkContext.theMetadataContext -- is nested, not "is"

What if we did

// in module Baggage
// so you'd `import Baggage`

protocol ContextCarrier { 
  var baggage: Context { get set }

  subscript<Key: ContextKey>(_ key: Key.Type) -> Key.Value? { get set }
}

struct Context { ... }

extension Context: ContextCarrier { 
  var baggage = self ... 
  ... 
}

This way other libs can:

  • carry Context without being one
  • the module name and type name don't clash:
    • module Baggage
    • and type name Context
  • implement the "accessors" (var zipkinTrace: ...) on the BaggageContextCarrier protocol
    • and it become available on Context as well as "my-framework-context" (any of them for that matter 🎉 )

We do have disambiguation that it's the Baggage.Context is any other lib has a Context type and they'd clash.

For passing around:

  • libs unaware of frameworks could use func hello(who: String, context: BaggageContextCarrier)
    • this way any library can call hello(who: "me", context: myFrameworkSpecificContext)
    • this can be optional though if they dont want to
    • if they lib does not do this, users would have to pass hello(who: "me", context: myFrameworkSpecificContext.baggage) which again reads quite well
      • or if they have the "raw" context they can pass context 👍

Let's explore this idea a bit 👀

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions