Skip to content

Adopt ServiceContext 1.0 #127

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
May 31, 2023
Merged

Adopt ServiceContext 1.0 #127

merged 2 commits into from
May 31, 2023

Conversation

ktoso
Copy link
Member

@ktoso ktoso commented May 26, 2023

Resolves #99

Motivation:
The baggage type ended up more useful than anticipated and we're renaming it to ServiceContext for the 1.0 release.

Many libraries and production systems end up passing context around which may not necessarily be related to tracing, which made us make this naming change. Functionally ServiceContext and Baggage are the same, but the way we talk about context propagation in general makes more sense if we call this a context stype.

Modifications:

Use the new type; The Baggage still exists in the InstrumentationBaggage module so people can still use it if they wanted to but it is a TYPEALIAS to the ServiceContext.

@ktoso ktoso requested review from tomerd, yim-lee and slashmo May 26, 2023 22:22
@ktoso ktoso marked this pull request as draft May 26, 2023 22:57
Copy link
Collaborator

@slashmo slashmo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

README.md Outdated
@@ -14,7 +14,7 @@ While Swift Distributed Tracing allows building all kinds of _instruments_, whic

This project uses the context progagation type defined independently in:

- 🧳 [swift-distributed-tracing-baggage](https://github.com/apple/swift-distributed-tracing-baggage) -- [`Baggage`](https://apple.github.io/swift-distributed-tracing-baggage/docs/current/InstrumentationBaggage/Structs/Baggage.html) (zero dependencies)
- 🧳 [swift-service-context](https://github.com/apple/swift-service-context) -- [`Baggage`](https://apple.github.io/swift-service-context/docs/current/ServiceContextModule/Structs/Baggage.html) (zero dependencies)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these links point to the Swift Package Index hosted docs instead? This one gives me a 404.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one should be 404 because Baggage is renamed. +1 for switching to SPI though.

README.md Outdated
@@ -330,7 +330,7 @@ InstrumentationSystem.bootstrap(MultiplexInstrument([FancyInstrument(), OtherFan
<a name="passing-context-objects"></a>
### Context propagation, by explicit `LoggingContext` passing

> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-distributed-tracing-baggage).
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated service context [ServiceContext](https://github.com/apple/swift-service-context).

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the intention was to embed type names in the sentence, so this should be better:

Suggested change
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [`Logger`](https://github.com/apple/swift-log) with an associated [`ServiceContext`](https://github.com/apple/swift-service-context).

@ktoso
Copy link
Member Author

ktoso commented May 27, 2023

Thanks for review! I’ll push this to completion on Monday I think

Copy link
Contributor

@stevapple stevapple left a comment

Choose a reason for hiding this comment

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

With the renaming it’s also worth clarifying the relationship between Swift ServiceContext and W3C Baggage / Trace Context, especially the latter — since this is package for distributed tracing.

Package.swift Outdated
@@ -14,7 +14,7 @@ let package = Package(
.library(name: "Tracing", targets: ["Tracing"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
.package(url: "https://github.com/apple/swift-service-context.git", .upToNextMinor(from: "1.0.0")),
Copy link
Contributor

Choose a reason for hiding this comment

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

With a stable 1.0 we don’t need .upToMextMinor any more.

Suggested change
.package(url: "https://github.com/apple/swift-service-context.git", .upToNextMinor(from: "1.0.0")),
.package(url: "https://github.com/apple/swift-service-context.git", from: "1.0.0"),

README.md Outdated
@@ -14,7 +14,7 @@ While Swift Distributed Tracing allows building all kinds of _instruments_, whic

This project uses the context progagation type defined independently in:

- 🧳 [swift-distributed-tracing-baggage](https://github.com/apple/swift-distributed-tracing-baggage) -- [`Baggage`](https://apple.github.io/swift-distributed-tracing-baggage/docs/current/InstrumentationBaggage/Structs/Baggage.html) (zero dependencies)
- 🧳 [swift-service-context](https://github.com/apple/swift-service-context) -- [`Baggage`](https://apple.github.io/swift-service-context/docs/current/ServiceContextModule/Structs/Baggage.html) (zero dependencies)
Copy link
Contributor

Choose a reason for hiding this comment

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

This one should be 404 because Baggage is renamed. +1 for switching to SPI though.

README.md Outdated
@@ -330,7 +330,7 @@ InstrumentationSystem.bootstrap(MultiplexInstrument([FancyInstrument(), OtherFan
<a name="passing-context-objects"></a>
### Context propagation, by explicit `LoggingContext` passing

> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-distributed-tracing-baggage).
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the intention was to embed type names in the sentence, so this should be better:

Suggested change
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [`Logger`](https://github.com/apple/swift-log) with an associated [`ServiceContext`](https://github.com/apple/swift-service-context).

await userCode(request)
}
}
}
```

This is introducing multiple layers of nesting, and we have un-necessarily restored, picked-up, and restored the baggage again. In order to avoid this duplicate work, it is beneficial to use the ``withSpan(_:baggage:ofKind:at:function:file:line:_:)-4o2b`` overload, which also accepts a `Baggage` as parameter, rather than picking it up from the task-local value:
This is introducing multiple layers of nesting, and we have un-necessarily restored, picked-up, and restored the context again. In order to avoid this duplicate work, it is beneficial to use the ``withSpan(_:context:ofKind:at:function:file:line:_:)-4o2b`` overload, which also accepts a `ServiceContext` as parameter, rather than picking it up from the task-local value:
Copy link
Contributor

Choose a reason for hiding this comment

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

It’s curious to me whether Baggage and ServiceContext are countable for the library — it seems we’re skipping the article somewhere. I really think we need it, but cleaning up should take an extra pass.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I didn't understand the question/concern here?

/// - extractor: The ``Extractor`` that extracts values from the given `Carrier`.
func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout Baggage, using extractor: Extract)
func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we already picked context?

Suggested change
func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout ServiceContext, using extractor: Extract)
func extract<Carrier, Extract>(_ carrier: Carrier, into context: inout ServiceContext, using extractor: Extract)

@ktoso
Copy link
Member Author

ktoso commented May 30, 2023

Sorry to have you folks pinged while this was still a draft; I've gone through now cleaning up more of the baggage word use and will be doing another pass tomorrow to clean things up and add any necessary wording about what the context is.

The entire README is to be replaced by the reference docs pages.

@ktoso ktoso force-pushed the wip-service-context branch 3 times, most recently from bc0d3c1 to 68f75b2 Compare May 30, 2023 21:37
**Motivation:**
The baggage type ended up more useful than anticipated and we're
renaming it to ServiceContext for the 1.0 release.

Many libraries and production systems and up passing context around
which may not necessarily be related to tracing, which made us make this
naming change. Functionally ServiceContext and Baggage are the same, but
the way we talk about context propagation in general makes more sense if
we call this a context stype.

**Modifications:**

Use the new type; The `Baggage` still exists in the
`InstrumentationBaggage` module so people can still use it if they
wanted to but it is a TYPEALIAS to the ServiceContext.
@ktoso ktoso force-pushed the wip-service-context branch from 9114e51 to 5dbdb4f Compare May 31, 2023 10:12

@testable import Instrumentation
import ServiceContextModule
import InstrumentationBaggage // legacy module, kept for easier migrations
Copy link
Member

Choose a reason for hiding this comment

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

I thought we are going to pull out the legacy baggage module? Should we remove this test?

Copy link
Member Author

Choose a reason for hiding this comment

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

So this module exists in the context repo and it is optional and immediately deprecated in there. It is a module with a typealias to the new context style, so if someone uses it explicitly they’ll get a migration warning. Though we don’t reexport this module anymore in tracing…

I did not make any APIs in tracing use baggage though.

it’s a bit tricky to judge how worth it is

Copy link
Member

Choose a reason for hiding this comment

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

IMO if we are going to drop baggage here we should also do it over in the service-context package. This way we don't release software with immediate deprecations

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 I can be convinced to do this I guess hmmm... we had this idea to be less breaking to folks with @tomerd bur maybe it doesn't matter? It would only work for those that explicitly used the baggage MODULE which should be very few... like just @weissi probably hm

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh actually, we can't have this test since we're testing here with warnings-as-errors here so the deprecation becomes an error and fails the build 😉

error: 'Baggage' is deprecated: Use 'ServiceContext' from 'ServiceContextModule' instead.

Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

LGTM! Just one minor comment

@ktoso ktoso marked this pull request as ready for review May 31, 2023 12:55
@ktoso ktoso merged commit 394441c into main May 31, 2023
@ktoso ktoso deleted the wip-service-context branch May 31, 2023 20:39
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.

🧳 Make sure to bump baggage dependency to 1.0
4 participants