Skip to content

Commit 3fed073

Browse files
committed
include swift-log integration
1 parent 1a65627 commit 3fed073

File tree

13 files changed

+784
-3
lines changed

13 files changed

+784
-3
lines changed

Docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Documentation landing page
2+
3+
This documentation target exists only to serve as a landing page for self hosted documentation.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ``SwiftDistributedTracing``
2+
3+
A Distributed Tracing API for Swift.
4+
5+
## Overview
6+
7+
This is a collection of Swift libraries enabling the instrumentation of server side applications using tools such as tracers. Our goal is to provide a common foundation that allows to freely choose how to instrument systems with minimal changes to your actual code.
8+
9+
While Swift Distributed Tracing allows building all kinds of _instruments_, which can co-exist in applications transparently, its primary use is instrumenting multi-threaded and distributed systems with Distributed Traces.
10+
11+
### Quickstart Guides
12+
13+
We provide a number of guides aimed at getting your started with tracing your systems and have prepared them from three "angles":
14+
15+
1. **Application developers** who create server-side applications
16+
* please refer to the <doc:TraceYourApplication> guide.
17+
2. **Library/Framework developers** who provide building blocks to create these applications
18+
* please refer to the <doc:InstrumentYourLibrary> guide.
19+
3. **Instrument developers** who provide tools to collect distributed metadata about your application
20+
* please refer to the <doc:ImplementATracer> guide.
21+
22+
23+
## Topics
24+
25+
### Guides
26+
27+
- <doc:TraceYourApplication>
28+
- <doc:InstrumentYourLibrary>
29+
- <doc:ImplementATracer>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project
6+
// authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
16+
// This module is left purposefully empty of any source files, as it serves
17+
// only as a "landing page" for the documentation. This is in-place until docc
18+
// gains the ability to support package-wide documentation.
19+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ let package = Package(
88
.library(name: "Tracing", targets: ["Tracing"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
11+
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage", .upToNextMinor(from: "0.4.1")),
12+
// .package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
13+
.package(url: "https://github.com/ktoso/swift-log", .branch("wip-baggage-in-handlers-but-not-api")),
1214
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1315
],
1416
targets: [
@@ -19,6 +21,7 @@ let package = Package(
1921
name: "Instrumentation",
2022
dependencies: [
2123
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
24+
.product(name: "Logging", package: "swift-log"),
2225
]
2326
),
2427
.testTarget(

Package@swift-5.2.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
12+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
1213
],
1314
targets: [
1415
// ==== --------------------------------------------------------------------------------------------------------
@@ -18,6 +19,7 @@ let package = Package(
1819
name: "Instrumentation",
1920
dependencies: [
2021
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
22+
.product(name: "Logging", package: "swift-log"),
2123
]
2224
),
2325
.testTarget(

Package@swift-5.3.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
12+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
1213
],
1314
targets: [
1415
// ==== --------------------------------------------------------------------------------------------------------
@@ -18,6 +19,7 @@ let package = Package(
1819
name: "Instrumentation",
1920
dependencies: [
2021
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
22+
.product(name: "Logging", package: "swift-log"),
2123
]
2224
),
2325
.testTarget(

Package@swift-5.4.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
12+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
1213
],
1314
targets: [
1415
// ==== --------------------------------------------------------------------------------------------------------
@@ -18,6 +19,7 @@ let package = Package(
1819
name: "Instrumentation",
1920
dependencies: [
2021
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
22+
.product(name: "Logging", package: "swift-log"),
2123
]
2224
),
2325
.testTarget(

Package@swift-5.5.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
12+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
1213
],
1314
targets: [
1415
// ==== --------------------------------------------------------------------------------------------------------
@@ -18,6 +19,7 @@ let package = Package(
1819
name: "Instrumentation",
1920
dependencies: [
2021
.product(name: "InstrumentationBaggage", package: "swift-distributed-tracing-baggage"),
22+
.product(name: "Logging", package: "swift-log"),
2123
]
2224
),
2325
.testTarget(
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020-2022 Apple Inc. and the Swift Distributed Tracing project
6+
// authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Logging
16+
@_exported import InstrumentationBaggage
17+
18+
#if swift(>=5.5.0) && canImport(_Concurrency)
19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
20+
extension Logger {
21+
22+
/// Extract any potential ``Logger/Metadata`` that might be obtained by extracting the
23+
/// passed ``InstrumentationBaggage/Baggage`` to this logger's configured ``Logger/MetadataProvider``.
24+
///
25+
/// Use this when it is necessary to "materialize" contextual baggage metadata into the logger, for future use,
26+
/// and you cannot rely on using the task-local way of passing Baggage around, e.g. when the logger will be
27+
/// used from multiple callbacks, and it would be troublesome to have to restore the task-local baggage in every callback.
28+
///
29+
/// Generally prefer to set the task-local baggage using `Baggage.current` or `Tracer.withSpan`.
30+
public mutating func provideMetadata(from baggage: Baggage?) {
31+
guard let baggage = baggage else {
32+
return
33+
}
34+
35+
Baggage.withValue(baggage) {
36+
let metadata = self.metadataProvider.provideMetadata()
37+
for (k, v) in metadata {
38+
self[metadataKey: k] = v
39+
}
40+
}
41+
}
42+
}
43+
#endif

Sources/Tracing/Docs.docc/Guides/TraceYourApplication.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Once you have selected an implementation, add it as a dependency to your `Packag
2828
.package(url: "https://github.com/slashmo/opentelemetry-swift.git", from: "<latest-version>"),
2929

3030
// This will automatically include a dependency on the swift-distributed-tracing API:
31-
// .package(url: "https://github.com/apple/swift-distributed-tracing.git", from: 1.0.0),
31+
// .package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.0.0"),
3232
```
3333

3434
Next, add the dependency to your application target:
@@ -102,7 +102,6 @@ A typical bootstrap could look something like this:
102102
```swift
103103
import OpenTelemetry
104104
import StatsdMetrics
105-
import FancyLogging
106105

107106
extension Logger.MetadataProvider {
108107

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project
6+
// authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
//
15+
// BaggageLoggingTest+XCTest.swift
16+
//
17+
import XCTest
18+
///
19+
/// NOTE: This file was generated by generate_linux_tests.rb
20+
///
21+
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
22+
///
23+
24+
extension BaggageLoggingTest {
25+
26+
@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
27+
static var allTests : [(String, (BaggageLoggingTest) -> () throws -> Void)] {
28+
return [
29+
("testLoggingCallsMetadataProviderWithTaskLocalBaggage", testLoggingCallsMetadataProviderWithTaskLocalBaggage),
30+
("testLoggingMergesOneOffMetadataWithProvidedMetadataFromTaskLocalBaggage", testLoggingMergesOneOffMetadataWithProvidedMetadataFromTaskLocalBaggage),
31+
("testLoggingMergesOneOffMetadataWithProvidedMetadataFromExplicitlyPassedBaggage", testLoggingMergesOneOffMetadataWithProvidedMetadataFromExplicitlyPassedBaggage),
32+
("testLoggingIncludesExplicitBaggageOverTaskLocal", testLoggingIncludesExplicitBaggageOverTaskLocal),
33+
("testLogHandlerThatDidNotImplementProvidersButSomeoneAttemptsToSetOneOnIt", testLogHandlerThatDidNotImplementProvidersButSomeoneAttemptsToSetOneOnIt),
34+
]
35+
}
36+
}
37+

0 commit comments

Comments
 (0)