1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
//! # OpenTelemetry OTLP Exporter
//!
//! The OTLP Exporter enables exporting telemetry data (logs, metrics, and traces) in the
//! OpenTelemetry Protocol (OTLP) format to compatible backends. These backends include:
//!
//! - OpenTelemetry Collector
//! - Open-source observability tools (Prometheus, Jaeger, etc.)
//! - Vendor-specific monitoring platforms
//!
//! This crate supports sending OTLP data via:
//! - gRPC
//! - HTTP (binary protobuf or JSON)
//!
//! ## Quickstart with OpenTelemetry Collector
//!
//! The examples below show traces, but the same pattern applies to metrics
//! ([`MetricExporter`]) and logs ([`LogExporter`]) — just swap the exporter
//! builder and the corresponding SDK provider.
//!
//! ### HTTP Transport (Port 4318)
//!
//! Run the OpenTelemetry Collector:
//!
//! ```shell
//! $ docker run -p 4318:4318 otel/opentelemetry-collector:latest
//! ```
//!
//! Configure your application to export traces via HTTP:
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "http-proto"))]
//! # {
//! use opentelemetry::global;
//! use opentelemetry::trace::Tracer;
//! use opentelemetry_otlp::Protocol;
//! use opentelemetry_otlp::WithExportConfig;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! // Initialize OTLP exporter using HTTP binary protocol
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_http()
//! .with_protocol(Protocol::HttpBinary)
//! .build()?;
//!
//! // Create a tracer provider with the exporter
//! let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
//! .with_batch_exporter(otlp_exporter)
//! .build();
//!
//! // Set it as the global provider
//! global::set_tracer_provider(tracer_provider);
//!
//! // Get a tracer and create spans
//! let tracer = global::tracer("my_tracer");
//! tracer.in_span("doing_work", |_cx| {
//! // Your application logic here...
//! });
//!
//! Ok(())
//! # }
//! }
//! ```
//!
//! ### gRPC Transport (Port 4317)
//!
//! Run the OpenTelemetry Collector:
//!
//! ```shell
//! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest
//! ```
//!
//! Configure your application to export traces via gRPC (the tonic client requires a Tokio runtime):
//!
//! - With `[tokio::main]`
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
//! # {
//! use opentelemetry::{global, trace::Tracer};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! // Initialize OTLP exporter using gRPC (Tonic)
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .build()?;
//!
//! // Create a tracer provider with the exporter
//! let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
//! .with_batch_exporter(otlp_exporter)
//! .build();
//!
//! // Set it as the global provider
//! global::set_tracer_provider(tracer_provider);
//!
//! // Get a tracer and create spans
//! let tracer = global::tracer("my_tracer");
//! tracer.in_span("doing_work", |_cx| {
//! // Your application logic here...
//! });
//!
//! Ok(())
//! # }
//! }
//! ```
//!
//! - Without `[tokio::main]`
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
//! # {
//! use opentelemetry::{global, trace::Tracer};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! // Initialize OTLP exporter using gRPC (Tonic)
//! let rt = tokio::runtime::Runtime::new()?;
//! let tracer_provider = rt.block_on(async {
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .build()
//! .expect("Failed to create span exporter");
//! opentelemetry_sdk::trace::SdkTracerProvider::builder()
//! .with_batch_exporter(exporter)
//! .build()
//! });
//!
//! // Set it as the global provider
//! global::set_tracer_provider(tracer_provider);
//!
//! // Get a tracer and create spans
//! let tracer = global::tracer("my_tracer");
//! tracer.in_span("doing_work", |_cx| {
//! // Your application logic here...
//! });
//!
//! // Ensure the runtime (`rt`) remains active until the program ends
//! Ok(())
//! # }
//! }
//! ```
//!
//! ## Using with Jaeger
//!
//! Jaeger natively supports the OTLP protocol, making it easy to send traces directly:
//!
//! ```shell
//! $ docker run -p 16686:16686 -p 4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest
//! ```
//!
//! After running your application configured with the OTLP exporter, view traces at:
//! `http://localhost:16686`
//!
//! ## Using with Prometheus
//!
//! Prometheus natively supports accepting metrics via the OTLP protocol
//! (HTTP/protobuf). You can [run
//! Prometheus](https://prometheus.io/docs/prometheus/latest/installation/) with
//! the following command:
//!
//! ```shell
//! docker run -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-otlp-receiver
//! ```
//!
//! (An empty prometheus.yml file is sufficient for this example.)
//!
//! Modify your application to export metrics via OTLP:
//!
//! ```no_run
//! # #[cfg(all(feature = "metrics", feature = "http-proto"))]
//! # {
//! use opentelemetry::global;
//! use opentelemetry::metrics::Meter;
//! use opentelemetry::KeyValue;
//! use opentelemetry_otlp::Protocol;
//! use opentelemetry_otlp::WithExportConfig;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! // Initialize OTLP exporter using HTTP binary protocol
//! let exporter = opentelemetry_otlp::MetricExporter::builder()
//! .with_http()
//! .with_protocol(Protocol::HttpBinary)
//! .with_endpoint("http://localhost:9090/api/v1/otlp/v1/metrics")
//! .build()?;
//!
//! // Create a meter provider with the OTLP Metric exporter
//! let meter_provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder()
//! .with_periodic_exporter(exporter)
//! .build();
//! global::set_meter_provider(meter_provider.clone());
//!
//! // Get a meter
//! let meter = global::meter("my_meter");
//!
//! // Create a metric
//! let counter = meter.u64_counter("my_counter").build();
//! counter.add(1, &[KeyValue::new("key", "value")]);
//!
//! // Shutdown the meter provider. This will trigger an export of all metrics.
//! meter_provider.shutdown()?;
//!
//! Ok(())
//! # }
//! }
//! ```
//!
//! After running your application configured with the OTLP exporter, view metrics at:
//! `http://localhost:9090`
//!
//! # Environment Variables
//!
//! The OTLP exporter respects the following environment variables, as defined by the
//! [OpenTelemetry specification]. Programmatic configuration via builder methods
//! takes precedence over environment variables. Signal-specific variables take
//! precedence over the generic `OTEL_EXPORTER_OTLP_*` variables.
//!
//! [OpenTelemetry specification]: https://opentelemetry.io/docs/specs/otel/protocol/exporter/
//!
//! ## General (all signals)
//!
//! | Variable | Description | Default |
//! |---|---|---|
//! | `OTEL_EXPORTER_OTLP_ENDPOINT` | Target URL for the exporter. For HTTP, signal paths (`/v1/traces`, `/v1/metrics`, `/v1/logs`) are appended automatically. | `http://localhost:4318` (HTTP), `http://localhost:4317` (gRPC) |
//! | `OTEL_EXPORTER_OTLP_PROTOCOL` | Transport protocol. Valid values: `grpc`, `http/protobuf`, `http/json`. Requires the corresponding crate feature. | Feature-dependent |
//! | `OTEL_EXPORTER_OTLP_TIMEOUT` | Maximum wait time (in milliseconds) for the backend to process each batch. | `10000` |
//! | `OTEL_EXPORTER_OTLP_HEADERS` | Key-value pairs for request headers. Format: `key1=value1,key2=value2`. Values are URL-decoded. | (none) |
//! | `OTEL_EXPORTER_OTLP_COMPRESSION` | Compression algorithm. Valid values: `gzip`, `zstd`. | (none) |
//!
//! ## Traces
//!
//! | Variable | Description |
//! |---|---|
//! | `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | Signal-specific endpoint for trace exports. |
//! | `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` | Signal-specific protocol for trace exports. Valid values: `grpc`, `http/protobuf`, `http/json`. |
//! | `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` | Signal-specific timeout (in milliseconds) for trace exports. |
//! | `OTEL_EXPORTER_OTLP_TRACES_HEADERS` | Signal-specific headers for trace exports. |
//! | `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` | Signal-specific compression for trace exports. |
//!
//! ## Metrics
//!
//! | Variable | Description |
//! |---|---|
//! | `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` | Signal-specific endpoint for metrics exports. |
//! | `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL` | Signal-specific protocol for metrics exports. Valid values: `grpc`, `http/protobuf`, `http/json`. |
//! | `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT` | Signal-specific timeout (in milliseconds) for metrics exports. |
//! | `OTEL_EXPORTER_OTLP_METRICS_HEADERS` | Signal-specific headers for metrics exports. |
//! | `OTEL_EXPORTER_OTLP_METRICS_COMPRESSION` | Signal-specific compression for metrics exports. |
//! | `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` | Temporality preference for metrics. Valid values: `cumulative`, `delta`, `lowmemory` (case-insensitive). | `cumulative` |
//!
//! ## Logs
//!
//! | Variable | Description |
//! |---|---|
//! | `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Signal-specific endpoint for log exports. |
//! | `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL` | Signal-specific protocol for log exports. Valid values: `grpc`, `http/protobuf`, `http/json`. |
//! | `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` | Signal-specific timeout (in milliseconds) for log exports. |
//! | `OTEL_EXPORTER_OTLP_LOGS_HEADERS` | Signal-specific headers for log exports. |
//! | `OTEL_EXPORTER_OTLP_LOGS_COMPRESSION` | Signal-specific compression for log exports. |
//!
//! # Feature Flags
//! The following feature flags can enable exporters for different telemetry signals:
//!
//! * `trace`: Includes the trace exporters.
//! * `metrics`: Includes the metrics exporters.
//! * `logs`: Includes the logs exporters.
//!
//! The following feature flags generate additional code and types:
//! * `serialize`: Enables serialization support for type defined in this crate via `serde`.
//!
//! The following feature flags offer additional configurations on gRPC:
//!
//! For users using `tonic` as grpc layer:
//! * `grpc-tonic`: Use `tonic` as grpc layer.
//! * `gzip-tonic`: Use gzip compression for `tonic` grpc layer.
//! * `zstd-tonic`: Use zstd compression for `tonic` grpc layer.
//! * `tls-ring`: Enable rustls TLS support using ring for `tonic`.
//! * `tls-aws-lc`: Enable rustls TLS support using aws-lc for `tonic`.
//! * `tls-provider-agnostic`: Provider-agnostic TLS — enables TLS code paths without bundling a specific
//! crypto provider. Use this when you install a `CryptoProvider` globally
//! (e.g., via `rustls-openssl` for FIPS/OpenSSL environments).
//! * `tls` (deprecated): Use `tls-ring` or `tls-aws-lc` instead.
//! * `tls-roots`: Adds system trust roots to rustls-based gRPC clients using the rustls-native-certs crate (use with `tls-ring` or `tls-aws-lc`).
//! * `tls-webpki-roots`: Embeds Mozilla's trust roots to rustls-based gRPC clients using the webpki-roots crate (use with `tls-ring` or `tls-aws-lc`).
//!
//! The following feature flags offer additional configurations on http:
//!
//! * `http-proto`: Use http as transport layer, protobuf as body format. This feature is enabled by default.
//! * `gzip-http`: Use gzip compression for HTTP transport.
//! * `zstd-http`: Use zstd compression for HTTP transport.
//! * `reqwest-blocking-client`: Use reqwest blocking http client. This feature is enabled by default.
//! * `reqwest-client`: Use reqwest http client.
//! * `reqwest-rustls`: Use reqwest with TLS with system trust roots via `rustls-native-certs` crate.
//! * `reqwest-rustls-webpki-roots`: Use reqwest with TLS with Mozilla's trust roots via `webpki-roots` crate.
//!
//! The following feature flags enable experimental retry support:
//!
//! * `experimental-grpc-retry`: Enable automatic retry with exponential backoff for gRPC exports.
//! Requires a Tokio runtime (`rt-tokio` SDK feature is enabled transitively).
//! * `experimental-http-retry`: Enable automatic retry with exponential backoff for HTTP exports.
//! Requires a Tokio runtime (`rt-tokio` SDK feature is enabled transitively).
//!
//! # Full Configuration Reference
//!
//!
//! There are two layers of configuration for the OTLP exporter:
//!
//! 1. **Exporter configuration** – controls how telemetry is sent (endpoint, transport, headers, TLS, compression, timeout).
//! Built via the signal-specific builder: [`SpanExporter::builder()`], [`MetricExporter::builder()`], [`LogExporter::builder()`].
//! 2. **Provider/SDK configuration** – controls how telemetry is collected and batched (sampling, batch size, resource, etc.).
//! Built via [`opentelemetry_sdk::trace::SdkTracerProvider::builder()`],
//! [`opentelemetry_sdk::metrics::SdkMeterProvider::builder()`], or
//! [`opentelemetry_sdk::logs::SdkLoggerProvider::builder()`].
//!
//! **Configuration precedence** (highest wins):
//! 1. Programmatic configuration via builder methods — always wins when set
//! 2. Signal-specific environment variables (e.g. `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`) — used when no programmatic value is set
//! 3. Generic environment variables (e.g. `OTEL_EXPORTER_OTLP_ENDPOINT`) — used when neither programmatic nor signal-specific env var is set
//! 4. Built-in defaults — used when nothing else is configured
//!
//! ## gRPC (tonic) — all configuration options
//!
//! Requires the `grpc-tonic` feature. The methods below come from two traits:
//! - [`WithExportConfig`]: `with_endpoint`, `with_timeout` (shared with HTTP)
//! - [`WithTonicConfig`]: `with_metadata`, `with_compression`, `with_tls_config`, `with_channel`, `with_interceptor`
//!
//! The examples here use [`SpanExporter`], but the same builder methods are
//! available on [`MetricExporter`] and [`LogExporter`].
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
//! # {
//! use opentelemetry_otlp::{WithExportConfig, WithTonicConfig, Compression};
//! use std::time::Duration;
//! use tonic::metadata::MetadataMap;
//!
//! // ── gRPC metadata (custom request headers) ───────────────────────────────
//! // MetadataMap carries per-call key/value pairs sent as HTTP/2 headers.
//! // with_metadata() is additive: calling it multiple times merges entries.
//! let mut metadata = MetadataMap::with_capacity(3);
//! metadata.insert("x-host", "example.com".parse().unwrap());
//! metadata.insert("x-api-key", "secret".parse().unwrap());
//! metadata.insert_bin("trace-proto-bin", tonic::metadata::MetadataValue::from_bytes(b"[bin]"));
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! // Target gRPC endpoint. Defaults to http://localhost:4317.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (or OTEL_EXPORTER_OTLP_ENDPOINT).
//! .with_endpoint("http://my-collector:4317")
//! // Per-export timeout. Defaults to 10 s.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT (or OTEL_EXPORTER_OTLP_TIMEOUT).
//! .with_timeout(Duration::from_secs(5))
//! // Custom gRPC metadata (auth tokens, routing headers, …).
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_HEADERS (or OTEL_EXPORTER_OTLP_HEADERS).
//! .with_metadata(metadata)
//! // Compression. Requires the `gzip-tonic` or `zstd-tonic` feature.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_COMPRESSION (or OTEL_EXPORTER_OTLP_COMPRESSION).
//! .with_compression(Compression::Gzip)
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ### TLS (grpc-tonic)
//!
//! Requires the `tls-ring` or `tls-aws-lc` feature (plus optionally `tls-roots` or `tls-webpki-roots`
//! to load CA roots automatically).
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic", any(feature = "tls-ring", feature = "tls-aws-lc")))]
//! # {
//! use opentelemetry_otlp::{WithExportConfig, WithTonicConfig};
//! use opentelemetry_otlp::tonic_types::transport::ClientTlsConfig;
//!
//! let tls = ClientTlsConfig::new()
//! .domain_name("my-collector.example.com")
//! // Optionally verify the server with a CA certificate:
//! // .ca_certificate(tonic::transport::Certificate::from_pem(CA_PEM))
//! // Or present a client identity for mutual TLS (mTLS):
//! // .identity(tonic::transport::Identity::from_pem(CERT_PEM, KEY_PEM))
//! ;
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .with_endpoint("https://my-collector.example.com:4317")
//! .with_tls_config(tls)
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ### Pre-built tonic channel
//!
//! Use `with_channel` when you need full control over the transport (e.g. Unix sockets,
//! custom load-balancing). **Note:** `with_channel` overrides any TLS config set via
//! `with_tls_config`, and you are responsible for matching the channel timeout to
//! the exporter timeout.
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
//! # {
//! use opentelemetry_otlp::{WithExportConfig, WithTonicConfig};
//! use std::time::Duration;
//!
//! let channel = tonic::transport::Channel::from_static("http://localhost:4317")
//! .timeout(Duration::from_secs(5))
//! .connect_lazy();
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .with_channel(channel)
//! .with_timeout(Duration::from_secs(5)) // keep in sync with channel timeout above
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ### gRPC interceptors
//!
//! Use `with_interceptor` to modify every outbound gRPC request — useful for injecting
//! auth tokens or dynamic metadata. Only one interceptor can be set; chain multiple together
//! before passing them in.
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
//! # {
//! use opentelemetry_otlp::WithTonicConfig;
//! use tonic::{Request, Status};
//!
//! fn auth_interceptor(mut req: Request<()>) -> Result<Request<()>, Status> {
//! req.metadata_mut().insert("authorization", "Bearer my-token".parse().unwrap());
//! Ok(req)
//! }
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .with_interceptor(auth_interceptor)
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ### gRPC retry policy
//!
//! Requires the `experimental-grpc-retry` feature. When enabled, failed exports are retried
//! with exponential backoff and jitter. Without this feature, failed exports are not retried.
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "experimental-grpc-retry"))]
//! # {
//! use opentelemetry_otlp::{WithTonicConfig, RetryPolicy};
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .with_retry_policy(RetryPolicy {
//! max_retries: 5, // number of attempts after the first failure
//! initial_delay_ms: 500, // delay before the first retry
//! max_delay_ms: 30_000, // cap on the delay between retries
//! jitter_ms: 100, // upper bound for random jitter added by the exporter
//! })
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ## HTTP — all configuration options
//!
//! Requires the `http-proto` (default) or `http-json` feature. The methods below come from:
//! - [`WithExportConfig`]: `with_endpoint`, `with_timeout`, `with_protocol`
//! - [`WithHttpConfig`]: `with_headers`, `with_compression`, `with_http_client`
//!
//! The examples here use [`SpanExporter`], but the same builder methods are
//! available on [`MetricExporter`] and [`LogExporter`].
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "http-proto"))]
//! # {
//! use opentelemetry_otlp::{WithExportConfig, WithHttpConfig, Protocol, Compression};
//! use std::time::Duration;
//! use std::collections::HashMap;
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_http()
//! // Target base URL. Defaults to http://localhost:4318.
//! // The path /v1/traces (or /v1/metrics, /v1/logs) is appended automatically.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (or OTEL_EXPORTER_OTLP_ENDPOINT).
//! .with_endpoint("http://my-collector:4318")
//! // Per-export timeout. Defaults to 10 s.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT (or OTEL_EXPORTER_OTLP_TIMEOUT).
//! .with_timeout(Duration::from_secs(5))
//! // Transport encoding. HttpBinary (protobuf) is the default.
//! // HttpJson requires the `http-json` feature.
//! // Env var: OTEL_EXPORTER_OTLP_PROTOCOL.
//! .with_protocol(Protocol::HttpBinary)
//! // Custom HTTP headers (auth tokens, routing headers, …).
//! // Values are URL-decoded when read from environment variables.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_HEADERS (or OTEL_EXPORTER_OTLP_HEADERS).
//! .with_headers(HashMap::from([
//! ("x-api-key".to_string(), "secret".to_string()),
//! ]))
//! // Compression. Requires the `gzip-http` or `zstd-http` feature.
//! // Env var: OTEL_EXPORTER_OTLP_TRACES_COMPRESSION (or OTEL_EXPORTER_OTLP_COMPRESSION).
//! .with_compression(Compression::Gzip)
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ### Custom HTTP client
//!
//! By default the exporter uses a `reqwest` blocking client (`reqwest-blocking-client` feature,
//! enabled by default). Supply your own client to control TLS, proxies, connection pooling, etc.
//! The client must implement the [`opentelemetry_http::HttpClient`] trait.
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "http-proto", feature = "reqwest-client"))]
//! # {
//! use opentelemetry_otlp::WithHttpConfig;
//!
//! // reqwest async client (requires the `reqwest-client` feature)
//! let http_client = reqwest::Client::builder()
//! .timeout(std::time::Duration::from_secs(5))
//! // .danger_accept_invalid_certs(true) // for testing only
//! .build()
//! .expect("Failed to build reqwest client");
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_http()
//! .with_http_client(http_client)
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ### HTTP retry policy
//!
//! Requires the `experimental-http-retry` feature. When enabled, failed exports are retried
//! with exponential backoff and jitter. Without this feature, failed exports are not retried.
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "experimental-http-retry"))]
//! # {
//! use opentelemetry_otlp::{WithHttpConfig, RetryPolicy};
//!
//! let exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_http()
//! .with_retry_policy(RetryPolicy {
//! max_retries: 5, // number of attempts after the first failure
//! initial_delay_ms: 500, // delay before the first retry
//! max_delay_ms: 30_000, // cap on the delay between retries
//! jitter_ms: 100, // upper bound for random jitter added by the exporter
//! })
//! .build()
//! .expect("Failed to build SpanExporter");
//! # }
//! ```
//!
//! ## All three signals (Traces, Metrics, Logs)
//!
//! The same exporter configuration options apply to all three signals. The only differences are:
//! - The builder entry point: [`SpanExporter::builder()`], [`MetricExporter::builder()`], [`LogExporter::builder()`]
//! - The signal-specific environment variables (e.g. `OTEL_EXPORTER_OTLP_TRACES_*` vs `OTEL_EXPORTER_OTLP_METRICS_*`)
//! - Metrics has an additional `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` variable
//!
//! ```no_run
//! # #[cfg(all(feature = "trace", feature = "metrics", feature = "logs", feature = "grpc-tonic"))]
//! # {
//! use opentelemetry_otlp::{WithExportConfig, WithTonicConfig};
//! use opentelemetry_sdk::{
//! trace::SdkTracerProvider,
//! metrics::SdkMeterProvider,
//! logs::SdkLoggerProvider,
//! Resource,
//! };
//! use std::time::Duration;
//!
//! let resource = Resource::builder()
//! .with_service_name("my-service")
//! .build();
//!
//! // Traces
//! let span_exporter = opentelemetry_otlp::SpanExporter::builder()
//! .with_tonic()
//! .with_endpoint("http://my-collector:4317")
//! .with_timeout(Duration::from_secs(5))
//! .build()
//! .expect("Failed to build SpanExporter");
//! let tracer_provider = SdkTracerProvider::builder()
//! .with_resource(resource.clone())
//! .with_batch_exporter(span_exporter)
//! .build();
//!
//! // Metrics
//! let metric_exporter = opentelemetry_otlp::MetricExporter::builder()
//! .with_tonic()
//! .with_endpoint("http://my-collector:4317")
//! .with_timeout(Duration::from_secs(5))
//! .build()
//! .expect("Failed to build MetricExporter");
//! let meter_provider = SdkMeterProvider::builder()
//! .with_resource(resource.clone())
//! .with_periodic_exporter(metric_exporter)
//! .build();
//!
//! // Logs
//! let log_exporter = opentelemetry_otlp::LogExporter::builder()
//! .with_tonic()
//! .with_endpoint("http://my-collector:4317")
//! .with_timeout(Duration::from_secs(5))
//! .build()
//! .expect("Failed to build LogExporter");
//! let logger_provider = SdkLoggerProvider::builder()
//! .with_resource(resource)
//! .with_batch_exporter(log_exporter)
//! .build();
//! # }
//! ```
/// Retry logic for exporting telemetry data.
pub use crateCompression;
pub use crateExporterBuildError;
pub use crate;
pub use crate;
pub use crate;
pub use crateWithHttpConfig;
pub use crateWithTonicConfig;
pub use crate;
pub use RetryPolicy;
/// Type to indicate the builder does not have a client set.
;
/// Type to hold the [TonicExporterBuilder] and indicate it has been set.
///
/// Allowing access to [TonicExporterBuilder] specific configuration methods.
// This is for clippy to work with only the grpc-tonic feature enabled
;
/// Type to hold the [HttpExporterBuilder] and indicate it has been set.
///
/// Allowing access to [HttpExporterBuilder] specific configuration methods.
;
pub use crateHttpExporterBuilder;
pub use crateTonicExporterBuilder;
use ;
/// The communication protocol to use when exporting data.
/// Placeholder type when no exporter pipeline has been configured in telemetry pipeline.
);
/// Re-exported types from the `tonic` crate.