diff --git a/.clippy.toml b/.clippy.toml index eeb746c..d5acd3f 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1,5 +1,6 @@ allowed-duplicate-crates = [ "base64", + "bitflags", "hashbrown", "indexmap", "regex-automata", diff --git a/crates/tracing-subscriber/Cargo.toml b/crates/tracing-subscriber/Cargo.toml index a0429c4..6356345 100644 --- a/crates/tracing-subscriber/Cargo.toml +++ b/crates/tracing-subscriber/Cargo.toml @@ -17,7 +17,7 @@ opentelemetry = { workspace = true } opentelemetry-otlp = { version = "0.16.0", features = ["grpc-tonic", "trace", "tls-roots"], optional = true } opentelemetry-proto = { version = "0.6.0", optional = true, features = ["tonic"] } opentelemetry-stdout = { version = "0.4.0", optional = true, features = ["trace"] } -opentelemetry_sdk = { workspace = true, features = ["rt-tokio-current-thread"] } +opentelemetry_sdk = { workspace = true, features = ["rt-tokio", "rt-tokio-current-thread"] } pyo3-asyncio = { workspace = true, features = ["tokio-runtime"] } serde = { workspace = true } thiserror = { workspace = true } diff --git a/crates/tracing-subscriber/src/contextmanager.rs b/crates/tracing-subscriber/src/contextmanager.rs index 1278a42..7784394 100644 --- a/crates/tracing-subscriber/src/contextmanager.rs +++ b/crates/tracing-subscriber/src/contextmanager.rs @@ -197,7 +197,7 @@ mod test { use crate::{ contextmanager::{CurrentThreadTracingConfig, GlobalTracingConfig, TracingConfig}, - export_process::{BatchConfig, ExportProcess, ExportProcessConfig, SimpleConfig}, + export_process::{ExportProcess, ExportProcessConfig, SimpleConfig}, subscriber::TracingSubscriberRegistryConfig, }; @@ -236,71 +236,6 @@ mod test { end_time_unix_nano: u128, } - #[test] - /// Test that a global batch process can be started and stopped and that it exports - /// accurate spans as configured. - fn test_global_batch() { - let temporary_file_path = get_tempfile("test_global_batch"); - let layer_config = Box::new(crate::layers::otel_otlp_file::Config { - file_path: Some(temporary_file_path.as_os_str().to_str().unwrap().to_owned()), - filter: Some("error,pyo3_tracing_subscriber=info".to_string()), - }); - let subscriber = Box::new(TracingSubscriberRegistryConfig { layer_config }); - let config = TracingConfig::Global(GlobalTracingConfig { - export_process: ExportProcessConfig::Batch(BatchConfig { - subscriber: crate::subscriber::PyConfig { - subscriber_config: subscriber, - }, - }), - }); - let export_process = ExportProcess::start(config).unwrap(); - let rt2 = Builder::new_current_thread().enable_time().build().unwrap(); - let _guard = rt2.enter(); - let export_runtime = rt2 - .block_on(tokio::time::timeout(Duration::from_secs(1), async move { - for _ in 0..N_SPANS { - example(); - } - export_process.shutdown().await - })) - .unwrap() - .unwrap() - .unwrap(); - drop(export_runtime); - - let reader = std::io::BufReader::new(std::fs::File::open(temporary_file_path).unwrap()); - let lines = reader.lines(); - let spans = lines - .flat_map(|line| { - let line = line.unwrap(); - let span_data: SpanData = serde_json::from_str(line.as_str()).unwrap(); - span_data - .resource_spans - .iter() - .flat_map(|resource_span| { - resource_span - .scope_spans - .iter() - .flat_map(|scope_span| scope_span.spans.clone()) - }) - .collect::>() - }) - .collect::>(); - assert_eq!(spans.len(), N_SPANS); - - let span_grace = Duration::from_millis(200); - for span in spans { - assert_eq!(span.name, "example"); - assert!( - span.end_time_unix_nano - span.start_time_unix_nano >= SPAN_DURATION.as_nanos() - ); - assert!( - (span.end_time_unix_nano - span.start_time_unix_nano) - <= (SPAN_DURATION.as_nanos() + span_grace.as_nanos()) - ); - } - } - #[test] /// Test that a global simple export process can be started and stopped and that it /// exports accurate spans as configured. @@ -352,7 +287,7 @@ mod test { .collect::>(); assert_eq!(spans.len(), N_SPANS); - let span_grace = Duration::from_millis(10); + let span_grace = Duration::from_millis(50); for span in spans { assert_eq!(span.name, "example"); assert!( diff --git a/crates/tracing-subscriber/src/layers/otel_otlp.rs b/crates/tracing-subscriber/src/layers/otel_otlp.rs index 6e52fa7..8c86483 100644 --- a/crates/tracing-subscriber/src/layers/otel_otlp.rs +++ b/crates/tracing-subscriber/src/layers/otel_otlp.rs @@ -16,7 +16,6 @@ use std::{collections::HashMap, time::Duration}; use opentelemetry_otlp::{TonicExporterBuilder, WithExportConfig}; use opentelemetry_sdk::{ - runtime::TokioCurrentThread, trace::{Sampler, SpanLimits}, Resource, }; @@ -103,7 +102,7 @@ impl Config { ); let tracer = if batch { - pipeline.install_batch(TokioCurrentThread {}) + pipeline.install_batch(opentelemetry_sdk::runtime::Tokio {}) } else { pipeline.install_simple() } diff --git a/crates/tracing-subscriber/src/layers/otel_otlp_file.rs b/crates/tracing-subscriber/src/layers/otel_otlp_file.rs index 7d0d412..8956e2e 100644 --- a/crates/tracing-subscriber/src/layers/otel_otlp_file.rs +++ b/crates/tracing-subscriber/src/layers/otel_otlp_file.rs @@ -13,7 +13,6 @@ // limitations under the License. use crate::create_init_submodule; -use opentelemetry_sdk::runtime::TokioCurrentThread; use pyo3::prelude::*; use tracing_subscriber::Layer; @@ -52,16 +51,13 @@ impl crate::layers::Config for Config { } None => exporter_builder, }; - let provider = if batch { - opentelemetry_sdk::trace::TracerProvider::builder() - .with_batch_exporter(exporter_builder.build(), TokioCurrentThread) - .build() - } else { - opentelemetry_sdk::trace::TracerProvider::builder() - .with_simple_exporter(exporter_builder.build()) - .build() - }; - let tracer = provider.tracer("pyo3-opentelemetry-stdout"); + if batch { + return Err(BuildError::BatchModeNotSupported)?; + } + let provider = opentelemetry_sdk::trace::TracerProvider::builder() + .with_simple_exporter(exporter_builder.build()) + .build(); + let tracer = provider.tracer("pyo3_tracing_subscriber"); let env_filter = build_env_filter(self.filter.clone())?; let layer = tracing_opentelemetry::layer() .with_tracer(tracer) @@ -77,6 +73,8 @@ impl crate::layers::Config for Config { pub(crate) enum BuildError { #[error("failed to initialize file span exporter for specified file path: {0}")] InvalidFile(#[from] std::io::Error), + #[error("batch mode is not supported for stdout layer")] + BatchModeNotSupported, } create_init_submodule! { diff --git a/examples/pyo3-opentelemetry-lib/Makefile.toml b/examples/pyo3-opentelemetry-lib/Makefile.toml index 09e6b39..93b4cf7 100644 --- a/examples/pyo3-opentelemetry-lib/Makefile.toml +++ b/examples/pyo3-opentelemetry-lib/Makefile.toml @@ -36,15 +36,14 @@ # separate process; that proved non-trivial on a first attempt, as the tests ran into sevaral unexpected # failures. - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export[2]' --with-global-tracing-configuration - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export[3]' --with-global-tracing-configuration - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export_async[0]' --with-global-tracing-configuration - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export_async[1]' --with-global-tracing-configuration - - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export[config2]' --with-global-tracing-configuration - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export[config3]' --with-global-tracing-configuration - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export_async[config0]' --with-global-tracing-configuration - poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export_async[config1]' --with-global-tracing-configuration + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export[02]' --with-global-tracing-configuration + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export[03]' --with-global-tracing-configuration + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_file_export_asynchronous[00]' --with-global-tracing-configuration + + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export[02]' --with-global-tracing-configuration + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export[03]' --with-global-tracing-configuration + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export_asynchronous[00]' --with-global-tracing-configuration + poetry run pytest 'pyo3_opentelemetry_lib/test/tracing_test.py::test_otlp_export_asynchronous[01]' --with-global-tracing-configuration ''' [tasks.python-check-all] diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/__init__.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/__init__.py index 0993fc1..5b14109 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/__init__.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/__init__.py @@ -12,6 +12,5 @@ from pyo3_opentelemetry_lib import _tracing_subscriber - __doc__ = _tracing_subscriber.__doc__ __all__ = getattr(_tracing_subscriber, "__all__", []) diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.py index a2c6030..a4dbb1c 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.py @@ -12,7 +12,5 @@ from pyo3_opentelemetry_lib._tracing_subscriber import layers - __doc__ = layers.__doc__ __all__ = getattr(layers, "__all__", []) - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.pyi b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.pyi index 741a427..50d94c1 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.pyi +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/__init__.pyi @@ -11,20 +11,21 @@ # ***************************************************************************** from __future__ import annotations + from typing import TYPE_CHECKING -from . import file as file -from . import otel_otlp_file as otel_otlp_file +from . import file as file from . import otel_otlp as otel_otlp +from . import otel_otlp_file as otel_otlp_file if TYPE_CHECKING: - from typing import Union + from typing import Union - Config = Union[ - file.Config, - otel_otlp_file.Config, - otel_otlp.Config, - ] - """ + Config = Union[ + file.Config, + otel_otlp_file.Config, + otel_otlp.Config, + ] + """ One of the supported layer configurations that may be set on the subscriber configuration. """ diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.py index 365f089..ea3053c 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.py @@ -12,8 +12,5 @@ from pyo3_opentelemetry_lib._tracing_subscriber.layers import file - __doc__ = file.__doc__ __all__ = getattr(file, "__all__", []) - - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.pyi b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.pyi index 7caa5c2..8054827 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.pyi +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/file/__init__.pyi @@ -39,4 +39,3 @@ class Config: :param json: Whether or not to format the output as JSON. Defaults to `True`. """ ... - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.py index cd94b23..efccc22 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.py @@ -12,7 +12,5 @@ from pyo3_opentelemetry_lib._tracing_subscriber.layers import otel_otlp - __doc__ = otel_otlp.__doc__ __all__ = getattr(otel_otlp, "__all__", []) - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.pyi b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.pyi index 5dde690..6accc02 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.pyi +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp/__init__.pyi @@ -11,7 +11,8 @@ # ***************************************************************************** from __future__ import annotations -from typing import Dict, Optional, TYPE_CHECKING, final + +from typing import TYPE_CHECKING, Dict, Optional, final @final class SpanLimits: @@ -47,8 +48,6 @@ class Resource: schema_url: Optional[str] = None, ) -> "Resource": ... - - @final class Config: """ @@ -98,14 +97,14 @@ class Config: ... if TYPE_CHECKING: - from typing import List, Union + from typing import List, Union ResourceValueArray = Union[List[bool], List[int], List[float], List[str]] """ An array of `ResourceValue`s. This array is homogenous, so all values must be of the same type. """ - ResourceValue= Union[bool, int, float, str, ResourceValueArray] + ResourceValue = Union[bool, int, float, str, ResourceValueArray] """ A value that can be added to a `Resource`. """ diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.py index db105d0..e28b7c3 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.py @@ -12,7 +12,5 @@ from pyo3_opentelemetry_lib._tracing_subscriber.layers import otel_otlp_file - __doc__ = otel_otlp_file.__doc__ __all__ = getattr(otel_otlp_file, "__all__", []) - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.pyi b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.pyi index 613126b..31e2f49 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.pyi +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/layers/otel_otlp_file/__init__.pyi @@ -32,4 +32,3 @@ class Config: and then `RUST_LOG` environment variable. If all of these values are empty, no spans will be exported. """ ... - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.py index 5737e29..64d80de 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.py @@ -12,7 +12,5 @@ from pyo3_opentelemetry_lib._tracing_subscriber import subscriber - __doc__ = subscriber.__doc__ __all__ = getattr(subscriber, "__all__", []) - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.pyi b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.pyi index 548de0c..e0894d0 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.pyi +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/_tracing_subscriber/subscriber/__init__.pyi @@ -22,4 +22,3 @@ class Config: """ def __new__(cls, *, layer: layers.Config) -> "Config": ... - diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/test/__artifacts__/.keep b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/test/__artifacts__/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/test/tracing_test.py b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/test/tracing_test.py index c717545..176137e 100644 --- a/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/test/tracing_test.py +++ b/examples/pyo3-opentelemetry-lib/pyo3_opentelemetry_lib/test/tracing_test.py @@ -44,38 +44,36 @@ def global_tracing(param: Any): return pytest.param(param, marks=pytest.mark.global_tracing_configuration) -@pytest.mark.parametrize( - "config_builder", - [ - lambda filename: CurrentThreadTracingConfig( +_TEST_FILE_EXPORT = [ + lambda filename: CurrentThreadTracingConfig( + export_process=SimpleConfig( + subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) + ) + ), + lambda filename: CurrentThreadTracingConfig( + export_process=BatchConfig( + subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) + ) + ), + global_tracing( + lambda filename: GlobalTracingConfig( export_process=SimpleConfig( subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) ) - ), - lambda filename: CurrentThreadTracingConfig( + ) + ), + global_tracing( + lambda filename: GlobalTracingConfig( export_process=BatchConfig( subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) ) - ), - global_tracing( - lambda filename: GlobalTracingConfig( - export_process=SimpleConfig( - subscriber=subscriber.Config( - layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename)) - ) - ) - ) - ), - global_tracing( - lambda filename: GlobalTracingConfig( - export_process=BatchConfig( - subscriber=subscriber.Config( - layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename)) - ) - ) - ) - ), - ], + ) + ), +] + + +@pytest.mark.parametrize( + "config_builder", _TEST_FILE_EXPORT, ids=[str(i).zfill(2) for i in range(len(_TEST_FILE_EXPORT))] ) async def test_file_export(config_builder: Callable[[str], TracingConfig], tracer: Tracer, file_export_filter: None): """ @@ -84,20 +82,24 @@ async def test_file_export(config_builder: Callable[[str], TracingConfig], trace await _test_file_export(config_builder, tracer) +_TEST_FILE_EXPORT_MULTI_THREADS = [ + lambda filename: CurrentThreadTracingConfig( + export_process=SimpleConfig( + subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) + ) + ), + lambda filename: CurrentThreadTracingConfig( + export_process=BatchConfig( + subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) + ) + ), +] + + @pytest.mark.parametrize( "config_builder", - [ - lambda filename: CurrentThreadTracingConfig( - export_process=SimpleConfig( - subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) - ) - ), - lambda filename: CurrentThreadTracingConfig( - export_process=BatchConfig( - subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) - ) - ), - ], + _TEST_FILE_EXPORT_MULTI_THREADS, + ids=[str(i).zfill(2) for i in range(len(_TEST_FILE_EXPORT_MULTI_THREADS))], ) async def test_file_export_multi_threads( config_builder: Callable[[str], TracingConfig], tracer: Tracer, file_export_filter: None @@ -149,30 +151,21 @@ async def _test_file_export(config_builder: Callable[[str], TracingConfig], trac assert counter["example_function_impl"] == 1 -@pytest.mark.parametrize( - "config_builder", - [ - global_tracing( - lambda filename: GlobalTracingConfig( - export_process=SimpleConfig( - subscriber=subscriber.Config( - layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename)) - ) - ) - ) - ), - global_tracing( - lambda filename: GlobalTracingConfig( - export_process=BatchConfig( - subscriber=subscriber.Config( - layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename)) - ) - ) +_TEST_FILE_EXPORT_ASYNC = [ + global_tracing( + lambda filename: GlobalTracingConfig( + export_process=SimpleConfig( + subscriber=subscriber.Config(layer=file.Config(file_path=os.path.join(_TEST_ARTIFACTS_DIR, filename))) ) - ), - ], + ) + ), +] + + +@pytest.mark.parametrize( + "config_builder", _TEST_FILE_EXPORT_ASYNC, ids=[str(i).zfill(2) for i in range(len(_TEST_FILE_EXPORT_ASYNC))] ) -async def test_file_export_async( +async def test_file_export_asynchronous( config_builder: Callable[[str], TracingConfig], tracer: Tracer, file_export_filter: None ): """ @@ -218,18 +211,18 @@ async def test_file_export_async( assert counter["example_function_impl_async"] == 1 +_TEST_OTLP_EXPORT = [ + CurrentThreadTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config()))), + CurrentThreadTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config()))), + global_tracing(GlobalTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config())))), + global_tracing(GlobalTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config())))), +] + + @pytest.mark.parametrize( "config", - [ - CurrentThreadTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config()))), - CurrentThreadTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config()))), - global_tracing( - GlobalTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config()))) - ), - global_tracing( - GlobalTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config()))) - ), - ], + _TEST_OTLP_EXPORT, + ids=[str(i).zfill(2) for i in range(len(_TEST_OTLP_EXPORT))], ) async def test_otlp_export( config: TracingConfig, @@ -267,12 +260,16 @@ async def test_otlp_export( assert counter["example_function_impl"] == 1 +_TEST_OTLP_EXPORT_MULTI_THREADS = [ + CurrentThreadTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config()))), + CurrentThreadTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config()))), +] + + @pytest.mark.parametrize( "config", - [ - CurrentThreadTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config()))), - CurrentThreadTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config()))), - ], + _TEST_OTLP_EXPORT_MULTI_THREADS, + ids=[str(i).zfill(2) for i in range(len(_TEST_OTLP_EXPORT_MULTI_THREADS))], ) async def test_otlp_export_multi_threads( config: TracingConfig, @@ -311,18 +308,18 @@ async def test_otlp_export_multi_threads( assert counter["example_function_impl"] == 1 +TEST_OTLP_EXPORT_ASYNC = [ + global_tracing(GlobalTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config())))), + global_tracing(GlobalTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config())))), +] + + @pytest.mark.parametrize( "config", - [ - global_tracing( - GlobalTracingConfig(export_process=SimpleConfig(subscriber=subscriber.Config(layer=otlp.Config()))) - ), - global_tracing( - GlobalTracingConfig(export_process=BatchConfig(subscriber=subscriber.Config(layer=otlp.Config()))) - ), - ], + TEST_OTLP_EXPORT_ASYNC, + ids=[str(i).zfill(2) for i in range(len(TEST_OTLP_EXPORT_ASYNC))], ) -async def test_otlp_export_async( +async def test_otlp_export_asynchronous( config: TracingConfig, tracer: Tracer, otlp_test_namespace: str,