Giter Club home page Giter Club logo

aws-xray-sdk-swift's Introduction

aws-xray-sdk-swift

CI

Unofficial AWS X-Ray Recorder SDK for Swift.

Getting started

Installation

Add a dependency using Swift Package Manager.

dependencies: [
    .package(url: "https://github.com/pokryfka/aws-xray-sdk-swift.git", from: "0.1.0")
]

Recording

Create an instance of XRayRecorder:

let recorder = XRayRecorder()

Begin and end (sub)segments explicitly:

let segment = recorder.beginSegment(name: "Segment 1")
usleep(100_000)
segment.end()

use closures for convenience:

recorder.segment(name: "Segment 2") { segment in
    try? segment.subsegment(name: "Subsegment 2.1") { segment in
        _ = segment.subsegment(name: "Subsegment 2.1.1 with Result") { _ -> String in
            usleep(100_000)
            return "Result"
        }
        try segment.subsegment(name: "Subsegment 2.1.1 with Error") { _ in
            usleep(200_000)
            throw ExampleError.test
        }
    }
}

Emitting

Emit recorded segments:

let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let emmiter = XRayEmmiter(eventLoop: group.next())

try emmiter.send(segments: recorder.removeReady()).wait()

try group.syncShutdownGracefully()

Result in AWS X-Ray console:

Screenshot of the AWS X-Ray console

See AWSXRayRecorderExample/main.swift for a complete example.

Annotations

Segments and subsegments can include an annotations object containing one or more fields that X-Ray indexes for use with filter expressions. (...)

segment.setAnnotation("zip_code", value: 98101)

Metadata

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 (...)

segment.setMetadata(["debug": ["test": "Metadata string"]])

AWS SDK

Record AWSClient requests with XRayMiddleware:

let s3 = S3(middlewares: [XRayMiddleware(recorder: recorder, name: "S3")],
            httpClientProvider: .createNew)

and/or recording SwiftNIO futures:

recorder.segment(name: "List Buckets") {
    s3.listBuckets()
}

Result in AWS X-Ray console:

Screenshot of the AWS X-Ray console

See AWSXRayRecorderExampleSDK/main.swift for a complete example.

AWS Lambda

See AWSXRayRecorderExampleLambda/main.swift for AWS Lambda function example.

Check swift-aws-lambda-template for more examples and a template for deploying Lambda functions.

References

aws-xray-sdk-swift's People

Contributors

pokryfka avatar slashmo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.