Skip to content

Commit

Permalink
Merge pull request #24 from axiomhq/update
Browse files Browse the repository at this point in the history
API update
  • Loading branch information
Licenser authored May 22, 2024
2 parents 853ba50 + bf82372 commit 6361ae1
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 331 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on:
on:
pull_request:
branches:
- main
Expand All @@ -23,10 +23,6 @@ jobs:
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install rust
uses: actions-rs/toolchain@v1
with:
components: rustfmt
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -62,16 +58,28 @@ jobs:
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install rust
uses: actions-rs/toolchain@v1
- name: Run cargo test
uses: actions-rs/cargo@v1
env:
AXIOM_TOKEN: ${{ secrets.AXIOM_TOKEN }}
AXIOM_URL: https://cloud.dev.axiomtestlabs.co
AXIOM_DATASET: _traces
run: cargo test

validate-crate:
name: Validate crate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
command: test
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Test publish
run: cargo publish --dry-run

publish_on_crates_io:
name: Publish on crates.io
runs-on: ubuntu-latest
Expand All @@ -82,9 +90,7 @@ jobs:
- test
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions-rs/cargo@v1
with:
command: publish
- name: Publish on crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ include = [
resolver = "2"

[dependencies]
opentelemetry = { version = "0.22" }
opentelemetry-otlp = { version = "0.15", features = [
"prost",
"tokio",
"http-proto",
"reqwest-client",
] }
url = "2.4.1"
thiserror = "1"

tracing-core = { version = "0.1", default-features = false, features = ["std"] }
tracing-opentelemetry = { version = "0.23", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false, features = [
Expand All @@ -41,18 +37,22 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
"fmt",
"json",
] }


reqwest = { version = "0.11", default-features = false }
thiserror = "1"
opentelemetry-semantic-conventions = "0.14"
url = "2.4.1"
opentelemetry_sdk = { version = "0.22.1", features = ["rt-tokio"] }
opentelemetry = { version = "0.22" }
opentelemetry-otlp = { version = "0.15", features = [
"prost",
"tokio",
"http-proto",
"reqwest-client",
] }
opentelemetry-semantic-conventions = "0.15"
opentelemetry_sdk = { version = "0.22", features = ["rt-tokio"] }

[dev-dependencies]
tokio = { version = "1", features = ["full", "tracing"] }
tracing = { version = "0.1", features = ["log"] }
opentelemetry = { version = "0.22" }
anyhow = "1.0.80"
uuid = { version = "1", features = ["v4"] }
tracing-subscriber = { version = "0.3", default-features = false, features = [
"smallvec",
"std",
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For more information check out the [official documentation](https://axiom.co/doc

## Usage

Add the following to your Cargo.toml:
Add the following to your `Cargo.toml`:

```toml
[dependencies]
Expand All @@ -36,14 +36,12 @@ Then create an API token with ingest permission into that dataset in
Now you can set up tracing in one line like this:

```rust,no_run
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _, Registry};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_axiom::init()?;
let axiom_layer = tracing_axiom::default("readme")?; // Set AXIOM_DATASET and AXIOM_TOKEN in your env!
Registry::default().with(axiom_layer).init();
say_hello();
// Ensure that the tracing provider is shutdown correctly
opentelemetry::global::shutdown_tracer_provider();
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing_subscriber::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let axiom_layer = tracing_axiom::builder().with_service_name("fmt").layer()?;
let axiom_layer = tracing_axiom::builder("fmt").build()?;
let fmt_layer = tracing_subscriber::fmt::layer().pretty();
tracing_subscriber::registry()
.with(fmt_layer)
Expand Down
63 changes: 24 additions & 39 deletions examples/layers/main.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
use opentelemetry::global;
use opentelemetry_sdk::propagation::TraceContextPropagator;
use tracing::{info, instrument};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Registry;
use uuid::Uuid;
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt};

#[instrument]
fn say_hi(id: Uuid, name: impl Into<String> + std::fmt::Debug) {
fn say_hi(id: u64, name: impl Into<String> + std::fmt::Debug) {
info!(?id, "Hello, {}!", name.into());
}

fn setup_tracing(otel_is_configured: bool, tags: &[(&str, &str)]) -> Result<(), anyhow::Error> {
if otel_is_configured {
info!("Axiom OpenTelemetry tracing endpoint is configured:");
// Setup an AWS CloudWatch compatible tracing layer
let cloudwatch_layer = tracing_subscriber::fmt::layer()
.json()
.with_ansi(false)
.without_time()
.with_target(false);

// Setup an Axiom OpenTelemetry compatible tracing layer
let axiom_layer = tracing_axiom::builder()
.with_service_name("layers")
.with_tags(tags)
.layer()?;

// Setup our multi-layered tracing subscriber
Registry::default()
.with(axiom_layer)
.with(cloudwatch_layer)
.init();
} else {
info!("OpenTelemetry is not configured: Using AWS CloudWatch savvy format",);
tracing_subscriber::fmt()
.json()
.with_max_level(tracing::Level::INFO)
.with_current_span(false)
.with_ansi(false)
.without_time()
.with_target(false)
.init();
};
fn setup_tracing(tags: &[(&'static str, &'static str)]) -> Result<(), tracing_axiom::Error> {
info!("Axiom OpenTelemetry tracing endpoint is configured:");
// Setup an AWS CloudWatch compatible tracing layer
let cloudwatch_layer = tracing_subscriber::fmt::layer()
.json()
.with_ansi(false)
.without_time()
.with_target(false);

// Setup an Axiom OpenTelemetry compatible tracing layer
let tag_iter = tags.iter().copied();
let axiom_layer = tracing_axiom::builder("layers")
.with_tags(tag_iter)
.build()?;

// Setup our multi-layered tracing subscriber
Registry::default()
.with(axiom_layer)
.with(cloudwatch_layer)
.init();

global::set_text_map_propagator(TraceContextPropagator::new());

Expand All @@ -55,10 +41,9 @@ const TAGS: &[(&str, &str)] = &[

#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
setup_tracing(true, TAGS)?; // NOTE we depend on environment variable
setup_tracing(TAGS)?; // NOTE we depend on environment variable

let uuid = Uuid::new_v4();
say_hi(uuid, "world");
say_hi(42, "world");

// do something with result ...

Expand Down
22 changes: 11 additions & 11 deletions examples/noenv/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use tracing::{info, instrument};
use uuid::Uuid;
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _, Registry};

#[instrument]
fn say_hi(id: Uuid, name: impl Into<String> + std::fmt::Debug) {
fn say_hi(id: u64, name: impl Into<String> + std::fmt::Debug) {
info!(?id, "Hello, {}!", name.into());
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_axiom::builder()
.with_service_name("noenv")
.with_tags(&[("aws_region", "us-east-1")]) // Set otel tags
.with_dataset("tracing-axiom-examples") // Set dataset
.with_token("xaat-some-valid-token") // Set API token
.with_url("http://localhost:4318") // Set URL, can be changed to any OTEL endpoint
.init()?; // Initialize tracing
let axiom_layer = tracing_axiom::builder("noenv")
.with_tags([("aws_region", "us-east-1")].iter().copied()) // Set otel tags
.with_dataset("tracing-axiom-examples")? // Set dataset
.with_token("xaat-some-valid-token")? // Set API token
.with_url("http://localhost:4318")? // Set URL, can be changed to any OTEL endpoint
.build()?; // Initialize tracing

let uuid = Uuid::new_v4();
say_hi(uuid, "world");
Registry::default().with(axiom_layer).init();

say_hi(42, "world");

// do something with result ...

Expand Down
6 changes: 5 additions & 1 deletion examples/simple/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tracing::{error, instrument};
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _, Registry};

#[instrument]
fn say_hello() {
Expand All @@ -7,7 +8,10 @@ fn say_hello() {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_axiom::init()?;
let axiom_layer = tracing_axiom::default("simple")?;

Registry::default().with(axiom_layer).init();

say_hello();

// Ensure that the tracing provider is shutdown correctly
Expand Down
Loading

0 comments on commit 6361ae1

Please sign in to comment.