Skip to content

Commit

Permalink
Merge pull request #10 from microsoft/build
Browse files Browse the repository at this point in the history
Build returns a Result
  • Loading branch information
Robo210 committed Aug 28, 2024
2 parents 3663164 + 1a15226 commit 8fe5a6e
Show file tree
Hide file tree
Showing 23 changed files with 767 additions and 681 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ chrono = {version="0.4", default-features = false, features=["std"]}
once_cell = ">=1.18"
dashmap = "6"
paste = "1"
thiserror = "1"

[target.'cfg(not(target_os = "linux"))'.dependencies]
tracelogging = ">= 1.2.0"
Expand Down
2 changes: 1 addition & 1 deletion benches/etw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing_subscriber::{self, prelude::*};
pub fn etw_benchmark(c: &mut Criterion) {
let builder = LayerBuilder::new("etw_bench");
let provider_id = builder.get_provider_id();
let _subscriber = tracing_subscriber::registry().with(builder.build()).init();
let _subscriber = tracing_subscriber::registry().with(builder.build().unwrap()).init();

let etw_session = SessionBuilder::new_file_mode(
"tokio-tracing-etw-bench",
Expand Down
2 changes: 1 addition & 1 deletion benches/user_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing_subscriber::{self, prelude::*};
#[cfg(target_os = "linux")]
pub fn user_events_benchmark(c: &mut Criterion) {
let builder = LayerBuilder::new("user_events_bench");
let _subscriber = tracing_subscriber::registry().with(builder.build()).init();
let _subscriber = tracing_subscriber::registry().with(builder.build().unwrap()).init();

// Disabled provider
// {
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvBasic").build()) // Collects everything
.with(LayerBuilder::new_common_schema_events("ExampleProvBasic_CS").build_with_target("geneva"))
.with(LayerBuilder::new("ExampleProvBasic").build().unwrap()) // Collects everything
.with(LayerBuilder::new_common_schema_events("ExampleProvBasic_CS").build_with_target("geneva").unwrap())
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

Expand Down
2 changes: 1 addition & 1 deletion examples/etw_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new_common_schema_events("ExampleProvEtwEvent_CS").build())
.with(LayerBuilder::new_common_schema_events("ExampleProvEtwEvent_CS").build().unwrap())
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

Expand Down
2 changes: 1 addition & 1 deletion examples/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn test_function(x: u32, y: f64) -> f64 {

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvInstrument").build()) // Collects everything
.with(LayerBuilder::new("ExampleProvInstrument").build().unwrap()) // Collects everything
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

Expand Down
2 changes: 1 addition & 1 deletion examples/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new_common_schema_events("ExampleProvSpan_CS").build())
.with(LayerBuilder::new_common_schema_events("ExampleProvSpan_CS").build().unwrap())
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

Expand Down
2 changes: 1 addition & 1 deletion examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing_subscriber::{self, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvEtwEventStress").build())
.with(LayerBuilder::new("ExampleProvEtwEventStress").build().unwrap())
.init();

for i in 0..500000 {
Expand Down
28 changes: 1 addition & 27 deletions src/_details.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Module for internal structs that need to be publically accessible,
// Module for internal structs that need to be publicly accessible,
// but should not be directly used by consumers of the crate.
//
// Implementations for these structs are contained in other files.

use std::{marker::PhantomData, pin::Pin, sync::Arc};

use crate::native::ProviderTypes;

// Public with public fields because the `etw_event!` macro needs to create it at invocation site.
#[doc(hidden)]
Expand All @@ -14,27 +12,3 @@ pub struct EventMetadata {
pub identity: tracing::callsite::Identifier,
pub event_tag: u32,
}

// This struct needs to be public as it implements the tracing_subscriber::Layer trait.
#[doc(hidden)]
pub struct EtwLayer<S, Mode: ProviderTypes>
where
Mode::Provider: crate::native::EventWriter<Mode> + 'static
{
pub(crate) provider: Pin<Arc<Mode::Provider>>,
pub(crate) default_keyword: u64,
pub(crate) _p: PhantomData<S>,
}

// This struct needs to be public as it implements the tracing_subscriber::Layer::Filter trait.
#[doc(hidden)]
#[cfg(any(not(feature = "global_filter"), docsrs))]
pub struct EtwFilter<S, Mode: ProviderTypes>
where
Mode::Provider: crate::native::EventWriter<Mode> + 'static
{
pub(crate) provider: Pin<Arc<Mode::Provider>>,
pub(crate) default_keyword: u64,
pub(crate) _p: PhantomData<S>,
pub(crate) _m: PhantomData<Mode>,
}
20 changes: 15 additions & 5 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_imports)]

use tracing::{event, span, Level};
use tracing_etw::{etw_event, LayerBuilder};
use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};
Expand All @@ -8,11 +10,19 @@ use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};
// }

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("test").build()) // Collects everything
.with(LayerBuilder::new_common_schema_events("test2").build_with_target("geneva"))
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();
let registry = tracing_subscriber::registry();

#[cfg(not(feature = "global_filter"))]
let registry = registry.with(LayerBuilder::new("test").build().unwrap());
#[cfg(all(not(feature = "global_filter"), feature = "common_schema"))]
let registry = registry.with(LayerBuilder::new_common_schema_events("test2").build_with_target("geneva").unwrap());
#[cfg(not(feature = "global_filter"))]
let registry = registry.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE));

#[cfg(feature = "global_filter")]
let registry = registry.with(LayerBuilder::new("test").build_global_filter().unwrap());

registry.init();

#[allow(non_snake_case)]
let fieldB = "asdf";
Expand Down
13 changes: 13 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum EtwError {
#[error("Provider group GUID must not be zeros")]
EmptyProviderGroupGuid,
#[error("Provider group names must be lower case ASCII or numeric digits: {0:?}")]
InvalidProviderGroupCharacters(String),
#[error("Linux provider names must be ASCII alphanumeric: {0:?}")]
InvalidProviderNameCharacters(String),
#[error("Linux provider name and provider group must less than 234 characters combined. Current length: {0:?}")]
TooManyCharacters(usize)
}
Loading

0 comments on commit 8fe5a6e

Please sign in to comment.