Skip to content

Commit 8daa244

Browse files
committed
Merge remote-tracking branch 'apple/wip-docs-1.0' into wip-docs-1.0
2 parents 8fee747 + 00c354e commit 8daa244

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The table below illustrates the
3737

3838
| Library | Status | Baggage propagation | Automatic spans (e.g. "request" span) |
3939
|--------------------------------------------------|-------------------------------------------------------------|-------------------|-----------------------------------------------------------|
40-
| [Swift gRPC](https://github.com/grpc/grpc-swift) | [PR - in progress](https://github.com/grpc/grpc-swift/pull/1510) | WIP | Pending | |
40+
| [gRPC Swift](https://github.com/grpc/grpc-swift) | [PR - in progress](https://github.com/grpc/grpc-swift/pull/1510) | WIP | Pending | |
4141
| _Your library?_ | ... | ... |[Get in touch!](https://forums.swift.org/c/server/43) |
4242

4343

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This guide is aimed at ``TracerProtocol`` and ``InstrumentProtocol`` implementation authors.
66

7-
This guide is for you, if you find yourself in need of implementing your own tracing client such as Zipkin, Jaeger, X-Trace, OpenTelemetry or something similar that is custom to your company or distributed system.
7+
This guide is for you if you find yourself in need of implementing your own tracing client such as Zipkin, Jaeger, X-Trace, OpenTelemetry or something similar that is custom to your company or distributed system.
88

99
## Do you need an Instrument or a Tracer?
1010

@@ -14,12 +14,12 @@ A tracer is-an instrument as well, and further refines it with the ability to st
1414

1515
## Creating an instrument
1616

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

2020
`Instrument` has two requirements:
2121

22-
1. A method to inject values inside a `FIXME!!!` into a generic carrier (e.g. HTTP headers)
22+
1. A method to inject values into a `FIXME!!!` a generic carrier (e.g. HTTP headers)
2323
2. A method to extract values from a generic carrier (e.g. HTTP headers) and store them in a `FIXME!!!`
2424

2525
The two methods will be called by instrumented libraries/frameworks at asynchronous boundaries, giving you a chance to
@@ -81,7 +81,7 @@ func get(url: String, context: FIXME!!!) {
8181
```
8282

8383
On the receiving side, an HTTP server should use the following `Instrument` API to extract the HTTP headers of the given
84-
`HTTPRequest` into:
84+
`HTTPRequest`:
8585

8686
```swift
8787
func handler(request: HTTPRequest, context: FIXME!!!) {
@@ -94,7 +94,7 @@ func handler(request: HTTPRequest, context: FIXME!!!) {
9494
}
9595
```
9696

97-
> In case your library makes use of the `NIOHTTP1.HTTPHeaders` type we already have an `HTTPHeadersInjector` &
97+
> In case your library makes use of the `NIOHTTP1.HTTPHeaders` type we already have an `HTTPHeadersInjector` and
9898
`HTTPHeadersExtractor` available as part of the `NIOInstrumentation` library.
9999

100100
For your library/framework to be able to carry `FIXME!!!` across asynchronous boundaries, it's crucial that you carry the context throughout your entire call chain in order to avoid dropping metadata.
@@ -129,7 +129,7 @@ func get(url: String, context: FIXME!!!) {
129129
}
130130
```
131131

132-
> ⚠️ Make sure to ALWAYS end spans. Ensure that all paths taken by the code will result in ending the span.
132+
> ⚠️ Make sure to ALWAYS end spans to ensure that all paths taken by the code will result in ending the span.
133133
> Make sure that error cases also set the error attribute and end the span.
134134
135135
> In the above example we used the semantic `http.method` attribute that gets exposed via the

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This guide is aimed at library and framework developers who wish to instrument t
77
Doing so within a library may enable automatic trace propagation and is key to propagating trace information across
88
distributed nodes, e.g. by instrumenting the HTTP client used by such system.
99

10-
Other examples of libraries which benefit _the most_ from being instrumented using distributed tracing include:
10+
Other examples of libraries which would benefit _the most_ from being instrumented using distributed tracing include:
1111

1212
- HTTP Clients (e.g. AsyncHTTPClient),
1313
- HTTP Servers (e.g. Vapor or Smoke),
@@ -20,16 +20,16 @@ it is them who must inject and extract contextual baggage metadata to enable dis
2020

2121
Following those, any database or other complex library which may be able to emit useful information about its internals are
2222
also good candidates to being instrumented. Note that libraries may do so optionally, or hide the "verboseness" of such traces
23-
behind options, or only attach information if a Span is already active etc. Please review your library's documentation to learn
23+
behind options, or only attach information if a ``Span`` is already active etc. Please review your library's documentation to learn
2424
more about it has integrated tracing support.
2525

2626
### Propagating baggage metadata
2727

28-
When crossing boundaries between processes, such as making or receiving an HTTP request, the library responsible for doing so, should invoke instrumentation in order to inject or extract the contextual baggage metadata into/from the "carrier" type (such as the `HTTPResponse`) type.
28+
When crossing boundaries between processes, such as making or receiving an HTTP request, the library responsible for doing so should invoke instrumentation in order to inject or extract the contextual baggage metadata into/from the "carrier" type (such as the `HTTPResponse`) type.
2929

3030
#### Handling outbound requests
3131

32-
When a library makes an "outgoing" request or message interaction, it should invoke the method of a configured instrument. This will invoke whichever instrument the end-user has configured and allow them to customize what metadata gets to be propagated. This can be by the following diagram:
32+
When a library makes an "outgoing" request or message interaction, it should invoke the method of a configured instrument. This will invoke whichever instrument the end-user has configured and allow them to customize what metadata gets to be propagated. This can be depicted by the following diagram:
3333

3434
```
3535
┌──────────────────────────────────┐
@@ -74,7 +74,7 @@ As you can see, the library does not know anything about what tracing system or
7474

7575
All it has to do is query for the current [task-local](https://developer.apple.com/documentation/swift/tasklocal) `Baggage` value, and if one is present, call on the instrumentation system to inject it into the request.
7676

77-
Since neither, the tracing API, or the specific tracer backend are aware of this library's specific `HTTPRequest` type, we also need to implement an ``Injector`` which takes on the responsibility of adding the metadata into the carrier type (which in our case is the `HTTPRequest`). An injector could for example be implemented like this:
77+
Since neither the tracing API nor the specific tracer backend is aware of this library's specific `HTTPRequest` type, we also need to implement an ``Injector`` which takes on the responsibility of adding the metadata into the carrier type (which in our case is the `HTTPRequest`). An injector could for example be implemented like this:
7878

7979
```swift
8080
struct HTTPRequestInjector: Injector {
@@ -84,13 +84,13 @@ struct HTTPRequestInjector: Injector {
8484
}
8585
```
8686

87-
Once the metadat has been injected, the request–including all the additional metadatais sent over the network.
87+
Once the metadata has been injected, the request–including all the additional metadata is sent over the network.
8888

8989
> Note: The actual logic of deciding what baggage values to inject depend on the tracer implementation, and thus we are not covering it in this _end-user_ focused guide. Refer to <doc:ImplementATracer> if you'd like to learn about implementing a ``TracerProtocol``.
9090
9191
#### Handling inbound requests
9292

93-
On the receiving side, an HTTP server needs to perform the inverse operation, as it receives the request from the network and forms an `HTTPRequest` object, and before it passed it to user-code, it must extract any trace metadata from the request headers into the `Baggage`.
93+
On the receiving side, an HTTP server needs to perform the inverse operation, as it receives the request from the network and forms an `HTTPRequest` object, and before it passes it to user-code, it must extract any trace metadata from the request headers into the `Baggage`:
9494

9595
```
9696
┌──────────────────────────────────┐
@@ -113,7 +113,7 @@ On the receiving side, an HTTP server needs to perform the inverse operation, as
113113
└────
114114
```
115115

116-
This is very similar to what we were doing on the outbound side, but the roles of baggage and request are somewhat inversed: we're extracting values from the carrier into the baggage. The code performing this task could look something like this:
116+
This is very similar to what we were doing on the outbound side, but the roles of baggage and request are somewhat reversed: we're extracting values from the carrier into the baggage. The code performing this task could look something like this:
117117

118118
```swift
119119
func handler(request: HTTPRequest) async {
@@ -132,7 +132,7 @@ func handler(request: HTTPRequest) async {
132132
}
133133
```
134134

135-
Similarily to the outbound side, we need to implement an ``Extractor`` because the tracing libraries don't know about our specific HTTP types, yet we need to have them decide for which values to extract keys.
135+
Similarly to the outbound side, we need to implement an ``Extractor`` because the tracing libraries don't know about our specific HTTP types, yet we need to have them decide for which values to extract keys.
136136

137137
```swift
138138
struct HTTPRequestExtract: Instrumentation.Extractor {
@@ -158,7 +158,7 @@ func handler(request: HTTPRequest) async {
158158
}
159159
```
160160

161-
This sets the task-local value `Baggage.current` which is used by [swift-log](https://github.com/apple/swift-log), as well as ``TracerProtocol`` APIs in order to later "*pick up*" the baggage and and e.g. include it in log statements, or start new trace spans using the information stored in the baggage.
161+
This sets the task-local value `Baggage.current` which is used by [swift-log](https://github.com/apple/swift-log), as well as ``TracerProtocol`` APIs in order to later "*pick up*" the baggage and e.g. include it in log statements, or start new trace spans using the information stored in the baggage.
162162

163163
> Note: The end goal here being that when end-users of your library write `log.info("Hello")` the logger is able to pick up the contextual baggage information and include the e.g. the `trace-id` in such log statement automatically! This way, every log made during the handling of this request would include the trade-id automatically, e.g. like this:
164164
>
@@ -200,15 +200,15 @@ actor MySampleServer {
200200
}
201201
```
202202

203-
While this code is very simple for illustration purposes, and it may seem suprising why there are those two separate places where we need to call into user-code separately. But in practice such situations can happen when using asynchronous network or database libraries which offer their API in terms of such callbacks. Always consider if and when to restore baggage such that it makes sense for the end user.
203+
While this code is very simple for illustration purposes, and it may seem surprising why there are two separate places where we need to call into user-code separately, in practice such situations can happen when using asynchronous network or database libraries which offer their API in terms of callbacks. Always consider if and when to restore baggage such that it makes sense for the end user.
204204

205205
### Starting Trace Spans in Your Library
206206

207207
The above steps are enough if you wanted to provide contextual baggage propagation, and already enables techniques such as *correlation ids* which can be set once, in one system, and then carried through to any downstream services the code makes calls from while the baggage is set.
208208

209-
Many libraries also have the opportunity to start trace spans themselfes, on behalf of users, in pieces of the library that can provide useful insight in the behavior or the library in production. For example, the HTTPServer can start spans as soon as it begins handling HTTP requests, and this way provide a parent span to any spans the user-code would be creating itself.
209+
Many libraries also have the opportunity to start trace spans themselves, on behalf of users, in pieces of the library that can provide useful insight in the behavior or the library in production. For example, the HTTPServer can start spans as soon as it begins handling HTTP requests, and this way provide a parent span to any spans the user-code would be creating itself.
210210

211-
Let us revisit the previous sample HTTPServer which restored baggage around invoking the user-code, and further extend it to start a span including basic information about the HTTPRequest being handled:
211+
Let us revisit the previous sample HTTPServer which restores baggage around invoking the user-code, and further extend it to start a span including basic information about the HTTPRequest being handled:
212212

213213
```swift
214214
// SUB-OPTIMAL EXAMPLE:
@@ -272,7 +272,7 @@ func finishHandling(request: HTTPRequest, response: HTTPResponse) {
272272
}
273273
```
274274

275-
It is very important to _always_ end spans that are started, as otherwise resources they use may keep accumulating and lead to memory leaks, or worse issues in tracing backends dependin on their implementation.
275+
It is very important to _always_ end spans that have been started, as otherwise resources they use may keep accumulating and lead to memory leaks, or worse issues in tracing backends depending on their implementation.
276276

277277
The manual way of managing spans also means that error paths need to be treated with increased attention. This is something the `withSpan` APIs handle automatically, but we cannot rely on the `withSpan` detecting an error thrown out of its body closure anymore when using the `startSpan`/`end` APIs.
278278

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
## Overview
44

5-
This guide is aimed at **application developers** who have some server-side system and with to make use of distributed tracing
6-
in order to improve their experience understanding, and performance tuning and debugging their services in production or development.
5+
This guide is aimed at **application developers** who have some server-side system and want to make use of distributed tracing
6+
in order to improve their understanding and facilitate performance tuning and debugging their services in production or development.
77

8-
Distributed tracing offers a way to gain additional insight into your application is performing in production,
9-
without having to reconstruct the "big picture" from manually piecing together log lines and figuring out what happened
8+
Distributed tracing offers a way to gain additional insight into how your application is performing in production, without having to reconstruct the "big picture" from manually piecing together log lines and figuring out what happened
109
after what else and _why_. Distributed traces, as the name implies, also span multiple nodes in a micro-service architecture
11-
or clustered system, and provide a profiler like experience to debugging the handling of a "request" or otherwise defined span.
10+
or clustered system, and provide a profiler-like experience to debugging the handling of a "request" or otherwise defined span.
1211

1312
### Setting up instruments & tracers
1413

@@ -92,7 +91,7 @@ Libraries which support tracing are expected to accept a `FIXME!!!` parameter, w
9291

9392
> 💡 This general style recommendation has been ironed out together with the Swift standard library, core team, the SSWG as well as members of the community. Please respect these recommendations when designing APIs such that all APIs are able to "feel the same" yielding a great user experience for our end users ❤️
9493
>
95-
> It is possible that the ongoing Swift Concurrency efforts, and "Task Local" values will resolve this explicit context passing problem, however until these arrive in the language, please adopt the "context is the last parameter" style as outlined here.
94+
> It is possible that the ongoing Swift Concurrency efforts and "Task Local" values will resolve this explicit context passing problem, however until these arrive in the language, please adopt the "context is the last parameter" style as outlined here.
9695
9796
Propagating baggage context through your system is to be done explicitly, meaning as a parameter in function calls, following the "flow" of execution.
9897

Sources/Tracing/Docs.docc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ While Swift Distributed Tracing allows building all kinds of _instruments_, whic
1010

1111
### Quickstart Guides
1212

13-
We provide a number of guides, aimed at getting your started with tracing your systems and have prepared them from three "angles":
13+
We provide a number of guides aimed at getting your started with tracing your systems and have prepared them from three "angles":
1414

1515
1. **Application developers** who create server-side applications
1616
* please refer to the <doc:TraceYourApplication> guide.

0 commit comments

Comments
 (0)