Skip to content

Commit 90992c4

Browse files
committed
Move service context code in a separate file
1 parent 373efd7 commit 90992c4

2 files changed

Lines changed: 35 additions & 35 deletions

File tree

Sources/AWSLambdaRuntime/LambdaContext.swift

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import Logging
1717
import NIOCore
18-
import ServiceContextModule
1918

2019
// MARK: - Client Context
2120

@@ -243,37 +242,3 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
243242
)
244243
}
245244
}
246-
247-
// MARK: - ServiceContext integration
248-
249-
/// A ``ServiceContextKey`` for the AWS X-Ray trace ID.
250-
///
251-
/// This allows downstream libraries that depend on `swift-service-context`
252-
/// (but not on `AWSLambdaRuntime`) to access the current trace ID via
253-
/// `ServiceContext.current?.traceID`.
254-
private enum LambdaTraceIDKey: ServiceContextKey {
255-
typealias Value = String
256-
static var nameOverride: String? { AmazonHeaders.traceID }
257-
}
258-
259-
extension ServiceContext {
260-
/// The AWS X-Ray trace ID for the current Lambda invocation, if available.
261-
///
262-
/// This value is automatically set by the Lambda runtime before calling the handler
263-
/// and is available to all code running within the handler's async task tree.
264-
///
265-
/// Downstream libraries can read this without depending on `AWSLambdaRuntime`:
266-
/// ```swift
267-
/// if let traceID = ServiceContext.current?.traceID {
268-
/// // propagate traceID to outgoing HTTP requests, etc.
269-
/// }
270-
/// ```
271-
public var traceID: String? {
272-
get {
273-
self[LambdaTraceIDKey.self]
274-
}
275-
set {
276-
self[LambdaTraceIDKey.self] = newValue
277-
}
278-
}
279-
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import ServiceContextModule
2+
3+
// MARK: - ServiceContext integration
4+
5+
/// A ``ServiceContextKey`` for the AWS X-Ray trace ID.
6+
///
7+
/// This allows downstream libraries that depend on `swift-service-context`
8+
/// (but not on `AWSLambdaRuntime`) to access the current trace ID via
9+
/// `ServiceContext.current?.traceID`.
10+
private enum LambdaTraceIDKey: ServiceContextKey {
11+
typealias Value = String
12+
static var nameOverride: String? { AmazonHeaders.traceID }
13+
}
14+
15+
extension ServiceContext {
16+
/// The AWS X-Ray trace ID for the current Lambda invocation, if available.
17+
///
18+
/// This value is automatically set by the Lambda runtime before calling the handler
19+
/// and is available to all code running within the handler's async task tree.
20+
///
21+
/// Downstream libraries can read this without depending on `AWSLambdaRuntime`:
22+
/// ```swift
23+
/// if let traceID = ServiceContext.current?.traceID {
24+
/// // propagate traceID to outgoing HTTP requests, etc.
25+
/// }
26+
/// ```
27+
public var traceID: String? {
28+
get {
29+
self[LambdaTraceIDKey.self]
30+
}
31+
set {
32+
self[LambdaTraceIDKey.self] = newValue
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)