Skip to content

Commit 7586bdc

Browse files
authored
associated type Span, Tracer as short-hand, and *Protocol types (#93)
1 parent d633b17 commit 7586bdc

29 files changed

+1146
-599
lines changed

Package.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import PackageDescription
33

44
let package = Package(
55
name: "swift-distributed-tracing",
6+
platforms: [
7+
.macOS(.v10_15),
8+
.iOS(.v13),
9+
.tvOS(.v13),
10+
.watchOS(.v6),
11+
],
612
products: [
713
.library(name: "Instrumentation", targets: ["Instrumentation"]),
814
.library(name: "Tracing", targets: ["Tracing"]),

Package@swift-5.2.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

Package@swift-5.3.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

Package@swift-5.4.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

Package@swift-5.5.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This project uses the context progagation type defined independently in:
4040
+ [Extracting & injecting Baggage](#extracting--injecting-baggage)
4141
+ [Tracing your library](#tracing-your-library)
4242
* In-Depth Guide for: **Instrument developers**
43-
+ [Creating an `Instrument`](#instrument-developers--creating-an-instrument)
43+
+ [Creating an `InstrumentProtocol`](#instrument-developers--creating-an-instrument)
4444
+ [Creating a `Tracer`](#creating-a--tracer-)
4545
* [Contributing](#contributing)
4646

@@ -119,7 +119,7 @@ To your main target, add a dependency on `Tracing` library and the instrument yo
119119
),
120120
```
121121

122-
Then (in an application, libraries should _never_ invoke `bootstrap`), you will want to bootstrap the specific tracer you want to use in your application. A `Tracer` is a type of `Instrument` and can be offered used to globally bootstrap the tracing system, like this:
122+
Then (in an application, libraries should _never_ invoke `bootstrap`), you will want to bootstrap the specific tracer you want to use in your application. A `Tracer` is a type of `InstrumentProtocol` and can be offered used to globally bootstrap the tracing system, like this:
123123

124124

125125
```swift
@@ -295,7 +295,7 @@ To your main target, add a dependency on the `Instrumentation library` and the i
295295

296296
Instead of providing each instrumented library with a specific instrument explicitly, you *bootstrap* the
297297
`InstrumentationSystem` which acts as a singleton that libraries/frameworks access when calling out to the configured
298-
`Instrument`:
298+
`InstrumentProtocol`:
299299

300300
```swift
301301
InstrumentationSystem.bootstrap(FancyInstrument())
@@ -316,7 +316,7 @@ This is because tracing systems may attempt to emit metrics about their status e
316316

317317
#### Bootstrapping multiple instruments using MultiplexInstrument
318318

319-
It is important to note that `InstrumentationSystem.bootstrap(_: Instrument)` must only be called once. In case you
319+
It is important to note that `InstrumentationSystem.bootstrap(_: InstrumentProtocol)` must only be called once. In case you
320320
want to bootstrap the system to use multiple instruments, you group them in a `MultiplexInstrument` first, which you
321321
then pass along to the `bootstrap` method like this:
322322

@@ -444,7 +444,7 @@ Spans form hierarchies with their parent spans, and end up being visualized usin
444444
The above trace is achieved by starting and ending spans in all the mentioned functions, for example, like this:
445445

446446
```swift
447-
let tracer: Tracer
447+
let tracer: any TracerProtocol
448448

449449
func makeDinner(context: LoggingContext) async throws -> Meal {
450450
tracer.withSpan(operationName: "makeDinner", context) {
@@ -481,7 +481,7 @@ func get(url: String, context: LoggingContext) {
481481
}
482482
```
483483

484-
On the receiving side, an HTTP server should use the following `Instrument` API to extract the HTTP headers of the given
484+
On the receiving side, an HTTP server should use the following `InstrumentProtocol` API to extract the HTTP headers of the given
485485
`HTTPRequest` into:
486486

487487
```swift
@@ -538,10 +538,10 @@ func get(url: String, context: LoggingContext) {
538538

539539
## Instrument developers: Creating an instrument
540540

541-
Creating an instrument means adopting the `Instrument` protocol (or `Tracer` in case you develop a tracer).
542-
`Instrument` is part of the `Instrumentation` library & `Tracing` contains the `Tracer` protocol.
541+
Creating an instrument means adopting the `InstrumentProtocol` protocol (or `TracerProtocol` in case you develop a tracer).
542+
`InstrumentProtocol` is part of the `Instrumentation` library & `Tracing` contains the `TracerProtocol` protocol.
543543

544-
`Instrument` has two requirements:
544+
`InstrumentProtocol` has two requirements:
545545

546546
1. A method to inject values inside a `LoggingContext` into a generic carrier (e.g. HTTP headers)
547547
2. A method to extract values from a generic carrier (e.g. HTTP headers) and store them in a `LoggingContext`
@@ -552,11 +552,11 @@ act on the provided information or to add additional information to be carried a
552552
> Check out the [`Baggage` documentation](https://github.com/apple/swift-distributed-tracing-baggage) for more information on
553553
how to retrieve values from the `LoggingContext` and how to set values on it.
554554

555-
### Creating a `Tracer`
555+
### Creating a Tracer
556556

557557
When creating a tracer you need to create two types:
558558

559-
1. Your tracer conforming to `Tracer`
559+
1. Your tracer conforming to `TracerProtocol`
560560
2. A span class conforming to `Span`
561561

562562
> The `Span` conforms to the standard rules defined in [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-specification/blob/v0.7.0/specification/trace/api.md#span), so if unsure about usage patterns, you can refer to this specification and examples referring to it.

Sources/Instrumentation/Instrument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public protocol Injector: _SwiftInstrumentationSendable {
5050

5151
/// Conforming types are usually cross-cutting tools like tracers. They are agnostic of what specific `Carrier` is used
5252
/// to propagate metadata across boundaries, but instead just specify what values to use for which keys.
53-
public protocol Instrument: _SwiftInstrumentationSendable {
53+
public protocol InstrumentProtocol: _SwiftInstrumentationSendable {
5454
/// Extract values from a `Carrier` by using the given extractor and inject them into the given `Baggage`.
55-
/// It's quite common for `Instrument`s to come up with new values if they weren't passed along in the given `Carrier`.
55+
/// It's quite common for `InstrumentProtocol`s to come up with new values if they weren't passed along in the given `Carrier`.
5656
///
5757
/// - Parameters:
5858
/// - carrier: The `Carrier` that was used to propagate values across boundaries.

0 commit comments

Comments
 (0)