-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use BaggageContext to get and propagate context
- Loading branch information
Michal A
committed
Jul 25, 2020
1 parent
2d8e57f
commit 0f2852e
Showing
16 changed files
with
170 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the aws-xray-sdk-swift open source project | ||
// | ||
// Copyright (c) 2020 pokryfka and the aws-xray-sdk-swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Baggage | ||
|
||
private enum XRayContextKey: BaggageContextKey { | ||
typealias Value = XRayRecorder.TraceContext | ||
var name: String { "XRayTraceContext" } | ||
} | ||
|
||
public extension BaggageContext { | ||
/// XRay Trace Context.. | ||
var xRayContext: XRayRecorder.TraceContext? { | ||
get { | ||
self[XRayContextKey.self] | ||
} | ||
set { | ||
self[XRayContextKey.self] = newValue | ||
} | ||
} | ||
} | ||
|
||
internal extension BaggageContext { | ||
func withParent(_ parentId: XRayRecorder.Segment.ID) throws -> BaggageContext { | ||
guard var context = xRayContext else { throw XRayRecorder.TraceError.missingContext } | ||
context.parentId = parentId | ||
var updated = self | ||
updated.xRayContext = context | ||
return updated | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.