Logging and Telemetry exporters for Tembo.io applications

Overview

Tembo Telemetry

Logging and Telemetry exporters for Tembo.io applications.

Crates.io: tembo-telemetry Documentation LICENSE

Tembo Slack

Overview

Tembo Telemetry is a Rust crate designed to easily integrate logging and telemetry capabilities into applications built with Rust. It provides a streamlined way to configure and send telemetry data, with support for the OTLP telemetry format.

Quickstart

To get started with tembo-telemetry, add it as a dependency in your Cargo.toml:

[dependencies]
tembo-telemetry = "*"

Then, in your main application, set up and initialize the telemetry system:

use tembo_telemetry::{TelemetryConfig, TelemetryInit};

async fn main() {
    let telemetry_config = TelemetryConfig {
        app_name: "my_app".to_string(),
        env: "production".to_string(),
        endpoint_url: Some("http://my-telemetry-endpoint".to_string()),
        tracer_id: Some("my_tracer_id".to_string()),
    };

    let _ = telemetry_config.init().await;
}

Environment Configuration

The tembo-telemetry crate uses the ENV environment variable to determine the logging format suitable for different environments. This allows you to have tailored logging experiences for different deployment scenarios (e.g., development vs. production).

Setting the ENV variable

To set the logging environment, you can set the ENV variable before running your application:

export ENV=production

Logging Structure

  • Development (ENV=development): In the development environment, logs are formatted for readability. They are concise and intended for local debugging purposes.
2023-08-08T01:33:27.046003Z  INFO actix_server::builder: starting 14 workers
2023-08-08T01:33:27.046046Z  INFO trace: Starting HTTP server at https://0.0.0.0:3001/
2023-08-08T01:33:27.046067Z  INFO actix_server::server: Actix runtime found; starting in Actix runtime
  • Production (ENV=production or any other value): In the production environment or any setting other than development, logs are structured in the JSON format. This structure is optimized for machine parsing and is suitable for log aggregation systems, monitoring, and alerting tools.
{"v":0,"name":"app","msg":"starting 14 workers","level":30,"hostname":"gwaihir","pid":300368,"time":"2023-08-08T01:34:19.145972575Z","target":"actix_server::builder","line":200,"file":"/home/nhudson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-server-2.2.0/src/builder.rs"}
{"v":0,"name":"app","msg":"Starting HTTP server at https://0.0.0.0:3001/","level":30,"hostname":"gwaihir","pid":300368,"time":"2023-08-08T01:34:19.146026447Z","target":"app","line":66,"file":"src/main.rs"}
{"v":0,"name":"app","msg":"Actix runtime found; starting in Actix runtime","level":30,"hostname":"gwaihir","pid":300368,"time":"2023-08-08T01:34:19.146055049Z","target":"actix_server::server","line":196,"file":"/home/nhudson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/actix-server-2.2.0/src/server.rs"}

By default, if the ENV variable is not set, the logging will be in the non-development format.

To get the best logging experience tailored for your environment, always ensure to set the ENV variable appropriately before running your application.

You might also like...
🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

IBC modules and relayer - Formal specifications and Rust implementation

ibc-rs Rust implementation of the Inter-Blockchain Communication (IBC) protocol. This project comprises primarily four crates: The ibc crate defines t

Diem’s mission is to build a trusted and innovative financial network that empowers people and businesses around the world.
Diem’s mission is to build a trusted and innovative financial network that empowers people and businesses around the world.

Note to readers: On December 1, 2020, the Libra Association was renamed to Diem Association. The project repos are in the process of being migrated. A

Fast and efficient ed25519 signing and verification in Rust.
Fast and efficient ed25519 signing and verification in Rust.

ed25519-dalek Fast and efficient Rust implementation of ed25519 key generation, signing, and verification in Rust. Documentation Documentation is avai

A safe implementation of the secure remote password authentication and key-exchange protocol (SRP), SRP6a and legacy are as features available.

Secure Remote Password (SRP 6 / 6a) A safe implementation of the secure remote password authentication and key-exchange protocol (SRP version 6a). Ver

Retrieving SSH and GPS keys from GitHub and GitLab

Dormarch Retrieving SSH and GPS keys from GitHub and GitLab Usage After having installed Dormarch, you can see all the options with dormarch -h. To re

Terabethia - A Bridge and Messaging Protocol between Ethereum and the Internet Computer.
Terabethia - A Bridge and Messaging Protocol between Ethereum and the Internet Computer.

Terabethia - A Bridge Between Ethereum & the Internet Computer Terabethia is a bridge between Ethereum & the Internet Computer that contracts in both

A guide for Mozilla's developers and data scientists to analyze and interpret the data gathered by our data collection systems.

Mozilla Data Documentation This documentation was written to help Mozillians analyze and interpret data collected by our products, such as Firefox and

Diem’s mission is to build a trusted and innovative financial network that empowers people and businesses around the world.
Diem’s mission is to build a trusted and innovative financial network that empowers people and businesses around the world.

Note to readers: On December 1, 2020, the Libra Association was renamed to Diem Association. The project repos are in the process of being migrated. A

