Skip to content

Commit a79136a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into main
# Conflicts: # Package.swift
2 parents 4379443 + ec29f07 commit a79136a

File tree

56 files changed

+1289
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1289
-391
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.build/
2+
.swiftpm/
3+
UseCases/.build/
4+
UseCases/.swiftpm/

.swiftformat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# file options
22

3-
--swiftversion 5.2
3+
--swiftversion 5.0
44
--exclude .build
55
--exclude UseCases/.build
6+
--exclude Tests/LinuxMain.swift
7+
--exclude **/*Tests+XCTest.swift
68

79
# format options
810

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ let package = Package(
55
name: "gsoc-swift-tracing",
66
products: [
77
.library(name: "Instrumentation", targets: ["Instrumentation"]),
8-
.library(name: "TracingInstrumentation", targets: ["TracingInstrumentation"]),
8+
.library(name: "Tracing", targets: ["Tracing"]),
99
.library(name: "NIOInstrumentation", targets: ["NIOInstrumentation"]),
10-
.library(name: "OpenTelemetryInstrumentationSupport", targets: ["OpenTelemetryInstrumentationSupport"])
10+
.library(name: "OpenTelemetryInstrumentationSupport", targets: ["OpenTelemetryInstrumentationSupport"]),
1111
],
1212
dependencies: [
13-
// .package(
14-
// name: "swift-baggage-context",
15-
// url: "https://github.com/slashmo/gsoc-swift-baggage-context.git",
16-
// from: "0.2.0"
17-
// ),
18-
// .package(url: "https://github.com/slashmo/gsoc-swift-baggage-context.git", from: "0.2.0"),
19-
.package(url: "file:///users/ktoso/code/gsoc-swift-baggage-context", .branch("main")),
20-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0")
13+
.package(
14+
url: "https://github.com/slashmo/gsoc-swift-baggage-context.git",
15+
from: "0.3.0"
16+
),
17+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0"),
2118
],
2219
targets: [
2320
// ==== --------------------------------------------------------------------------------------------------------
@@ -37,16 +34,16 @@ let package = Package(
3734
),
3835

3936
.target(
40-
name: "TracingInstrumentation",
37+
name: "Tracing",
4138
dependencies: [
42-
"Instrumentation"
39+
"Instrumentation",
4340
]
4441
),
4542
.testTarget(
46-
name: "TracingInstrumentationTests",
43+
name: "TracingTests",
4744
dependencies: [
4845
"Instrumentation",
49-
"TracingInstrumentation",
46+
"Tracing",
5047
"BaggageLogging",
5148
]
5249
),
@@ -69,28 +66,28 @@ let package = Package(
6966
.target(
7067
name: "OpenTelemetryInstrumentationSupport",
7168
dependencies: [
72-
.target(name: "TracingInstrumentation")
69+
.target(name: "Tracing")
7370
]
7471
),
7572
.testTarget(
7673
name: "OpenTelemetryInstrumentationSupportTests",
7774
dependencies: [
78-
"OpenTelemetryInstrumentationSupport"
75+
"OpenTelemetryInstrumentationSupport",
7976
]
8077
),
8178

8279
// ==== --------------------------------------------------------------------------------------------------------
8380
// MARK: Performance / Benchmarks
8481

8582
.target(
86-
name: "Benchmarks",
83+
name: "TracingBenchmarks",
8784
dependencies: [
8885
"Baggage",
89-
"SwiftBenchmarkTools",
86+
"TracingBenchmarkTools",
9087
]
9188
),
9289
.target(
93-
name: "SwiftBenchmarkTools",
90+
name: "TracingBenchmarkTools",
9491
dependencies: []
9592
),
9693
]

Sources/Instrumentation/InstrumentationSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public enum InstrumentationSystem {
6565
///
6666
/// Defaults to a no-op `Instrument` if `boostrap` wasn't called before.
6767
public static var instrument: Instrument {
68-
self.lock.withReaderLock { self._instrument }
68+
return self.lock.withReaderLock { self._instrument }
6969
}
7070

7171
/// Get an `Instrument` instance of the given type.
@@ -75,14 +75,14 @@ public enum InstrumentationSystem {
7575
/// - Parameter instrumentType: The type of `Instrument` you want to retrieve an instance for.
7676
/// - Returns: An `Instrument` instance of the given type or `nil` if no `Instrument` of that type has been bootstrapped.
7777
public static func instrument<I>(of instrumentType: I.Type) -> I? where I: Instrument {
78-
self._findInstrument(where: { $0 is I }) as? I
78+
return self._findInstrument(where: { $0 is I }) as? I
7979
}
8080
}
8181

8282
extension InstrumentationSystem {
8383
/// :nodoc: INTERNAL API: Do Not Use
8484
public static func _findInstrument(where predicate: (Instrument) -> Bool) -> Instrument? {
85-
self.lock.withReaderLock {
85+
return self.lock.withReaderLock {
8686
if let multiplex = self._instrument as? MultiplexInstrument {
8787
return multiplex.firstInstrument(where: predicate)
8888
} else if predicate(self._instrument) {

Sources/Instrumentation/MultiplexInstrument.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct MultiplexInstrument {
2929

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

@@ -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/NIOInstrumentation/HTTPHeadersCarrier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct HTTPHeadersExtractor: ExtractorProtocol {
1818
public init() {}
1919

2020
public func extract(key: String, from headers: HTTPHeaders) -> String? {
21-
headers.first(name: key)
21+
return headers.first(name: key)
2222
}
2323
}
2424

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+EndUser.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,21 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
import TracingInstrumentation
14+
import Tracing
1515

16+
extension SpanAttributeName {
17+
/// - See: EndUserAttributes
18+
public enum EndUser {
19+
/// - See: EndUserAttributes
20+
public static let id = "enduser.id"
21+
/// - See: EndUserAttributes
22+
public static let role = "enduser.role"
23+
/// - See: EndUserAttributes
24+
public static let scope = "enduser.scope"
25+
}
26+
}
27+
28+
#if swift(>=5.2)
1629
extension SpanAttributes {
1730
/// Semantic end-user attributes.
1831
public var endUser: EndUserAttributes {
@@ -26,6 +39,8 @@ extension SpanAttributes {
2639
}
2740

2841
/// End-user-related semantic conventions as defined in the OpenTelemetry spec.
42+
///
43+
/// - SeeAlso: [OpenTelemetry: General identity attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/b70565d5a8a13d26c91fb692879dc874d22c3ac8/specification/trace/semantic_conventions/span-general.md#general-identity-attributes) (as of August 2020)
2944
@dynamicMemberLookup
3045
public struct EndUserAttributes: SpanAttributeNamespace {
3146
public var attributes: SpanAttributes
@@ -38,13 +53,14 @@ public struct EndUserAttributes: SpanAttributeNamespace {
3853
public init() {}
3954

4055
/// Username or client_id extracted from the access token or Authorization header in the inbound request from outside the system.
41-
public var id: SpanAttributeKey<String> { "enduser.id" }
56+
public var id: SpanAttributeKey<String> { .init(name: SpanAttributeName.EndUser.id) }
4257

4358
/// Actual/assumed role the client is making the request under extracted from token or application security context.
44-
public var role: SpanAttributeKey<String> { "enduser.role" }
59+
public var role: SpanAttributeKey<String> { .init(name: SpanAttributeName.EndUser.role) }
4560

4661
/// Scopes or granted authorities the client currently possesses extracted from token or application security context.
4762
/// The value would come from the scope associated with an OAuth 2.0 Access Token or an attribute value in a SAML 2.0 Assertion.
48-
public var scope: SpanAttributeKey<String> { "enduser.scope" }
63+
public var scope: SpanAttributeKey<String> { .init(name: SpanAttributeName.EndUser.scope) }
4964
}
5065
}
66+
#endif
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020 Moritz Lang and the Swift Tracing project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
import Tracing
15+
16+
extension SpanAttributeName {
17+
/// - See: GRPCAttributes
18+
public enum GRPC {
19+
/// - See: GRPCAttributes
20+
public static let messageType = "message.type"
21+
/// - See: GRPCAttributes
22+
public static let messageID = "message.id"
23+
/// - See: GRPCAttributes
24+
public static let messageCompressedSize = "message.compressed_size"
25+
/// - See: GRPCAttributes
26+
public static let messageUncompressedSize = "message.uncompressed_size"
27+
}
28+
}
29+
30+
#if swift(>=5.2)
31+
extension SpanAttributes {
32+
/// Semantic conventions for gRPC spans.
33+
public var gRPC: GRPCAttributes {
34+
get {
35+
.init(attributes: self)
36+
}
37+
set {
38+
self = newValue.attributes
39+
}
40+
}
41+
}
42+
43+
/// Semantic conventions for gRPC spans as defined in the OpenTelemetry spec.
44+
///
45+
/// - SeeAlso: [OpenTelemetry: Semantic conventions for gRPC spans](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#grpc) (as of August 2020)
46+
@dynamicMemberLookup
47+
public struct GRPCAttributes: SpanAttributeNamespace {
48+
public var attributes: SpanAttributes
49+
50+
public init(attributes: SpanAttributes) {
51+
self.attributes = attributes
52+
}
53+
54+
public struct NestedAttributes: NestedSpanAttributesProtocol {
55+
public init() {}
56+
57+
/// The type of message, e.g. "SENT" or "RECEIVED".
58+
public var messageType: SpanAttributeKey<String> { .init(name: SpanAttributeName.GRPC.messageType) }
59+
60+
/// The message id calculated as two different counters starting from 1, one for sent messages and one for received messages.
61+
public var messageID: SpanAttributeKey<Int> { .init(name: SpanAttributeName.GRPC.messageID) }
62+
63+
/// The compressed message size in bytes.
64+
public var messageCompressedSize: SpanAttributeKey<Int> {
65+
.init(name: SpanAttributeName.GRPC.messageCompressedSize)
66+
}
67+
68+
/// The uncompressed message size in bytes.
69+
public var messageUncompressedSize: SpanAttributeKey<Int> {
70+
.init(name: SpanAttributeName.GRPC.messageUncompressedSize)
71+
}
72+
}
73+
}
74+
#endif

0 commit comments

Comments
 (0)