Skip to content

Commit f0192ec

Browse files
committed
fix warnings
1 parent 45d79d5 commit f0192ec

9 files changed

+171
-121
lines changed

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

+11-47
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
This guide is aimed at ``Tracer`` and ``Instrument`` protocol implementation authors.
5+
This guide is aimed at ``Tracer`` and `Instrument` protocol implementation authors.
66

77
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. This guide will also complete your understanding of how distributed tracing systems actually work, so even the casual developer may find this guide useful to read through, even if not implementing your own tracers.
88

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

1515
## Creating an instrument
1616

17-
In order to implement an instrument you need to implement the ``Instrument`` protocol.
18-
``Instrument`` is part of the `Instrumentation` library that `Tracing` depends on and offers the minimal core APIs that allow implementing instrumentation types.
17+
In order to implement an instrument you need to implement the `Instrument` protocol.
18+
`Instrument` is part of the `Instrumentation` library that `Tracing` depends on and offers the minimal core APIs that allow implementing instrumentation types.
1919

2020
`Instrument` has two requirements:
2121

22-
1. A ``Instrument/extract(_:into:using:)`` method, which extracts values from a generic carrier (e.g. HTTP headers) and store them into a `Baggage` instance
23-
2. A ``Istrument/inject(_:into:using:)`` method, which takes values from the `Baggage` to inject them into a generic carrier (e.g. HTTP headers)
22+
1. A `Instrument/extract(_:into:using:)` method, which extracts values from a generic carrier (e.g. HTTP headers) and store them into a `Baggage` instance
23+
2. A `Instrument/inject(_:into:using:)` method, which takes values from the `Baggage` to inject them into a generic carrier (e.g. HTTP headers)
2424

2525
The two methods will be called by instrumented libraries/frameworks at asynchronous boundaries, giving you a chance to
2626
act on the provided information or to add additional information to be carried across these boundaries.
@@ -116,59 +116,23 @@ func handler(request: HTTPRequest) async throws {
116116
> In case your library makes use of the `NIOHTTP1.HTTPHeaders` type we already have an `HTTPHeadersInjector` and
117117
`HTTPHeadersExtractor` available as part of the `NIOInstrumentation` library.
118118

119-
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.
119+
For your library/framework to be able to carry `Baggage` across asynchronous boundaries, it's crucial that you carry the context throughout your entire call chain in order to avoid dropping metadata.
120120

121-
### Tracing your library
122-
123-
When your library/framework can benefit from tracing, you should make use of it by integrating the `Tracing` library.
124-
125-
In order to work with the tracer [configured by the end-user](#Bootstrapping-the-Instrumentation-System), it adds a property to `InstrumentationSystem` that gives you back a `Tracer`. You can then use that tracer to start `Span`s. In an HTTP client you e.g.
126-
should start a `Span` when sending the outgoing HTTP request:
127-
128-
```swift
129-
func get(url: String, context: FIXME!!!) {
130-
var request = HTTPRequest(url: url)
131-
132-
// inject the request headers into the baggage as explained above
133-
134-
// start a span for the outgoing request
135-
let tracer = InstrumentationSystem.tracer
136-
var span = tracer.startSpan(named: "HTTP GET", context: context, ofKind: .client)
137-
138-
// set attributes on the span
139-
span.attributes.http.method = "GET"
140-
// ...
141-
142-
self.execute(request).always { _ in
143-
// set some more attributes & potentially record an error
144-
145-
// end the span
146-
span.end()
147-
}
148-
}
149-
```
150-
151-
> ⚠️ Make sure to ALWAYS end spans to ensure that all paths taken by the code will result in ending the span.
152-
> Make sure that error cases also set the error attribute and end the span.
153-
154-
> In the above example we used the semantic `http.method` attribute that gets exposed via the
155-
`TracingOpenTelemetrySupport` library.
156-
157-
## Instrument developers: Creating an instrument
121+
## Creating an instrument
158122

159123
Creating an instrument means adopting the `Instrument` protocol (or `Tracer` in case you develop a tracer).
160124
`Instrument` is part of the `Instrumentation` library & `Tracing` contains the `Tracer` protocol.
161125

162126
`Instrument` has two requirements:
163127

164-
1. A method to inject values inside a `FIXME!!!` into a generic carrier (e.g. HTTP headers)
165-
2. A method to extract values from a generic carrier (e.g. HTTP headers) and store them in a `FIXME!!!`
128+
1. A method to inject values inside a `Baggage` into a generic carrier (e.g. HTTP headers)
129+
2. A method to extract values from a generic carrier (e.g. HTTP headers) and store them in a `Baggage`
166130

167131
The two methods will be called by instrumented libraries/frameworks at asynchronous boundaries, giving you a chance to
168132
act on the provided information or to add additional information to be carried across these boundaries.
169133

170134
> Check out the [`Baggage` documentation](https://github.com/apple/swift-distributed-tracing-baggage) for more information on
171-
how to retrieve values from the `FIXME!!!` and how to set values on it.
135+
how to retrieve values from the `Baggage` and how to set values on it.
172136

173137
### Creating a `Tracer`
174138

@@ -199,7 +163,7 @@ extension Baggage {
199163
}
200164
}
201165

202-
var context = DefaultFIXME!!!.topLevel(logger: ...)
166+
var context = Baggage.topLevel(logger: ...)
203167
context.baggage.traceID = "4bf92f3577b34da6a3ce929d0e0e4736"
204168
print(context.baggage.traceID ?? "new trace id")
205169
```

0 commit comments

Comments
 (0)