← Back to Pull requests

[SDT-0002]: (SSC side) move ServiceContext from SSC to SDT implementation #92

Open
kukushechkin opened this pull request with 777 lines diff across 11 files
View on GitHub
kukushechkin kukushechkin commented on Sep 09, 2026 15:00 UTC
Author

Turn this package into a thin compatibility layer over swift-distributed-tracing.

Motivation:

Companion to apple/swift-distributed-tracing#240. ServiceContext's implementation moved there, renamed to TracingContext. This package now re-exports it instead of owning it.

Modifications:

  • Added a dependency on swift-distributed-tracing.

  • ServiceContextModule re-exports its ContextStorage module and declares its own non-deprecated ServiceContext/ServiceContextKey/AnyServiceContextKey typealiases.

  • Moved the behavior test suite to swift-distributed-tracing.

  • Add a compatibility smoke test.

  • Updated the README to point new adopters at swift-distributed-tracing directly.
  • Result:

    import ServiceContextModule keeps working with no code changes and no deprecation warning, even in a file that also imports Tracing directly. New code should depend on swift-distributed-tracing and use TracingContext instead.

    Diff: 777 lines (+130 / -647) across 11 files Reviewer: czechboy0 Review duration: 47513m
    All Vouch review confidence checks passed
    Residual risk 0.08 = Change Risk (0.64) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.64 · 777 lines diff across 11 files
    0.64
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.87 · 5 substantive comment(s)
    0.87
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.398
    Real PR Conversation Timeline
    11 items
    FranzBusch FranzBusch commented on code on Sep 24, 2026 12:52 UTC
    Code Review
    README.md:1
    @@ -1,76 +1,63 @@
     # Swift Service Context
     
     [![Swift 6.0](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/)
    -[![Swift 6.1](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/) 
    +[![Swift 6.1](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/)
     [![Swift 6.2](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/)
     
    -`ServiceContext` is a minimal (zero-dependency) context propagation container, intended to "carry" items for purposes of cross-cutting tools to be built on top of it.
    +> **This package is now a thin compatibility layer.** The implementation of `ServiceContext` moved into
    +> [swift-distributed-tracing](https://github.com/apple/swift-distributed-tracing), where the type is named
    +> `TracingContext`. `import ServiceContextModule` keeps compiling and behaving exactly as it does today,
    +> with no code changes required.
    +>
    +> New projects, and existing ones that can freely update their code, should depend on
    +> swift-distributed-tracing directly and use `TracingContext` (or `Tracing`, if they also need spans)
    +> instead of adding this package.
     
    -It is modeled after the concepts explained in [W3C Baggage](https://w3c.github.io/baggage/) and 
    -in the spirit of [Tracing Plane](https://cs.brown.edu/~jcmace/papers/mace18universal.pdf) 's "Baggage Context" type,
    -although by itself it does not define a specific serialization format.
    +`ServiceContext` is a minimal context propagation container: a value type, propagated through task-local
    +storage, that carries arbitrary key-value pairs across concurrent Swift code.
     
    -See https://github.com/apple/swift-distributed-tracing for actual instrument types and implementations which can be used to
    -deploy various cross-cutting instruments all reusing the same baggage type. More information can be found in the
    -[SSWG meeting notes](https://gist.github.com/ktoso/4d160232407e4d5835b5ba700c73de37#swift-baggage-context--distributed-tracing).
    -
    -## Overview
    -
    -`ServiceContext` serves as currency type for carrying around additional contextual information between Swift tasks and functions.
    +## Dependency
     
    -One generally starts from a "top level" (empty) or the "current" (`ServiceContext.current`) context and then adds values to it.
    +If you already depend on this package, you do not need to change anything.

    Shouldn't we recommend them to mover over?

    kukushechkin kukushechkin commented on code on Sep 24, 2026 12:56 UTC
    Code Review
    Package.swift:1
    @@ -20,8 +20,19 @@ let package = Package(
                 ]
             ),
         ],
    +    dependencies: [
    +        .package(

    Should be changed before merging. And this defines the sequence of merges — SDT first, SSC follows.

    czechboy0 czechboy0 commented on code on Sep 24, 2026 15:06 UTC
    Code Review
    Sources/ServiceContextModule/CompatibilityShim.swift:1
    @@ -0,0 +1,26 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// This source file is part of the Swift Service Context open source project
    +//
    +// Copyright (c) 2020-2026 Apple Inc. and the Swift Service Context project authors
    +// Licensed under Apache License v2.0
    +//
    +// See LICENSE.txt for license information
    +// See CONTRIBUTORS.txt for the list of Swift Service Context project authors
    +//
    +// SPDX-License-Identifier: Apache-2.0
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// `ServiceContext`, `ServiceContextKey`, and `AnyServiceContextKey` now live in the
    +// `swift-distributed-tracing` package's `ContextStorage` module, renamed to `TracingContext`,
    +// `TracingContextKey`, and `AnyTracingContextKey`. This module re-exports the module and declares its
    +// own, non-deprecated names so `import ServiceContextModule` keeps working unchanged, with no
    +// deprecation notice, for existing dependents of this package. `TODOLocation` kept its name, so this
    +// typealias just makes it reachable under this module too.
    +@_exported import ContextStorage
    +
    +public typealias ServiceContext = ContextStorage.TracingContext
    +public typealias ServiceContextKey = ContextStorage.TracingContextKey
    +public typealias AnyServiceContextKey = ContextStorage.AnyTracingContextKey
    +public typealias TODOLocation = ContextStorage.TODOLocation

    Should we deprecate these, to nudge folks to migrate?

    kukushechkin kukushechkin commented on code on Sep 25, 2026 11:59 UTC
    Code Review
    README.md:1
    @@ -1,76 +1,63 @@
     # Swift Service Context
     
     [![Swift 6.0](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/)
    -[![Swift 6.1](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/) 
    +[![Swift 6.1](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/)
     [![Swift 6.2](https://img.shields.io/badge/Swift-6.0-ED523F.svg?style=flat)](https://swift.org/download/)
     
    -`ServiceContext` is a minimal (zero-dependency) context propagation container, intended to "carry" items for purposes of cross-cutting tools to be built on top of it.
    +> **This package is now a thin compatibility layer.** The implementation of `ServiceContext` moved into
    +> [swift-distributed-tracing](https://github.com/apple/swift-distributed-tracing), where the type is named
    +> `TracingContext`. `import ServiceContextModule` keeps compiling and behaving exactly as it does today,
    +> with no code changes required.
    +>
    +> New projects, and existing ones that can freely update their code, should depend on
    +> swift-distributed-tracing directly and use `TracingContext` (or `Tracing`, if they also need spans)
    +> instead of adding this package.
     
    -It is modeled after the concepts explained in [W3C Baggage](https://w3c.github.io/baggage/) and 
    -in the spirit of [Tracing Plane](https://cs.brown.edu/~jcmace/papers/mace18universal.pdf) 's "Baggage Context" type,
    -although by itself it does not define a specific serialization format.
    +`ServiceContext` is a minimal context propagation container: a value type, propagated through task-local
    +storage, that carries arbitrary key-value pairs across concurrent Swift code.
     
    -See https://github.com/apple/swift-distributed-tracing for actual instrument types and implementations which can be used to
    -deploy various cross-cutting instruments all reusing the same baggage type. More information can be found in the
    -[SSWG meeting notes](https://gist.github.com/ktoso/4d160232407e4d5835b5ba700c73de37#swift-baggage-context--distributed-tracing).
    -
    -## Overview
    -
    -`ServiceContext` serves as currency type for carrying around additional contextual information between Swift tasks and functions.
    +## Dependency
     
    -One generally starts from a "top level" (empty) or the "current" (`ServiceContext.current`) context and then adds values to it.
    +If you already depend on this package, you do not need to change anything.

    I would not add deprecations in the same release as the move, but in a follow-up minor release, so there is a no-deprecation-warning combination of releases allowing people to continue doing what they are doing, if they only want to depend on SSC and not update any code/libraries.

    kukushechkin kukushechkin commented on code on Sep 25, 2026 11:59 UTC
    Code Review
    Sources/ServiceContextModule/CompatibilityShim.swift:1
    @@ -0,0 +1,26 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// This source file is part of the Swift Service Context open source project
    +//
    +// Copyright (c) 2020-2026 Apple Inc. and the Swift Service Context project authors
    +// Licensed under Apache License v2.0
    +//
    +// See LICENSE.txt for license information
    +// See CONTRIBUTORS.txt for the list of Swift Service Context project authors
    +//
    +// SPDX-License-Identifier: Apache-2.0
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// `ServiceContext`, `ServiceContextKey`, and `AnyServiceContextKey` now live in the
    +// `swift-distributed-tracing` package's `ContextStorage` module, renamed to `TracingContext`,
    +// `TracingContextKey`, and `AnyTracingContextKey`. This module re-exports the module and declares its
    +// own, non-deprecated names so `import ServiceContextModule` keeps working unchanged, with no
    +// deprecation notice, for existing dependents of this package. `TODOLocation` kept its name, so this
    +// typealias just makes it reachable under this module too.
    +@_exported import ContextStorage
    +
    +public typealias ServiceContext = ContextStorage.TracingContext
    +public typealias ServiceContextKey = ContextStorage.TracingContextKey
    +public typealias AnyServiceContextKey = ContextStorage.AnyTracingContextKey
    +public typealias TODOLocation = ContextStorage.TODOLocation

    Same question as @FranzBusch asked above. I think we should first make a move without deprecations, and then release another minor with deprecations.

    czechboy0 czechboy0 approved these changes on Sep 25, 2026 12:56 UTC
    Approved Reviewer

    Approved these changes.

    heckj heckj commented on code on Sep 25, 2026 15:15 UTC
    Code Review
    Sources/ServiceContextModule/Docs.docc/index.md:1
    @@ -18,7 +18,15 @@ More information can be found in the
     
     > Note: Automatic propagation through task-locals by using `ServiceContext.current` is supported in Swift version 5.5 or later.
     
    -## Getting started
    +> Note: `ServiceContext`, `ServiceContextKey`, `AnyServiceContextKey`, and `TODOLocation` are

    this is going to leave two call-outs/asides (notes) back to back. Are both worthy of being described as explicit call outs vs. just having them as narrative text? I think the first we could drop to "just text"

    kukushechkin kukushechkin commented on code on Sep 25, 2026 17:11 UTC
    Code Review
    Sources/ServiceContextModule/Docs.docc/index.md:1
    @@ -18,7 +18,15 @@ More information can be found in the
     
     > Note: Automatic propagation through task-locals by using `ServiceContext.current` is supported in Swift version 5.5 or later.
     
    -## Getting started
    +> Note: `ServiceContext`, `ServiceContextKey`, `AnyServiceContextKey`, and `TODOLocation` are

    Maybe just remove Note from both?

    kukushechkin kukushechkin commented on code on Sep 29, 2026 09:44 UTC
    Code Review
    Sources/ServiceContextModule/Docs.docc/index.md:1
    @@ -18,7 +18,15 @@ More information can be found in the
     
     > Note: Automatic propagation through task-locals by using `ServiceContext.current` is supported in Swift version 5.5 or later.
     
    -## Getting started
    +> Note: `ServiceContext`, `ServiceContextKey`, `AnyServiceContextKey`, and `TODOLocation` are

    Done

    kukushechkin kukushechkin commented on Sep 29, 2026 09:45 UTC
    Author

    Also, TracingContext is renamed to InstrumentationContext, as discussed here: https://github.com/apple/swift-distributed-tracing/pull/240#issuecomment-5833119881

    Reviewers
    Assignees
    kukushechkin kukushechkin
    Labels
    risk: low confidence: 87.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 64.5% (MEDIUM) · Higher = larger blast radius
    64.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.2% · Lower = rushed or shallow review
    87.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 8.2% · Safe to merge
    8.2%