-
Notifications
You must be signed in to change notification settings - Fork 4
XRayRecorder_Segment
A segment records tracing information about a request that your application serves.
public class Segment
At a minimum, a segment records the name, ID, start time, trace ID, and end time of the request.
Encodable
Segments and subsegments can include a metadata object containing one or more fields with values of any type, including objects and arrays.
X-Ray does not index metadata, and values can be any size, as long as the segment document doesn't exceed the maximum size (64 kB).
You can view metadata in the full segment document returned by the BatchGetTraces API.
Field keys (debug in the following example) starting with AWS.
are reserved for use by AWS-provided SDKs and clients.
public typealias Metadata = [String: AnyEncodable]
Context baggage containing XRayContext
.
var baggage: BaggageContext
Indicates if the segment is recording information.
var isSampled: Bool
The logical name of the service that handled the request, up to 200 characters. For example, your application's name or domain name. Names can contain Unicode letters, numbers, and whitespace, and the following symbols: _, ., :, /, %, &, #, =, +, , -, @
var name: String
Creates new subsegment.
@inlinable public func subsegment<T>(name: String, startTime: XRayRecorder.Timestamp = .now(), metadata: XRayRecorder.Segment.Metadata? = nil, body: (XRayRecorder.Segment) throws -> T) rethrows -> T
Records thrown Error
.
- name: - name: segment name
- startTime: - startTime: start time, defaults to now
- metadata: - metadata: segment metadata
- body: - body: subsegment body
Creates new subsegment.
@inlinable public func subsegment<T, E>(name: String, startTime: XRayRecorder.Timestamp = .now(), metadata: XRayRecorder.Segment.Metadata? = nil, body: (XRayRecorder.Segment) throws -> Result<T, E>) rethrows -> Result<T, E>
Records thrown Error
and .failure
.
- name: - name: segment name
- startTime: - startTime: start time, defaults to now
- metadata: - metadata: segment metadata
- body: - body: subsegment body
Records details about an HTTP request that your application served (in a segment) or that your application made to a downstream HTTP API (in a subsegment).
public func setHTTPRequest(method: HTTPMethod, url: String, userAgent: String? = nil, clientIP: String? = nil)
The IP address of the requester can be retrieved from the IP packet's Source Address
or, for forwarded requests,
from an X-Forwarded-For
header.
- method: - method: The request method. For example,
GET
. - url: - url: The full URL of the request, compiled from the protocol, hostname, and path of the request.
- userAgent: - userAgent: The user agent string from the requester's client.
- clientIP: - clientIP: The IP address of the requester.
Records details about an HTTP request that your application served (in a segment) or that your application made to a downstream HTTP API (in a subsegment).
public func setHTTPRequest(_ request: HTTPRequestHead)
The IP address of the requester is retrieved from an X-Forwarded-For
header.
- request: - request: HTTP request.
Records details about an HTTP response that your application served (in a segment) or that your application made to a downstream HTTP API (in a subsegment).
public func setHTTPResponse(_ response: HTTPResponseHead)
Set one or more of the error fields:
-
error
- if response status code was 4XX Client Error -
throttle
- if response status code was 429 Too Many Requests -
fault
- if response status code was 5XX Server Error
- response: - response: HTTP response.
Records details about an HTTP response that your application served (in a segment) or that your application made to a downstream HTTP API (in a subsegment).
public func setHTTPResponse(status: HTTPResponseStatus)
Set one or more of the error fields:
-
error
- if response status code was 4XX Client Error -
throttle
- if response status code was 429 Too Many Requests -
fault
- if response status code was 5XX Server Error
- status: - status: HTTP status.
Updates endTime
of the Segment.
public func end()
Has no effect if the segment has been already ended or emitted in which case an error will be logged.
Creates new subsegment.
public func beginSubsegment(name: String, startTime: XRayRecorder.Timestamp = .now(), metadata: XRayRecorder.Segment.Metadata? = nil) -> XRayRecorder.Segment
- name: - name: segment name
- startTime: - startTime: start time, defaults to now
- metadata: - metadata: segment metadata
Records an excaption.
public func addException(message: String, type: String? = nil)
- message: - message: exception message
- type: - type: excetion type
Records and error.
public func addError(_ error: Error)
- error: - error: error
Records details about an HTTP request that your application served (in a segment) or that your application made to a downstream HTTP API (in a subsegment).
public func setHTTPRequest(method: String, url: String, userAgent: String? = nil, clientIP: String? = nil)
The IP address of the requester can be retrieved from the IP packet's Source Address
or, for forwarded requests,
from an X-Forwarded-For
header.
Has no effect if the HTTP method is invalid in which case an error will be logged.
- method: - method: The request method. For example,
GET
. - url: - url: The full URL of the request, compiled from the protocol, hostname, and path of the request.
- userAgent: - userAgent: The user agent string from the requester's client.
- clientIP: - clientIP: The IP address of the requester.
Records details about an HTTP response that your application served (in a segment) or that your application made to a downstream HTTP API (in a subsegment).
public func setHTTPResponse(status: UInt, contentLength: UInt? = nil)
Set one or more of the error fields:
-
error
- if response status code was 4XX Client Error -
throttle
- if response status code was 429 Too Many Requests -
fault
- if response status code was 5XX Server Error
- status: - status: HTTP status of the response.
- contentLength: - contentLength: the length of the response body in bytes.
Sets an annotation.
public func setAnnotation(_ value: String, forKey key: String)
Keys must be alphanumeric in order to work with filters. Underscore is allowed. Other symbols and whitespace are not allowed.
X-Ray indexes up to 50 annotations per trace.
- value: - value: annotation value
- key: - key: annotation key
Sets an annotation.
public func setAnnotation(_ value: Bool, forKey key: String)
Keys must be alphanumeric in order to work with filters. Underscore is allowed. Other symbols and whitespace are not allowed.
X-Ray indexes up to 50 annotations per trace.
- value: - value: annotation value
- key: - key: annotation key
Sets an annotation.
public func setAnnotation(_ value: Int, forKey key: String)
Keys must be alphanumeric in order to work with filters. Underscore is allowed. Other symbols and whitespace are not allowed.
X-Ray indexes up to 50 annotations per trace.
- value: - value: annotation value
- key: - key: annotation key
Sets an annotation.
public func setAnnotation(_ value: Double, forKey key: String)
Keys must be alphanumeric in order to work with filters. Underscore is allowed. Other symbols and whitespace are not allowed.
X-Ray indexes up to 50 annotations per trace.
- value: - value: annotation value
- key: - key: annotation key
Sets metadata object.
public func setMetadata(_ metadata: Metadata)
Replaces all previously set metadata.
Keys starting with AWS.
are reserved for use by AWS-provided SDKs and clients.
- metadata: - metadata: metadata object
Sets a metadata value.
public func setMetadata(_ value: AnyEncodable, forKey key: String)
Overwrites previous value.
Keys starting with AWS.
are reserved for use by AWS-provided SDKs and clients.
- value: - value: metadata value
- key: - key: metadata key
Appends a metadata value.
public func appendMetadata(_ value: AnyEncodable, forKey key: String)
Stores the value in a collection, appending to the end of the collection if it already exists.
Keys starting with AWS.
are reserved for use by AWS-provided SDKs and clients.
- value: - value: metadata value
- key: - key: metadata key
public func encode(to encoder: Encoder) throws
Generated at 2020-08-17T04:20:53+0000 using swift-doc 1.0.0-beta.4.
Types
- AnyCodable
- AnyDecodable
- AnyEncodable
- XRayLogEmitter
- XRayNoOpEmitter
- XRayNoOpRecorder
- XRayRecorder
- XRayRecorder.Config
- XRayRecorder.Config.ContextMissingStrategy
- XRayRecorder.Segment
- XRayRecorder.Segment.ID
- XRayRecorder.Timestamp
- XRayRecorder.TraceContext
- XRayRecorder.TraceID
- XRayUDPEmitter
- XRayUDPEmitter.Config
- XRayUDPEmitter.EventLoopGroupProvider
- XRayUDPEmitter.SegmentEncoding