Skip to main content

grow_zipkin/
lib.rs

1// Skeleton created by sdk-kit 0.1.0; owned by this repository (edit freely).
2//! # grow-zipkin
3//!
4//! Rust SDK for [Zipkin](https://grow-codes-packages.github.io/zipkin/) by Grow Codes.
5//!
6//! ```no_run
7//! # async fn demo() -> grow_zipkin::Result<()> {
8//! use grow_zipkin::tracing::{traced, TracingConfig};
9//! use grow_zipkin::{ZipkinClient, ZipkinConfig, ZipkinSpan, ZipkinKind};
10//!
11//! // Export OpenTelemetry spans to Zipkin (v2 JSON to /api/v2/spans, W3C + B3 propagation).
12//! let tracing = grow_zipkin::init_tracing(TracingConfig::new("checkout"))?;
13//! traced("charge-card", async { Ok::<_, std::io::Error>(()) }).await.ok();
14//! tracing.shutdown().await?;
15//!
16//! // Report spans without OpenTelemetry and read them back.
17//! let client = ZipkinClient::new(ZipkinConfig::from_env()?)?;
18//! let span = ZipkinSpan::new("5af7183fb1d4cf5f0a6665df1d0a9b8c", "0000000000000001")
19//!     .with_kind(ZipkinKind::Server)
20//!     .with_name("get /orders")
21//!     .with_local_service("checkout")
22//!     .with_timing(1_795_034_515_005_000, 1_000);
23//! client.reporter().report(&[span]).await?;
24//! let trace = client.query().get_trace("5af7183fb1d4cf5f0a6665df1d0a9b8c").await?;
25//! println!("{} spans", trace.map_or(0, |t| t.spans.len()));
26//! client.close().await;
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! Modules: [`ZipkinClient`] (health, ping, server version), [`ZipkinReporter`] (direct span
32//! reporting), [`ZipkinQueryClient`] (the v2 query API and the category `TraceQueryClient`),
33//! [`ZipkinSpanExporter`] (OpenTelemetry exporter, own implementation — the
34//! `opentelemetry-zipkin` crate is discontinued), [`init_tracing`] (the Zipkin preset) and the
35//! [`tracing`] category helpers.
36//!
37//! Features: `blocking` (a blocking client), `testing` (in-memory fakes and the conformance
38//! runner)
39//! , `tower` and `reqwest-middleware` (tracing instrumentation)
40//! .
41#![cfg_attr(docsrs, feature(doc_cfg))]
42
43pub mod core;
44
45mod client;
46mod config;
47mod exporter;
48mod model;
49mod query;
50mod reporter;
51mod setup;
52
53#[cfg(feature = "blocking")]
54#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
55pub mod blocking;
56
57#[cfg(feature = "testing")]
58#[cfg_attr(docsrs, doc(cfg(feature = "testing")))]
59pub mod testing;
60
61pub mod tracing;
62
63pub use crate::core::{Error, ErrorCode, HealthStatus, Result, RetryPolicy, Secret};
64
65pub use crate::config::{
66    base_from_endpoint, spans_endpoint, DEFAULT_URL, ENV_OTEL_ZIPKIN_ENDPOINT, ENV_ZIPKIN_URL,
67    SPANS_PATH,
68};
69
70pub use crate::client::{ZipkinClient, ZipkinServerInfo};
71
72pub use crate::model::{
73    annotation_to_event, dependencies_from_value, normalize_zipkin_span, strings_from_value,
74    summarize_zipkin_trace, tag_value, zipkin_span_to_span, zipkin_spans_from_value,
75    zipkin_trace_id, zipkin_trace_to_trace, zipkin_traces_from_value, ZipkinAnnotation,
76    ZipkinDependencyLink, ZipkinEndpoint, ZipkinKind, ZipkinSpan,
77};
78
79pub use crate::reporter::{ZipkinReporter, ZipkinReporterOptions, DEFAULT_MAX_BATCH_SIZE};
80
81pub use crate::query::{
82    build_annotation_query, ZipkinDependencyOptions, ZipkinQueryClient, ZipkinTraceQuery,
83    DEFAULT_SEARCH_LIMIT, DEFAULT_SEARCH_WINDOW, TRACE_MANY_CHUNK,
84};
85
86pub use crate::exporter::{
87    attribute_to_tag, to_zipkin_span, ExportErrorHandler, ZipkinSpanExporter,
88    ZipkinSpanExporterOptions, REMOTE_SERVICE_KEYS, UNKNOWN_SERVICE,
89};
90
91pub use crate::setup::{
92    default_propagators, init_tracing, init_tracing_with_options, order_propagators,
93    tracing_config_from_env, tracing_config_from_env_with, zipkin_exporter_factory, ZipkinExporter,
94    ZipkinTracingOptions, DEFAULT_TRACING_PROTOCOL,
95};
96
97pub use crate::config::ZipkinConfig;
98
99pub use crate::config::ZipkinConfigBuilder;
100
101/// Service-prefixed alias of [`Error`].
102pub type ZipkinError = Error;