|
4 | 4 |
|
5 | 5 | use std::fmt::Debug; |
6 | 6 |
|
7 | | -use futures_core::future::BoxFuture; |
8 | 7 | use opentelemetry_sdk::error::OTelSdkResult; |
9 | 8 | use opentelemetry_sdk::trace::SpanData; |
10 | 9 |
|
@@ -66,15 +65,15 @@ impl SpanExporterBuilder<TonicExporterBuilderSet> { |
66 | 65 | pub fn build(self) -> Result<SpanExporter, opentelemetry::trace::TraceError> { |
67 | 66 | let span_exporter = self.client.0.build_span_exporter()?; |
68 | 67 | opentelemetry::otel_debug!(name: "SpanExporterBuilt"); |
69 | | - Ok(SpanExporter::new(span_exporter)) |
| 68 | + Ok(span_exporter) |
70 | 69 | } |
71 | 70 | } |
72 | 71 |
|
73 | 72 | #[cfg(any(feature = "http-proto", feature = "http-json"))] |
74 | 73 | impl SpanExporterBuilder<HttpExporterBuilderSet> { |
75 | 74 | pub fn build(self) -> Result<SpanExporter, opentelemetry::trace::TraceError> { |
76 | 75 | let span_exporter = self.client.0.build_span_exporter()?; |
77 | | - Ok(SpanExporter::new(span_exporter)) |
| 76 | + Ok(span_exporter) |
78 | 77 | } |
79 | 78 | } |
80 | 79 |
|
@@ -106,28 +105,57 @@ impl HasHttpConfig for SpanExporterBuilder<HttpExporterBuilderSet> { |
106 | 105 | } |
107 | 106 | } |
108 | 107 |
|
109 | | -/// OTLP exporter that sends tracing information |
| 108 | +/// OTLP exporter that sends tracing data |
110 | 109 | #[derive(Debug)] |
111 | | -pub struct SpanExporter(Box<dyn opentelemetry_sdk::trace::SpanExporter>); |
| 110 | +pub struct SpanExporter { |
| 111 | + client: SupportedTransportClient, |
| 112 | +} |
| 113 | + |
| 114 | +#[derive(Debug)] |
| 115 | +enum SupportedTransportClient { |
| 116 | + #[cfg(feature = "grpc-tonic")] |
| 117 | + Tonic(crate::exporter::tonic::trace::TonicTracesClient), |
| 118 | + #[cfg(any(feature = "http-proto", feature = "http-json"))] |
| 119 | + Http(crate::exporter::http::OtlpHttpClient), |
| 120 | +} |
112 | 121 |
|
113 | 122 | impl SpanExporter { |
114 | 123 | /// Obtain a builder to configure a [SpanExporter]. |
115 | 124 | pub fn builder() -> SpanExporterBuilder<NoExporterBuilderSet> { |
116 | 125 | SpanExporterBuilder::default() |
117 | 126 | } |
118 | 127 |
|
119 | | - /// Build a new span exporter from a client |
120 | | - pub fn new(client: impl opentelemetry_sdk::trace::SpanExporter + 'static) -> Self { |
121 | | - SpanExporter(Box::new(client)) |
| 128 | + #[cfg(any(feature = "http-proto", feature = "http-json"))] |
| 129 | + pub(crate) fn from_http(client: crate::exporter::http::OtlpHttpClient) -> Self { |
| 130 | + SpanExporter { |
| 131 | + client: SupportedTransportClient::Http(client), |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + #[cfg(feature = "grpc-tonic")] |
| 136 | + pub(crate) fn from_tonic(client: crate::exporter::tonic::trace::TonicTracesClient) -> Self { |
| 137 | + SpanExporter { |
| 138 | + client: SupportedTransportClient::Tonic(client), |
| 139 | + } |
122 | 140 | } |
123 | 141 | } |
124 | 142 |
|
125 | 143 | impl opentelemetry_sdk::trace::SpanExporter for SpanExporter { |
126 | | - fn export(&mut self, batch: Vec<SpanData>) -> BoxFuture<'static, OTelSdkResult> { |
127 | | - self.0.export(batch) |
| 144 | + async fn export(&mut self, batch: Vec<SpanData>) -> OTelSdkResult { |
| 145 | + match &mut self.client { |
| 146 | + #[cfg(feature = "grpc-tonic")] |
| 147 | + SupportedTransportClient::Tonic(client) => client.export(batch).await, |
| 148 | + #[cfg(any(feature = "http-proto", feature = "http-json"))] |
| 149 | + SupportedTransportClient::Http(client) => client.export(batch).await, |
| 150 | + } |
128 | 151 | } |
129 | 152 |
|
130 | 153 | fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) { |
131 | | - self.0.set_resource(resource); |
| 154 | + match &mut self.client { |
| 155 | + #[cfg(feature = "grpc-tonic")] |
| 156 | + SupportedTransportClient::Tonic(client) => client.set_resource(resource), |
| 157 | + #[cfg(any(feature = "http-proto", feature = "http-json"))] |
| 158 | + SupportedTransportClient::Http(client) => client.set_resource(resource), |
| 159 | + } |
132 | 160 | } |
133 | 161 | } |
0 commit comments