GithubHelp home page GithubHelp logo

trace-context's Introduction

trace-context

Extract and inject W3C TraceContext headers.

Installation

cargo add trace-context

Example usage

let mut headers = http::HeaderMap::new();
headers.insert(
  "traceparent",
  "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01".parse().unwrap()
);

let context = trace_context::TraceContext::extract(&headers).unwrap();

let trace_id = u128::from_str_radix("0af7651916cd43dd8448eb211c80319c", 16);
let parent_id = u64::from_str_radix("00f067aa0ba902b7", 16);

assert_eq!(context.trace_id(), trace_id.unwrap());
assert_eq!(context.parent_id(), trace_id.ok());
assert_eq!(context.sampled(), true);

Safety

This crate uses #![deny(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

License

MIT OR Apache-2.0

trace-context's People

Contributors

watson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

trace-context's Issues

Support constructing a TraceContext from a string and not just a HeaderMap

This crate would be more useful if the interface to consturct a TraceContext didn't assume a HeaderMap as input, as all its doing is extracting the string value of the header and then parsing.

I'm happy to raise a PR to implement this but wanted to get your thoughts on how you'd like it implemented. The idomatic way might be to have a FromStr impl such as TraceContex::from_str()?.

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.