Comments
  • Add ability to filter logging based off a list of routes

    Add ability to filter logging based off a list of routes

    • Add implementation around setting up the TraceLogger and a custom filter to exclude routes from the Span. This way we will not log specific routes (eg, liveness, readiness).
    • Add new example showing how to exclude specific routes.
    • Add tests for the new code.
    • Update codeowners file.

    fixes: #2

    opened by nhudson 0
  • Extend environment filtering for subscriber

    Extend environment filtering for subscriber

    We will need a way to extend the env_filter for the subscriber in a manner that allows someone using this crate to write their own filtering middleware. The issue is that the tracing-actix-web crate doesn't have a good way of excluding route logging like the standard actix-web middleware::Logger.

        let server = HttpServer::new({
            let stop_handle = stop_handle.clone();
            let telemerty_config = web::Data::new(telemetry_config);
            move || {
                App::new()
                    .app_data(stop_handle.clone())
                    .app_data(telemerty_config.clone())
                    .service(hello)
                    .wrap(
                        middleware::Logger::default()
                            .exclude("/health/liveness")
                            .exclude("/health/readiness"),
                    )
                    .service(liveness)
                    .service(readiness)
            }
        })
        .bind(server_bind_address.clone())?
        .shutdown_timeout(5)
        .run();
    

    Since we are using tracing-actix-web crate, we must use TracingLogger to set Spans in the application. A good example of how to do this would be do extend something that looks like this:

    // Create a custom RootSpanBuilder
    pub struct CustomLevelRootSpanBuilder;
    
    impl RootSpanBuilder for CustomLevelRootSpanBuilder {
        fn on_request_start(request: &ServiceRequest) -> Span {
            // If the path matches our excluded routes, do not generate a span.
            match request.path() {
                "/health/liveness" | "/health/readiness" => {
                    // This is the crucial part: returning a non-recording span
                    // effectively "turns off" tracing for this request.
                    Span::none()
                }
                _ => tracing_actix_web::root_span!(level = Level::INFO, request),
            }
        }
    
        fn on_request_end<B: MessageBody>(span: Span, outcome: &Result<ServiceResponse<B>, Error>) {
            DefaultRootSpanBuilder::on_request_end(span, outcome);
        }
    }
    

    Then just build out the custom middleware with let middleware = TracingLogger::<CustomLevelRootSpanBuilder>::new();. Not quite sure if that is all that would have to be done, but I believe it's a start of something that could work.

    enhancement good first issue 
    opened by nhudson 0
Releases(v0.2.0)
  • v0.2.0(Aug 14, 2023)

    What's Changed

    • Add ability to filter logging based off a list of routes by @nhudson in https://github.com/tembo-io/tembo-telemetry/pull/3

    Full Changelog: https://github.com/tembo-io/tembo-telemetry/compare/v0.1.0...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Aug 8, 2023)

    Initial Release v0.1.0

    What's Changed

    • Initial code import with CI, publish and examples by @nhudson in https://github.com/tembo-io/tembo-telemetry/pull/1

    New Contributors

    • @nhudson made their first contribution in https://github.com/tembo-io/tembo-telemetry/pull/1

    Full Changelog: https://github.com/tembo-io/tembo-telemetry/commits/v0.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Tembo
Tembo
A lightweight and flexible framework to build your tailored blockchain applications.

TRINCI Blockchain Core A lightweight and flexible framework to build your tailored blockchain applications. Requirements The required dependencies to

Affidaty S.p.A. 11 Sep 26, 2022
End-to-end encryption and mutual authentication for distributed applications.

✨ Hands-on Introduction: Build end-to-end encrypted, mutually-authenticated, secure messaging in Rust ✨ Rust and Elixir libraries for end-to-end encry

Ockam | Trust for Data-in-Motion 2.8k Jan 2, 2023
Scrypto Advent Calendar. Learn the new programming langage to build quick and secure DeFi applications.

Scrypto Advent Calendar I am publishing new Christmas related Scrypto examples every day from Dec 1st to Dec 25th. "Watch" this project to get notifie

Clement Bisaillon 26 Nov 13, 2022
Automated security testing for open source libraries and applications.

autovet continuously searches for security breaches in open source libraries and applications. Recently processed packages package version channel las

null 5 Aug 23, 2022
CosmWasm-Examples is a collection of example contracts and applications built using the CosmWasm framework

CosmWasm-Examples is a collection of example contracts and applications built using the CosmWasm framework. CosmWasm is a secure and efficient smart contract platform designed specifically for the Cosmos ecosystem.

Vitalii Tsyhulov 20 Jun 9, 2023
Key derivation and cryptographic signing functionality for Ethereum applications (ethers-rs)

ethers-signer-factory ethers-signer-factory is a Rust crate that provides functions for key derivation and signing of Ethereum transactions and messag

Ilia 3 Sep 27, 2023
An extensible open-source framework for creating private/permissioned blockchain applications

Exonum Status: Project info: Community: Exonum is an extensible open-source framework for creating blockchain applications. Exonum can be used to crea

Exonum 1.2k Jan 1, 2023
An Ethereum 2.0 Emulator for Local Testing of Eth2 Applications

Mousse is an Ethereum 2.0 emulator for local testing of Eth2 applications (mainly Rollups). HTTP Server The REST API definition can be found in the ht

Mousse 46 Sep 10, 2022
Example worker for ethereum-based applications

Ethsig-rs Example worker for ethereum-based applications. Features: Verify arbitrary messages and their signature from an Ethereum Address Verify EIP-

odyslam.eth 28 Sep 26, 2022
A small, 8-byte, ID type for use in rust applications that need a pretty unique identifier

TinyId A small, 8-byte, ID type for use in rust applications that need a pretty unique identifier that is not required to be cryptographically secure

Tony B 1 May 4, 2022