Crate xray_lite

Source
Expand description

Provides a client interface for AWS X-Ray

§Examples

§Subsegment of AWS service operation

The xray_lite_aws_sdk extension is recommended for tracing operations through AWS SDK for Rust.

Here is an example to record a subsegment of an AWS service operation within a Lambda function invocation instrumented with AWS X-Ray:

use xray_lite::{AwsNamespace, Context, DaemonClient, SubsegmentContext};

fn main() {
   // reads AWS_XRAY_DAEMON_ADDRESS
   let client = DaemonClient::from_lambda_env().unwrap();
   // reads _X_AMZN_TRACE_ID
   let context = SubsegmentContext::from_lambda_env(client).unwrap();

   do_s3_get_object(&context);
}

fn do_s3_get_object(context: &impl Context) {
    // subsegment will have the name "S3" and `aws.operation` "GetObject"
    let subsegment = context.enter_subsegment(AwsNamespace::new("S3", "GetObject"));

    // call S3 GetObject ...

    // if you are using `aws-sdk-s3` crate, you can update the subsegment
    // with the request ID. suppose `out` is the output of the `GetObject`
    // operation:
    //
    //     subsegment
    //         .namespace_mut()
    //         .zip(out.request_id())
    //         .map(|(ns, id)| ns.request_id(id));

    // the subsegment will be ended and reported when it is dropped
}
§Subsegment of remote service call

Here is an example to record a subsegment of a remote service call within a Lambda function invocation intstrumented with AWS X-Ray:

use xray_lite::{Context, DaemonClient, RemoteNamespace, SubsegmentContext};

fn main() {
   // reads AWS_XRAY_DAEMON_ADDRESS
   let client = DaemonClient::from_lambda_env().unwrap();
   // reads _X_AMZN_TRACE_ID
   let context = SubsegmentContext::from_lambda_env(client).unwrap();

   do_some_request(&context);
}

fn do_some_request(context: &impl Context) {
    // subsegment will have the name "readme example",
    // `http.request.method` "POST", and `http.request.url` "https://codemonger.io/"
    let subsegment = context.enter_subsegment(RemoteNamespace::new(
        "readme example",
        "GET",
        "https://codemonger.io/",
    ));

    // do some request ...

    // the subsegment will be ended and reported when it is dropped
}
§Custom subsegment

Here is an example to record a custom subsegment within a Lambda function invocation intstrumented with AWS X-Ray:

use xray_lite::{Context, DaemonClient, CustomNamespace, SubsegmentContext};

fn main() {
   // reads AWS_XRAY_DAEMON_ADDRESS
   let client = DaemonClient::from_lambda_env().unwrap();
   // reads _X_AMZN_TRACE_ID
   let context = SubsegmentContext::from_lambda_env(client).unwrap()
       .with_name_prefix("readme_example.");

   do_something(&context);
}

fn do_something(context: &impl Context) {
    // subsegment will have the name "readme_example.do_something"
    let subsegment = context.enter_subsegment(CustomNamespace::new("do_something"));

    // do some thing ...

    // the subsegment will be ended and reported when it is dropped
}

§Acknowledgements

This crate is based on the great work by Doug Tangren (softprops).

Structs§

Aws
Context information about the AWS environment this segment was run in
AwsNamespace
Namespace for an AWS service.
AwsOperation
Information about an AWS operation
CustomNamespace
Namespace for a custom subsegment.
DaemonClient
X-Ray daemon client.
Ec2
Information about an EC2 instance.
Ecs
Information about an Amazon ECS container.
ElasticBeanstalk
Information about an Elastic Beanstalk environment. You can find this information in a file named /var/elasticbeanstalk/xray/environment.conf on the latest Elastic Beanstalk platforms.
Exception
Detailed representation of an exception
Header
Parsed representation of X-Amzn-Trace-Id request header
Http
Describes an http request/response cycle
RemoteNamespace
Namespace for an arbitrary remote service.
Request
Information about a request.
Response
Information about a response.
Seconds
Represents fractional seconds since the epoch These can be derived from std::time::Duration and be converted too std::time::Duration
Segment
Description of an internal application operation which may be an extension of an external operation
Service
An object with information about your application.
Sql
Information about a SQL operation
StackFrame
A summary of a single operation within a stack trace
Subsegment
Record information about the AWS services and resources that your application accesses. X-Ray uses this information to create inferred segments that represent the downstream services in your service map.
SubsegmentContext
Context as a subsegment of an existing segment.
XRay
Metadata about the type and version of instrumentation used.

Enums§

Annotation
A value type which may be used for filter querying
Cause
Represents the cause of an errror
Error
Common error type.
InfallibleClient
Infallible client.
InfallibleContext
Infallible context.
SegmentId
Unique identifier of an operation within a trace
SubsegmentSession
Subsegment session.
TraceId
Coorelates a string of spans together

Traits§

Client
X-Ray client interface.
Context
Context.
IntoInfallibleClient
Conversion into an InfallibleClient.
IntoInfallibleContext
Conversion into an infallible context.
Namespace
Namespace.

Type Aliases§

Result
Type alias for Results which may return Error.