Skip to content

Commit a09547a

Browse files
authored
Merge branch 'main' into wip-addnanoseconds
2 parents 4f63ee9 + 63a9c24 commit a09547a

21 files changed

+629
-368
lines changed

README.md

+10-10
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 `InstrumentProtocol`](#instrument-developers--creating-an-instrument)
43+
+ [Creating an `Instrument`](#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 `InstrumentProtocol` 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 `Instrument` 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-
`InstrumentProtocol`:
298+
`Instrument`:
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(_: InstrumentProtocol)` must only be called once. In case you
319+
It is important to note that `InstrumentationSystem.bootstrap(_: Instrument)` 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: any TracerProtocol
447+
let tracer: any Tracer
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 `InstrumentProtocol` API to extract the HTTP headers of the given
484+
On the receiving side, an HTTP server should use the following `Instrument` 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 `InstrumentProtocol` protocol (or `TracerProtocol` in case you develop a tracer).
542-
`InstrumentProtocol` is part of the `Instrumentation` library & `Tracing` contains the `TracerProtocol` protocol.
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.
543543

544-
`InstrumentProtocol` has two requirements:
544+
`Instrument` 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`
@@ -556,7 +556,7 @@ how to retrieve values from the `LoggingContext` and how to set values on it.
556556

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

559-
1. Your tracer conforming to `TracerProtocol`
559+
1. Your tracer conforming to `Tracer`
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

+2-2
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 InstrumentProtocol: _SwiftInstrumentationSendable {
53+
public protocol Instrument: _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 `InstrumentProtocol`s to come up with new values if they weren't passed along in the given `Carrier`.
55+
/// It's quite common for `Instrument`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.

Sources/Instrumentation/InstrumentationSystem.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
import InstrumentationBaggage
1616

1717
/// `InstrumentationSystem` is a global facility where the default cross-cutting tool can be configured.
18-
/// It is set up just once in a given program to select the desired ``InstrumentProtocol`` implementation.
18+
/// It is set up just once in a given program to select the desired ``Instrument`` implementation.
1919
///
2020
/// # Bootstrap multiple Instruments
2121
/// If you need to use more that one cross-cutting tool you can do so by using ``MultiplexInstrument``.
2222
///
23-
/// # Access the InstrumentProtocol
24-
/// ``instrument``: Returns whatever you passed to ``bootstrap(_:)`` as an ``InstrumentProtocol``.
23+
/// # Access the Instrument
24+
/// ``instrument``: Returns whatever you passed to ``bootstrap(_:)`` as an ``Instrument``.
2525
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
2626
public enum InstrumentationSystem {
2727
private static let lock = ReadWriteLock()
28-
private static var _instrument: InstrumentProtocol = NoOpInstrument()
28+
private static var _instrument: Instrument = NoOpInstrument()
2929
private static var isInitialized = false
3030

31-
/// Globally select the desired ``InstrumentProtocol`` implementation.
31+
/// Globally select the desired ``Instrument`` implementation.
3232
///
33-
/// - Parameter instrument: The ``InstrumentProtocol`` you want to share globally within your system.
33+
/// - Parameter instrument: The ``Instrument`` you want to share globally within your system.
3434
/// - Warning: Do not call this method more than once. This will lead to a crash.
35-
public static func bootstrap(_ instrument: InstrumentProtocol) {
35+
public static func bootstrap(_ instrument: Instrument) {
3636
self.lock.withWriterLock {
3737
precondition(
3838
!self.isInitialized, """
@@ -48,24 +48,24 @@ public enum InstrumentationSystem {
4848
/// For testing scenarios one may want to set instruments multiple times, rather than the set-once semantics enforced by ``bootstrap(_:)``.
4949
///
5050
/// - Parameter instrument: the instrument to boostrap the system with, if `nil` the ``NoOpInstrument`` is bootstrapped.
51-
internal static func bootstrapInternal(_ instrument: InstrumentProtocol?) {
51+
internal static func bootstrapInternal(_ instrument: Instrument?) {
5252
self.lock.withWriterLock {
5353
self._instrument = instrument ?? NoOpInstrument()
5454
}
5555
}
5656

57-
/// Returns the globally configured ``InstrumentProtocol``.
57+
/// Returns the globally configured ``Instrument``.
5858
///
59-
/// Defaults to a no-op ``InstrumentProtocol`` if ``bootstrap(_:)`` wasn't called before.
60-
public static var instrument: InstrumentProtocol {
59+
/// Defaults to a no-op ``Instrument`` if ``bootstrap(_:)`` wasn't called before.
60+
public static var instrument: Instrument {
6161
self.lock.withReaderLock { self._instrument }
6262
}
6363
}
6464

6565
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
6666
extension InstrumentationSystem {
6767
/// :nodoc: INTERNAL API: Do Not Use
68-
public static func _findInstrument(where predicate: (InstrumentProtocol) -> Bool) -> InstrumentProtocol? {
68+
public static func _findInstrument(where predicate: (Instrument) -> Bool) -> Instrument? {
6969
self.lock.withReaderLock {
7070
if let multiplex = self._instrument as? MultiplexInstrument {
7171
return multiplex.firstInstrument(where: predicate)

Sources/Instrumentation/MultiplexInstrument.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@
1414

1515
import InstrumentationBaggage
1616

17-
/// A pseudo-``InstrumentProtocol`` that may be used to instrument using multiple other ``InstrumentProtocol``s across a
17+
/// A pseudo-``Instrument`` that may be used to instrument using multiple other ``Instrument``s across a
1818
/// common `Baggage`.
1919
public struct MultiplexInstrument {
20-
private var instruments: [InstrumentProtocol]
20+
private var instruments: [Instrument]
2121

2222
/// Create a ``MultiplexInstrument``.
2323
///
24-
/// - Parameter instruments: An array of ``InstrumentProtocol``s, each of which will be used to ``InstrumentProtocol/inject(_:into:using:)`` or ``InstrumentProtocol/extract(_:into:using:)``
24+
/// - Parameter instruments: An array of ``Instrument``s, each of which will be used to ``Instrument/inject(_:into:using:)`` or ``Instrument/extract(_:into:using:)``
2525
/// through the same `Baggage`.
26-
public init(_ instruments: [InstrumentProtocol]) {
26+
public init(_ instruments: [Instrument]) {
2727
self.instruments = instruments
2828
}
2929
}
3030

3131
extension MultiplexInstrument {
32-
func firstInstrument(where predicate: (InstrumentProtocol) -> Bool) -> InstrumentProtocol? {
32+
func firstInstrument(where predicate: (Instrument) -> Bool) -> Instrument? {
3333
self.instruments.first(where: predicate)
3434
}
3535
}
3636

37-
extension MultiplexInstrument: InstrumentProtocol {
37+
extension MultiplexInstrument: Instrument {
3838
public func inject<Carrier, Inject>(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)
3939
where Inject: Injector, Carrier == Inject.Carrier
4040
{

Sources/Instrumentation/NoOpInstrument.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import InstrumentationBaggage
1616

17-
/// A "no op" implementation of an ``InstrumentProtocol``.
18-
public struct NoOpInstrument: InstrumentProtocol {
17+
/// A "no op" implementation of an ``Instrument``.
18+
public struct NoOpInstrument: Instrument {
1919
public init() {}
2020

2121
public func inject<Carrier, Inject>(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)

Sources/Tracing/Docs.docc/InDepthGuide.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When instrumenting server applications there are typically three parties involve
88

99
1. **Application developers** create server-side applications
1010
2. **Library/Framework developers** provide building blocks to create these applications
11-
3. **InstrumentProtocol developers** provide tools to collect distributed metadata about your application
11+
3. **Instrument developers** provide tools to collect distributed metadata about your application
1212

1313
For applications to be instrumented correctly these three parts have to play along nicely.
1414

@@ -42,7 +42,7 @@ To your main target, add a dependency on the `Instrumentation library` and the i
4242

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

4747
```swift
4848
InstrumentationSystem.bootstrap(FancyInstrument())
@@ -63,7 +63,7 @@ This is because tracing systems may attempt to emit metrics about their status e
6363

6464
#### Bootstrapping multiple instruments using MultiplexInstrument
6565

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

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

190190
```swift
191-
let tracer: any TracerProtocol
191+
let tracer: any Tracer
192192

193193
func makeDinner(context: LoggingContext) async throws -> Meal {
194194
tracer.withSpan(operationName: "makeDinner", context) {
@@ -225,7 +225,7 @@ func get(url: String, context: LoggingContext) {
225225
}
226226
```
227227

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

231231
```swift
@@ -280,12 +280,12 @@ func get(url: String, context: LoggingContext) {
280280
> In the above example we used the semantic `http.method` attribute that gets exposed via the
281281
`TracingOpenTelemetrySupport` library.
282282

283-
## InstrumentProtocol developers: Creating an instrument
283+
## Instrument developers: Creating an instrument
284284

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

288-
`InstrumentProtocol` has two requirements:
288+
`Instrument` has two requirements:
289289

290290
1. A method to inject values inside a `LoggingContext` into a generic carrier (e.g. HTTP headers)
291291
2. A method to extract values from a generic carrier (e.g. HTTP headers) and store them in a `LoggingContext`

Sources/Tracing/Docs.docc/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To your main target, add a dependency on the `Tracing` library and the instrumen
6262
),
6363
```
6464

65-
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:
65+
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:
6666

6767

6868
```swift

Sources/Tracing/InstrumentationSystem+Tracing.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ extension InstrumentationSystem {
2222
/// tracing instrument as passed to the multiplex instrument. If none is found, a ``NoOpTracer`` is returned.
2323
///
2424
/// - Returns: A ``Tracer`` if the system was bootstrapped with one, and ``NoOpTracer`` otherwise.
25-
public static var tracer: any TracerProtocol {
26-
let found: (any TracerProtocol)? =
27-
(self._findInstrument(where: { $0 is (any TracerProtocol) }) as? (any TracerProtocol))
25+
public static var tracer: any Tracer {
26+
let found: (any Tracer)? =
27+
(self._findInstrument(where: { $0 is (any Tracer) }) as? (any Tracer))
2828
return found ?? NoOpTracer()
2929
}
3030
#endif
@@ -35,9 +35,9 @@ extension InstrumentationSystem {
3535
/// tracing instrument as passed to the multiplex instrument. If none is found, a ``NoOpTracer`` is returned.
3636
///
3737
/// - Returns: A ``Tracer`` if the system was bootstrapped with one, and ``NoOpTracer`` otherwise.
38-
public static var legacyTracer: any LegacyTracerProtocol {
39-
let found: (any LegacyTracerProtocol)? =
40-
(self._findInstrument(where: { $0 is (any LegacyTracerProtocol) }) as? (any LegacyTracerProtocol))
38+
public static var legacyTracer: any LegacyTracer {
39+
let found: (any LegacyTracer)? =
40+
(self._findInstrument(where: { $0 is (any LegacyTracer) }) as? (any LegacyTracer))
4141
return found ?? NoOpTracer()
4242
}
4343
}

Sources/Tracing/NoOpTracer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Dispatch
1818

1919
/// Tracer that ignores all operations, used when no tracing is required.
2020
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
21-
public struct NoOpTracer: LegacyTracerProtocol {
21+
public struct NoOpTracer: LegacyTracer {
2222
public typealias TracerSpan = NoOpSpan
2323

2424
public init() {}
@@ -91,7 +91,7 @@ public struct NoOpTracer: LegacyTracerProtocol {
9191
}
9292

9393
#if swift(>=5.7.0)
94-
extension NoOpTracer: TracerProtocol {
94+
extension NoOpTracer: Tracer {
9595
public func startSpan<Clock: TracerClock>(
9696
_ operationName: String,
9797
baggage: @autoclosure () -> Baggage,

0 commit comments

Comments
 (0)