Skip to content

Commit 278b3d0

Browse files
committed
Rename TracingInstrument to Tracer
1 parent a8f1f8d commit 278b3d0

File tree

18 files changed

+71
-53
lines changed

18 files changed

+71
-53
lines changed

Sources/Instrumentation/MultiplexInstrument.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extension MultiplexInstrument: Instrument {
3939
)
4040
where
4141
Injector: InjectorProtocol,
42-
Carrier == Injector.Carrier {
42+
Carrier == Injector.Carrier
43+
{
4344
self.instruments.forEach { $0.inject(context, into: &carrier, using: injector) }
4445
}
4546

@@ -48,7 +49,8 @@ extension MultiplexInstrument: Instrument {
4849
)
4950
where
5051
Carrier == Extractor.Carrier,
51-
Extractor: ExtractorProtocol {
52+
Extractor: ExtractorProtocol
53+
{
5254
self.instruments.forEach { $0.extract(carrier, into: &context, using: extractor) }
5355
}
5456
}

Sources/Tracing/InstrumentationSystem+Tracing.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ import Baggage
1515
import Instrumentation
1616

1717
extension InstrumentationSystem {
18-
/// Get a `TracingInstrument` instance of the given type.
18+
/// Get a `Tracer` instance of the given type.
1919
///
2020
/// When using `MultiplexInstrument`, this returns the first instance of the given type stored in the `MultiplexInstrument`.
2121
///
2222
/// Usually tracing libraries will provide their own convenience getter, e.g. CoolTracing could provide `InstrumentationSystem.coolTracer`;
2323
/// if available, prefer using those APIs rather than relying on this general function.
2424
///
25-
/// - Parameter instrumentType: The type of `Instrument` you want to retrieve an instance for.
26-
/// - Returns: An `Instrument` instance of the given type or `nil` if no `Instrument` of that type has been bootstrapped.
27-
public static func tracingInstrument<T>(of instrumentType: T.Type) -> T? where T: TracingInstrument {
25+
/// - Parameter tracerType: The type of `Tracer` you want to retrieve an instance for.
26+
/// - Returns: A `Tracer` instance of the given type or `nil` if no `Tracer` of that type has been bootstrapped.
27+
public static func tracer<T>(of tracerType: T.Type) -> T? where T: Tracer {
2828
return self._findInstrument(where: { $0 is T }) as? T
2929
}
3030

31-
/// Returns the `TracingInstrument` bootstrapped as part of the `InstrumentationSystem`.
31+
/// Returns the `Tracer` bootstrapped as part of the `InstrumentationSystem`.
3232
///
3333
/// If the system was bootstrapped with a `MultiplexInstrument` this function attempts to locate the _first_
34-
/// tracing instrument as passed to the multiplex instrument. If none is found, a `NoOpTracingInstrument` is returned.
34+
/// tracing instrument as passed to the multiplex instrument. If none is found, a `NoOpTracer` is returned.
3535
///
36-
/// - Returns: A `TracingInstrument` if the system was bootstrapped with one, and `NoOpTracingInstrument` otherwise.
37-
public static var tracingInstrument: TracingInstrument {
38-
return (self._findInstrument(where: { $0 is TracingInstrument }) as? TracingInstrument) ?? NoOpTracingInstrument()
36+
/// - Returns: A `Tracer` if the system was bootstrapped with one, and `NoOpTracer` otherwise.
37+
public static var tracer: Tracer {
38+
return (self._findInstrument(where: { $0 is Tracer }) as? Tracer) ?? NoOpTracer()
3939
}
4040
}

Sources/Tracing/NoOpTracingInstrument.swift renamed to Sources/Tracing/NoOpTracer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import Baggage
1515
import Instrumentation
1616

17-
/// No operation TracingInstrument, used when no tracing is required.
18-
public struct NoOpTracingInstrument: TracingInstrument {
17+
/// No operation Tracer, used when no tracing is required.
18+
public struct NoOpTracer: Tracer {
1919
public func startSpan(
2020
named operationName: String,
2121
context: BaggageContextCarrier,

Sources/Tracing/Span.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Baggage
1515

1616
/// A `Span` type that follows the OpenTracing/OpenTelemetry spec. The span itself should not be
1717
/// initializable via its public interface. `Span` creation should instead go through `tracer.startSpan`
18-
/// where `tracer` conforms to `TracingInstrument`.
18+
/// where `tracer` conforms to `Tracer`.
1919
///
2020
/// - SeeAlso: [OpenTelemetry Specification: Span](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#span).
2121
public protocol Span {
@@ -25,7 +25,7 @@ public protocol Span {
2525
/// Set the status.
2626
/// - Parameter status: The status of this `Span`.
2727
mutating func setStatus(_ status: SpanStatus)
28-
28+
2929
/// Add a `SpanEvent` in place.
3030
/// - Parameter event: The `SpanEvent` to add to this `Span`.
3131
mutating func addEvent(_ event: SpanEvent)
@@ -162,7 +162,8 @@ extension SpanAttributeNamespace {
162162
}
163163

164164
public subscript<Namespace>(dynamicMember dynamicMember: KeyPath<SpanAttribute, Namespace>) -> Namespace
165-
where Namespace: SpanAttributeNamespace {
165+
where Namespace: SpanAttributeNamespace
166+
{
166167
SpanAttribute.__namespace[keyPath: dynamicMember]
167168
}
168169
}
@@ -364,7 +365,8 @@ extension SpanAttributes {
364365
///
365366
// TODO: document the pattern maybe on SpanAttributes?
366367
public subscript<Namespace>(dynamicMember dynamicMember: KeyPath<SpanAttribute, Namespace>) -> Namespace
367-
where Namespace: SpanAttributeNamespace {
368+
where Namespace: SpanAttributeNamespace
369+
{
368370
SpanAttribute.__namespace[keyPath: dynamicMember]
369371
}
370372
}

Sources/Tracing/TracingInstrument.swift renamed to Sources/Tracing/Tracer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Instrumentation
1616

1717
/// An `Instrument` with added functionality for distributed tracing. Is uses the span-based tracing model and is
1818
/// based on the OpenTracing/OpenTelemetry spec.
19-
public protocol TracingInstrument: Instrument {
19+
public protocol Tracer: Instrument {
2020
/// Start a new `Span` within the given `BaggageContext` at a given timestamp.
2121
/// - Parameters:
2222
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
@@ -39,7 +39,7 @@ public protocol TracingInstrument: Instrument {
3939
func forceFlush()
4040
}
4141

42-
extension TracingInstrument {
42+
extension Tracer {
4343
/// Start a new `Span` within the given `BaggageContext`. This passes `nil` as the timestamp to the tracer, which
4444
/// usually means it should default to the current timestamp.
4545
/// - Parameters:

Sources/TracingBenchmarkTools/ArgParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ArgumentParser<U> {
219219
) {
220220
self.arguments.append(
221221
Argument(name: name, help: help)
222-
{ try self.parseArgument(name, property, defaultValue, parser) }
222+
{ try self.parseArgument(name, property, defaultValue, parser) }
223223
)
224224
}
225225

Tests/InstrumentationTests/InstrumentTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ private final class FirstFakeTracer: Instrument {
6666
)
6767
where
6868
Injector: InjectorProtocol,
69-
Carrier == Injector.Carrier {
69+
Carrier == Injector.Carrier
70+
{
7071
guard let traceID = context[TraceIDKey.self] else { return }
7172
injector.inject(traceID, forKey: FirstFakeTracer.headerName, into: &carrier)
7273
}
@@ -76,7 +77,8 @@ private final class FirstFakeTracer: Instrument {
7677
)
7778
where
7879
Extractor: ExtractorProtocol,
79-
Carrier == Extractor.Carrier {
80+
Carrier == Extractor.Carrier
81+
{
8082
let traceID = extractor.extract(key: FirstFakeTracer.headerName, from: carrier) ?? FirstFakeTracer.defaultTraceID
8183
context[TraceIDKey.self] = traceID
8284
}
@@ -97,7 +99,8 @@ private final class SecondFakeTracer: Instrument {
9799
)
98100
where
99101
Injector: InjectorProtocol,
100-
Carrier == Injector.Carrier {
102+
Carrier == Injector.Carrier
103+
{
101104
guard let traceID = context[TraceIDKey.self] else { return }
102105
injector.inject(traceID, forKey: SecondFakeTracer.headerName, into: &carrier)
103106
}
@@ -107,7 +110,8 @@ private final class SecondFakeTracer: Instrument {
107110
)
108111
where
109112
Extractor: ExtractorProtocol,
110-
Carrier == Extractor.Carrier {
113+
Carrier == Extractor.Carrier
114+
{
111115
let traceID = extractor.extract(key: SecondFakeTracer.headerName, from: carrier) ?? SecondFakeTracer.defaultTraceID
112116
context[TraceIDKey.self] = traceID
113117
}

Tests/LinuxMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class LinuxMainRunnerImpl: LinuxMainRunner {
4343
testCase(SpanTests.allTests),
4444
testCase(TimestampTests.allTests),
4545
testCase(TracedLockTests.allTests),
46-
testCase(TracingInstrumentTests.allTests),
46+
testCase(TracerTests.allTests),
4747
])
4848
}
4949
}

Tests/NIOInstrumentationTests/FakeTracer.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ final class FakeTracer: Instrument {
2929
)
3030
where
3131
Injector: InjectorProtocol,
32-
Carrier == Injector.Carrier {
32+
Carrier == Injector.Carrier
33+
{
3334
guard let traceID = context[TraceIDKey.self] else { return }
3435
injector.inject(traceID, forKey: FakeTracer.headerName, into: &carrier)
3536
}
@@ -39,7 +40,8 @@ final class FakeTracer: Instrument {
3940
)
4041
where
4142
Extractor: ExtractorProtocol,
42-
Carrier == Extractor.Carrier {
43+
Carrier == Extractor.Carrier
44+
{
4345
let traceID = extractor.extract(key: FakeTracer.headerName, from: carrier) ?? FakeTracer.defaultTraceID
4446
context[TraceIDKey.self] = traceID
4547
}

Tests/TracingTests/TracedLock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class TracedLock {
3030
func lock(context: BaggageContext) {
3131
// time here
3232
self.underlyingLock.lock()
33-
self.activeSpan = InstrumentationSystem.tracingInstrument.startSpan(named: self.name, context: context)
33+
self.activeSpan = InstrumentationSystem.tracer.startSpan(named: self.name, context: context)
3434
}
3535

3636
func unlock(context: BaggageContext) {

0 commit comments

Comments
 (0)