Skip to content

XRayRecorder

pokryfka edited this page Aug 15, 2020 · 7 revisions

XRayRecorder

X-Ray tracer.

public class XRayRecorder

XRayRecorder allows to create new XRayRecorder.Segments and sends them using provided XRayEmitter.

References

Initializers

init(emitter:​config:​)

Creates an instance of XRayRecorder.

public convenience init(emitter:​ XRayEmitter, config:​ Config = Config())

Parameters

  • emitter:​ - emitter:​ emitter used to send XRayRecorder.Segments.
  • config:​ - config:​ configuration, overrides enviromental variables.

init(eventLoopGroupProvider:​config:​)

Creates an instance of XRayRecorder with XRayUDPEmitter.

public convenience init(eventLoopGroupProvider:​ XRayUDPEmitter.EventLoopGroupProvider = .createNew, config:​ Config = Config())

Parameters

  • eventLoopGroupProvider:​ - eventLoopGroupProvider:​ specifies how the EventLoopGroup used by XRayUDPEmitter will be created and establishes lifecycle ownership.
  • config:​ - config:​ configuration, overrides enviromental variables.

Methods

segment(name:​context:​startTime:​metadata:​body:​)

Creates new segment.

@inlinable public func segment<T>(name:​ String, context:​ TraceContext, startTime:​ XRayRecorder.Timestamp = .now(), metadata:​ XRayRecorder.Segment.Metadata? = nil, body:(XRayRecorder.Segment) throws -> T) rethrows -> T

Records thrown Error.

Parameters

  • name:​ - name:​ segment name
  • context:​ - context:​ the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata
  • body:​ - body:​ segment body

segment(name:​baggage:​startTime:​metadata:​body:​)

Creates new segment.

@inlinable public func segment<T>(name:​ String, baggage:​ BaggageContext, startTime:​ XRayRecorder.Timestamp = .now(), metadata:​ XRayRecorder.Segment.Metadata? = nil, body:(XRayRecorder.Segment) throws -> T) rethrows -> T

Records thrown Error.

Extracts the trace context from the baggage. Creates new one if the baggage does not contain a valid XRayContext.

Depending on the context missing strategy configuration will log an error or fail if the context is missing.

Parameters

  • name:​ - name:​ segment name
  • baggage:​ - baggage:​ baggage with the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata
  • body:​ - body:​ segment body

segment(name:​context:​startTime:​metadata:​body:​)

Creates new segment.

@inlinable public func segment<T, E>(name:​ String, context:​ TraceContext, 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.

Parameters

  • name:​ - name:​ segment name
  • context:​ - context:​ the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata
  • body:​ - body:​ segment body

segment(name:​baggage:​startTime:​metadata:​body:​)

Creates new segment.

@inlinable public func segment<T, E>(name:​ String, baggage:​ BaggageContext, 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.

Extracts the trace context from the baggage. Creates new one if the baggage does not contain a valid XRayContext.

Depending on the context missing strategy configuration will log an error or fail if the context is missing.

Parameters

  • name:​ - name:​ segment name
  • baggage:​ - baggage:​ baggage with the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata
  • body:​ - body:​ segment body

flush(on:​)

Flushes the emitter in SwiftNIO future.

public func flush(on eventLoop:​ EventLoop) -> EventLoopFuture<Void>

Parameters

  • eventLoop:​ - eventLoop:​ EventLoop used to "do the flushing".

segment(name:​context:​startTime:​metadata:​body:​)

Creates new segment.

@inlinable public func segment<T>(name:​ String, context:​ TraceContext, startTime:​ XRayRecorder.Timestamp = .now(), metadata:​ XRayRecorder.Segment.Metadata? = nil, body:() -> EventLoopFuture<T>) -> EventLoopFuture<T>

Records Error.

Parameters

  • name:​ - name:​ segment name
  • context:​ - context:​ the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata
  • body:​ - body:​ segment body

segment(name:​baggage:​startTime:​metadata:​body:​)

Creates new segment.

@inlinable public func segment<T>(name:​ String, baggage:​ BaggageContext, startTime:​ XRayRecorder.Timestamp = .now(), metadata:​ XRayRecorder.Segment.Metadata? = nil, body:() -> EventLoopFuture<T>) -> EventLoopFuture<T>

Records Error.

Parameters

  • name:​ - name:​ segment name
  • baggage:​ - baggage:​ baggage with the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata
  • body:​ - body:​ segment body

beginSegment(name:​context:​startTime:​metadata:​)

Creates new segment.

public func beginSegment(name:​ String, context:​ TraceContext, startTime:​ XRayRecorder.Timestamp = .now(), metadata:​ XRayRecorder.Segment.Metadata? = nil) -> XRayRecorder.Segment

Parameters

  • name:​ - name:​ segment name
  • context:​ - context:​ the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata

Returns

new segment

beginSegment(name:​baggage:​startTime:​metadata:​)

Creates new segment.

public func beginSegment(name:​ String, baggage:​ BaggageContext, startTime:​ XRayRecorder.Timestamp = .now(), metadata:​ XRayRecorder.Segment.Metadata? = nil) -> XRayRecorder.Segment

Extracts the trace context from the baggage. Creates new one if the baggage does not contain a valid XRayContext.

Depending on the context missing strategy configuration will log an error or fail if the context is missing.

Parameters

  • name:​ - name:​ segment name
  • baggage:​ - baggage:​ baggage with the trace context
  • startTime:​ - startTime:​ start time, defaults to now
  • metadata:​ - metadata:​ segment metadata

Returns

new segment

wait(_:​)

Flushes the emitter. May be blocking.

public func wait(_ callback:((Error?) -> Void)? = nil)

Parameters

  • callback:​ - callback:​ callback with error if the operation failed.

shutdown(_:​)

Flushes the emitter. May be blocking.

public func shutdown(_ callback:((Error?) -> Void)? = nil)

XRayRecorder.Segments after shutdown are NOT recorded.

Parameters

  • callback:​ - callback:​ callback with error if the operation failed.
Clone this wiki locally