Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Sep 19, 2024
1 parent 5f1b990 commit 46ce8af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions opentelemetry-appender-tracing/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use opentelemetry::KeyValue;
use opentelemetry_appender_tracing::layer;
use opentelemetry_sdk::{logs::LoggerProvider, Resource};
use tracing::error;
use tracing_subscriber::filter::filter_fn;
use tracing_subscriber::filter::{filter_fn, EnvFilter};
use tracing_subscriber::fmt;
use tracing_subscriber::layer::Layer;
use tracing_subscriber::prelude::*;
Expand All @@ -18,15 +18,19 @@ fn main() {
)]))
.with_simple_exporter(exporter)
.build();
let env_filter = EnvFilter::from_default_env();
let otel_layer = layer::OpenTelemetryTracingBridge::new(&provider);
let internal_log_layer = fmt::Layer::default()
.with_writer(std::io::stdout) // Writes to stdout
.pretty()
.with_filter(filter_fn(|meta| meta.target().starts_with("opentelemetry"))); // Custom filter function
.with_filter(filter_fn(|meta| meta.target().starts_with("opentelemetry"))) // Custom filter function
.with_filter(env_filter);
tracing_subscriber::registry()
.with(internal_log_layer)
.with(otel_layer)
.init();
error!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "otel@opentelemetry.io", message = "This is an example message");
for i in 0..3 {
error!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "otel@opentelemetry.io", message = "This is an example message", iteration = i);
}
let _ = provider.shutdown();
}

0 comments on commit 46ce8af

Please sign in to comment.