Giter VIP home page Giter VIP logo

tracing-aliyun-sls's Introduction

tracing-aliyun-sls

Crates.io Documentation MIT licensed FOSSA Status

Enable tracing integration with Aliyun SLS, also support log crate.

Feature Flags

  • lz4: enable lz4 compression for logs.
  • deflate: enable deflate compression for logs.
  • log-comp: enable the Logger for log crate.
  • derive-key: enable the ability to derive the shard key (128 bits hex) from any string using BLAKE3.
  • rustls: By default, it enables reqwest/default-tls, if you want to use rustls as the TLS backend, enable this feature also disable default features.

Note: lz4 and deflate cannot be enabled at the same time.

Example

To use with tracing:

use tracing_aliyun_sls::SlsLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

#[tokio::main]
async fn main() {
   let (layer, _guard) = SlsLayer::builder()
        .access_key("access_key")
        .access_secret("access_secret")
        .endpoint("cn-hangzhou.log.aliyuncs.com")
        .project("project")
        .logstore("logstore")
        .shard_key("shard_key") // Optional if you want to use `KeyHash` mode
        .max_level(tracing::Level::INFO) // Optional, default is `tracing::Level::TRACE`
        .drain_timeout(std::time::Duration::from_secs(10)) // Optional, default is 5 seconds
        .build_layer();
    
    tracing_subscriber::registry()
        .with(layer)
        .init();
}

If you want to use it with log, enable the log-comp feature:

use tracing_aliyun_sls::SlsLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

#[tokio::main(flavor = "current_thread")]
async fn main() {
   SlsLayer::builder()
        .access_key("access_key")
        .access_secret("access_secret")
        .endpoint("cn-hangzhou.log.aliyuncs.com")
        .project("project")
        .logstore("logstore")
        .shard_key("shard_key") // Optional if you want to use `KeyHash` mode
        .max_level(tracing::Level::INFO) // Optional, default is `tracing::Level::TRACE`
        .drain_timeout(std::time::Duration::from_secs(10)) // Optional, default is 5 seconds
        .build_logger()
        .init();
}

License

FOSSA Status

tracing-aliyun-sls's People

Contributors

lightsing avatar fossabot avatar

Watchers

 avatar  avatar

Forkers

fossabot

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.