You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|_Your library?_| ... |[Get in touch!](https://forums.swift.org/c/server/43)|
@@ -135,7 +135,7 @@ If you don't bootstrap (or other instrument) the default no-op tracer is used,
135
135
136
136
**Automatically reported spans**: When using an already instrumented library, e.g. an HTTP Server which automatically emits spans internally, this is all you have to do to enable tracing. It should now automatically record and emit spans using your configured backend.
137
137
138
-
**Using baggage and logging context**: The primary transport type for tracing metadata is called `Baggage`, and the primary type used to pass around baggage context and loggers is `LoggingContext`. Logging context combines baggage context values with a smart `Logger` that automatically includes any baggage values ("trace metadata") when it is used for logging. For example, when using an instrumented HTTP server, the API could look like this:
138
+
**Using baggage and logging context**: The primary transport type for tracing metadata is called `ServiceContext`, and the primary type used to pass around baggage context and loggers is `LoggingContext`. Logging context combines baggage context values with a smart `Logger` that automatically includes any baggage values ("trace metadata") when it is used for logging. For example, when using an instrumented HTTP server, the API could look like this:
139
139
140
140
```swift
141
141
SomeHTTPLibrary.handle { (request, context) in
@@ -157,9 +157,9 @@ In this snippet, we use the context logger to log a very useful message. However
157
157
158
158
Thanks to tracing, and trace identifiers, even if not using tracing visualization libraries, we can immediately co-relate log statements and know that the request `1111-23-1234556` has failed. Since our application can also _add_ values to the context, we can quickly notice that the error seems to occur for the user `Charlie` and not for user `Alice`. Perhaps the user Charlie has exceeded some quotas, does not have permissions or we have a bug in parsing names that include the letter `h`? We don't know _yet_, but thanks to tracing we can much quicker begin our investigation.
159
159
160
-
**Passing context to client libraries**: When using client libraries that support distributed tracing, they will accept a `Baggage.LoggingContext` type as their _last_ parameter in many calls.
160
+
**Passing context to client libraries**: When using client libraries that support distributed tracing, they will accept a `ServiceContext.LoggingContext` type as their _last_ parameter in many calls.
161
161
162
-
When using client libraries that support distributed tracing, they will accept a `Baggage.LoggingContext` type as their _last_ parameter in many calls. Please refer to [Context argument naming/positioning](#context-propagation-by-explicit-loggingcontext-passing) in the [Context propagation](#context-propagation-by-explicit-loggingcontext-passing) section of this readme to learn more about how to properly pass context values around.
162
+
When using client libraries that support distributed tracing, they will accept a `ServiceContext.LoggingContext` type as their _last_ parameter in many calls. Please refer to [Context argument naming/positioning](#context-propagation-by-explicit-loggingcontext-passing) in the [Context propagation](#context-propagation-by-explicit-loggingcontext-passing) section of this readme to learn more about how to properly pass context values around.
### Context propagation, by explicit `LoggingContext` passing
332
332
333
-
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [Baggage](https://github.com/apple/swift-service-context).
333
+
> `LoggingContext` naming has been carefully selected and it reflects the type's purpose and utility: It binds a [Swift Log `Logger`](https://github.com/apple/swift-log) with an associated distributed tracing [ServiceContext](https://github.com/apple/swift-service-context).
334
334
>
335
335
> It _also_ is used for tracing, by tracers reaching in to read or modify the carried baggage.
336
336
@@ -397,7 +397,7 @@ Frameworks may need to be more opinionated here, and e.g. already have some form
397
397
398
398
When adapting an existing library/framework to support `LoggingContext` and it already has a "framework context" which is expected to be passed through "everywhere", we suggest to follow these guidelines for adopting LoggingContext:
399
399
400
-
1. Add a `Baggage` as a property called `baggage` to your own `context` type, so that the call side for your
400
+
1. Add a `ServiceContext` as a property called `baggage` to your own `context` type, so that the call side for your
401
401
users becomes `context.baggage` (rather than the confusing `context.context`)
402
402
2. If you cannot or it would not make sense to carry baggage inside your framework's context object, pass (and accept (!)) the `LoggingContext` in your framework functions like follows:
403
403
- if they take no framework context, accept a `context: LoggingContext` which is the same guideline as for all other cases
@@ -417,8 +417,8 @@ Generally application developers _should not_ create new context objects, but ra
417
417
418
418
If really necessary, or for the purposes of testing, one can create a baggage or context using one of the two factory functions:
419
419
420
-
-[`DefaultLoggingContext.topLevel(logger:)`](https://github.com/apple/swift-service-context/blob/main/Sources/Baggage/LoggingContext.swift) or [`Baggage.topLevel`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/Baggage.swift) - which creates an empty context/baggage, without any values. It should _not_ be used too frequently, and as the name implies in applications it only should be used on the "top level" of the application, or at the beginning of a contextless (e.g. timer triggered) event processing.
421
-
-[`DefaultLoggingContext.TODO(logger:reason:)`](https://github.com/apple/swift-service-context/blob/main/Sources/Baggage/LoggingContext.swift) or [`Baggage.TODO`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/Baggage.swift) - which should be used to mark a parameter where "before this code goes into production, a real context should be passed instead." An application can be run with `-DBAGGAGE_CRASH_TODOS` to cause the application to crash whenever a TODO context is still in use somewhere, making it easy to diagnose and avoid breaking context propagation by accidentally leaving in a `TODO` context in production.
420
+
-[`DefaultLoggingContext.topLevel(logger:)`](https://github.com/apple/swift-service-context/blob/main/Sources/ServiceContext/LoggingContext.swift) or [`ServiceContext.topLevel`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/ServiceContext.swift) - which creates an empty context/baggage, without any values. It should _not_ be used too frequently, and as the name implies in applications it only should be used on the "top level" of the application, or at the beginning of a contextless (e.g. timer triggered) event processing.
421
+
-[`DefaultLoggingContext.TODO(logger:reason:)`](https://github.com/apple/swift-service-context/blob/main/Sources/ServiceContext/LoggingContext.swift) or [`ServiceContext.TODO`](https://github.com/apple/swift-service-context-core/blob/main/Sources/CoreBaggage/ServiceContext.swift) - which should be used to mark a parameter where "before this code goes into production, a real context should be passed instead." An application can be run with `-DBAGGAGE_CRASH_TODOS` to cause the application to crash whenever a TODO context is still in use somewhere, making it easy to diagnose and avoid breaking context propagation by accidentally leaving in a `TODO` context in production.
422
422
423
423
Please refer to the respective functions documentation for details.
## Library/Framework developers: Instrumenting your software
466
466
467
-
### Extracting & injecting Baggage
467
+
### Extracting & injecting ServiceContext
468
468
469
469
When hitting boundaries like an outgoing HTTP request you call out to the [configured instrument(s)](#Bootstrapping-the-Instrumentation-System):
470
470
@@ -549,7 +549,7 @@ Creating an instrument means adopting the `Instrument` protocol (or `Tracer` in
549
549
The two methods will be called by instrumented libraries/frameworks at asynchronous boundaries, giving you a chance to
550
550
act on the provided information or to add additional information to be carried across these boundaries.
551
551
552
-
> Check out the [`Baggage` documentation](https://github.com/apple/swift-service-context) for more information on
552
+
> Check out the [`ServiceContext` documentation](https://github.com/apple/swift-service-context) for more information on
553
553
how to retrieve values from the `LoggingContext` and how to set values on it.
554
554
555
555
### Creating a Tracer
@@ -561,16 +561,16 @@ When creating a tracer you need to create two types:
561
561
562
562
> The `Span` conforms to the standard rules defined in [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-specification/blob/v0.7.0/specification/trace/api.md#span), so if unsure about usage patterns, you can refer to this specification and examples referring to it.
563
563
564
-
### Defining, injecting and extracting Baggage
564
+
### Defining, injecting and extracting ServiceContext
Copy file name to clipboardExpand all lines: Sources/Tracing/Docs.docc/Guides/ImplementATracer.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -39,13 +39,13 @@ When creating a tracer you will need to implement two types:
39
39
### Defining, injecting and extracting ServiceContext
40
40
41
41
In order to be able to extract and inject values into the `ServiceContext` which is the value that is "carried around" across asynchronous contexts,
42
-
we need to declare a `BaggageKey`. ServiceContext generally acts as a type-safe dictionary and declaring the keys this way allows us to perform lookups
42
+
we need to declare a `ServiceContextKey`. ServiceContext generally acts as a type-safe dictionary and declaring the keys this way allows us to perform lookups
43
43
returning the expected type of values:
44
44
45
45
```swift
46
46
importTracing
47
47
48
-
privateenumTraceIDKey: BaggageKey{
48
+
privateenumTraceIDKey: ServiceContextKey{
49
49
typealiasValue=String
50
50
}
51
51
@@ -148,7 +148,7 @@ When creating a tracer you need to create two types:
0 commit comments