|
| 1 | +# Migration guide from 0.27 to 0.28 |
| 2 | + |
| 3 | +OpenTelemetry Rust 0.28 introduces a large number of breaking changes that |
| 4 | +impact all signals (logs/metrics/traces). This guide is intended to help with a |
| 5 | +smooth migration for the common use cases of using `opentelemetry`, |
| 6 | +`opentelemetry_sdk` `opentelemetry-otlp`, `opentelemetry-appender-tracing` |
| 7 | +crates. The detailed changelog for each crate that you use can be consulted for |
| 8 | +the full set of changes. This doc covers only the common scenario. |
| 9 | + |
| 10 | +## Tracing Shutdown changes |
| 11 | + |
| 12 | +`opentelemetry::global::shutdown_tracer_provider()` is removed. Now, you should |
| 13 | +explicitly call shutdown() on the created tracer provider. |
| 14 | + |
| 15 | +Before (0.27): |
| 16 | + |
| 17 | +```rust |
| 18 | +opentelemetry::global::shutdown_tracer_provider(); |
| 19 | +``` |
| 20 | + |
| 21 | + After (0.28): |
| 22 | + |
| 23 | +```rust |
| 24 | +let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() |
| 25 | + .build(); |
| 26 | + |
| 27 | +// Clone and set the tracer provider globally. Retain the original to invoke shutdown later. |
| 28 | +opentelemetry::global::set_tracer_provider(tracer_provider.clone()); |
| 29 | + |
| 30 | +// Shutdown the provider when application is exiting. |
| 31 | +tracer_provider.shutdown(); |
| 32 | +``` |
| 33 | + |
| 34 | +This now makes shutdown consistent across signals. |
| 35 | + |
| 36 | +## Rename SDK Structs |
| 37 | + |
| 38 | +`LoggerProvider`, `TracerProvider` are renamed to `SdkLoggerProvider` and |
| 39 | +`SdkTracerProvider` respectively. `MeterProvider` was already named |
| 40 | +`SdkMeterProvider` and this now ensures consistency across signals. |
| 41 | + |
| 42 | +### Async Runtime Requirements removed |
| 43 | + |
| 44 | +When using OTLP Exporter for Logs, Traces a "batching" exporter is recommended. |
| 45 | +Also, metrics always required a component named `PeriodicReader`. These |
| 46 | +components previously needed user to pass in an async runtime and enable |
| 47 | +appropriate feature flag depending on the runtime. |
| 48 | + |
| 49 | +These components have been re-written to no longer require an async runtime. |
| 50 | +Instead they operate by spawning dedicated background thread, and making |
| 51 | +blocking calls from the same. |
| 52 | + |
| 53 | +PeriodicReader, BatchSpanProcessor, BatchLogProcessor are the components |
| 54 | +affected. |
| 55 | + |
| 56 | +For Logs,Traces replace `.with_batch_exporter(exporter, runtime::Tokio)` with |
| 57 | +`.with_batch_exporter(exporter)`. |
| 58 | + |
| 59 | +For Metrics, replace `let reader = |
| 60 | +PeriodicReader::builder(exporter, runtime::Tokio).build();` with `let reader = |
| 61 | +PeriodicReader::builder(exporter).build();` or more conveniently, |
| 62 | +`.with_periodic_exporter(exporter)`. |
| 63 | + |
| 64 | +Please note the following: |
| 65 | + |
| 66 | +* With the new approach, only the following grpc/http clients are supported in |
| 67 | + `opentelemetry-otlp`. |
| 68 | + |
| 69 | + `grpc-tonic` (OTLP |
| 70 | + Exporter must be created from within a Tokio runtime) |
| 71 | + |
| 72 | + `reqwest-blocking-client` |
| 73 | + |
| 74 | + In other words, |
| 75 | + `reqwest` and `hyper` are not supported. |
| 76 | + If using exporters other than `opentelemetry-otlp`, consult the docs |
| 77 | + for the same to know if there are any restrictions/requirements on async |
| 78 | + runtime. |
| 79 | + |
| 80 | +* Timeout enforcement is now moved to Exporters. i.e |
| 81 | +BatchProcessor,PeriodicReader does not enforce timeouts. For logs and traces, |
| 82 | +`max_export_timeout` (on Processors) or `OTEL_BLRP_EXPORT_TIMEOUT` or |
| 83 | +`OTEL_BSP_EXPORT_TIMEOUT` is no longer supported. For metrics, `with_timeout` on |
| 84 | +PeriodicReader is no longer supported. |
| 85 | + |
| 86 | + `OTEL_EXPORTER_OTLP_TIMEOUT` can be used to setup timeout for OTLP Exporters |
| 87 | + via environment variables, or `.with_tonic().with_timeout()` or |
| 88 | + `.with_http().with_timeout()` programmatically. |
| 89 | + |
| 90 | +* If you need the old behavior (your application cannot spawn a new thread, or |
| 91 | +need to use another networking client etc.) use appropriate feature flag(s) from |
| 92 | + below. |
| 93 | + “experimental_metrics_periodicreader_with_async_runtime” |
| 94 | + "experimental_logs_batch_log_processor_with_async_runtime" |
| 95 | + "experimental_trace_batch_span_processor_with_async_runtime" |
| 96 | + |
| 97 | + **and** adjust the namespace: |
| 98 | + |
| 99 | + Example, when using Tokio runtime. |
| 100 | + |
| 101 | + ```rust |
| 102 | +let reader = opentelemetry_sdk::metrics::periodic_reader_with_async_runtime::PeriodicReader::builder(exporter, runtime::Tokio).build(); |
| 103 | +let tracer_provider = SdkTracerProvider::builder() |
| 104 | + .with_span_processor(span_processor_with_async_runtime::BatchSpanProcessor::builder(exporter, runtime::Tokio).build()) |
| 105 | + .build(); |
| 106 | +let logger_provider = SdkLoggerProvider::builder() |
| 107 | +.with_log_processor(log_processor_with_async_runtime::BatchLogProcessor::builder(exporter, runtime::Tokio).build()) |
| 108 | +.build(); |
| 109 | +``` |
| 110 | + |
| 111 | +## OTLP Default change |
| 112 | + |
| 113 | +"grpc-tonic" feature flag is no longer enabled by default in |
| 114 | +`opentelemetry-otlp`. "http-proto" and "reqwest-blocking-client" features are |
| 115 | +added as default, to align with the OTel specification. |
| 116 | + |
| 117 | +## Resource Changes |
| 118 | + |
| 119 | +`Resource` creation is moved to a builder pattern, and `Resource::{new, empty, |
| 120 | +from_detectors, new_with_defaults, from_schema_url, merge, default}` are |
| 121 | +replaced with `Resource::builder()`. |
| 122 | + |
| 123 | +Before: |
| 124 | + |
| 125 | +```rust |
| 126 | +Resource::default().with_attributes([ |
| 127 | + KeyValue::new("service.name", "test_service"), |
| 128 | + KeyValue::new("key", "value"), |
| 129 | +]); |
| 130 | +``` |
| 131 | + |
| 132 | +After: |
| 133 | + |
| 134 | +```rust |
| 135 | +Resource::builder() |
| 136 | + .with_service_name("test_service") |
| 137 | + .with_attribute(KeyValue::new("key", "value")) |
| 138 | + .build(); |
| 139 | +``` |
| 140 | + |
| 141 | +## Improved internal logging |
| 142 | + |
| 143 | +OpenTelemetry internally used `tracing` to emit its internal logs. This is under |
| 144 | +feature-flag "internal-logs" that is enabled by default in all crates. When |
| 145 | +using OTel Logging, care must be taken to avoid OTel's own internal log being |
| 146 | +fed back to OTel, creating an circular dependency. This can be achieved via proper |
| 147 | +filtering. The OTLP Examples in the repo shows how to achieve this. It also |
| 148 | +shows how to send OTel's internal logs to stdout using `tracing::Fmt`. |
| 149 | + |
| 150 | +## Full example |
| 151 | + |
| 152 | +A fully runnable example application using OTLP Exporter is provided in this |
| 153 | +repo. Comparing the 0.27 vs 0.28 of the example would give a good overview of |
| 154 | +the changes required to be made. |
| 155 | + |
| 156 | +[Basic OTLP Example |
| 157 | +(0.27)](https://github.com/open-telemetry/opentelemetry-rust/tree/opentelemetry-otlp-0.27.0/opentelemetry-otlp/examples) |
| 158 | +[Basic OTLP Example |
| 159 | +(0.28)](https://github.com/open-telemetry/opentelemetry-rust/tree/opentelemetry-otlp-0.27.0/opentelemetry-otlp/examples) |
| 160 | +// TODO: Update this link after github tag is created. |
| 161 | + |
| 162 | +This guide covers only the most common breaking changes. If you’re using custom |
| 163 | +exporters or processors (or authoring one), please consult the changelog for |
| 164 | +additional migration details. |
| 165 | + |
| 166 | +## Notes on Breaking Changes and the Path to 1.0 |
| 167 | + |
| 168 | +We understand that breaking changes can be challenging, but they are essential |
| 169 | +for the growth and stability of the project. With the release of 0.28, the |
| 170 | +Metric API (`opentelemetry` crate, "metrics" feature flag) and LogBridge API |
| 171 | +(`opentelemetry` crate, "logs" feature flag) are now stable, and we do not |
| 172 | +anticipate further breaking changes for these components. |
| 173 | + |
| 174 | +Moreover, the `opentelemetry_sdk` crate for "logs" and "metrics" will have a |
| 175 | +very high bar for any future breaking changes. Any changes are expected to |
| 176 | +primarily impact those developing custom components, such as custom exporters. |
| 177 | +In the upcoming releases, we aim to bring the "traces" feature to the same level |
| 178 | +of stability as "logs" and "metrics". Additionally, "opentelemetry-otlp", the |
| 179 | +official exporter, will also receive stability guarantees. |
| 180 | + |
| 181 | +We are excited to announce that a 1.0 release, encompassing logs, metrics, and |
| 182 | +traces, is planned for June 2025. We appreciate your patience and support as we |
| 183 | +work towards this milestone. The 1.0 release will cover the API |
| 184 | +(`opentelemetry`), SDK (`opentelemetry_sdk`), OTLP Exporter |
| 185 | +(`opentelemetry-otlp`), and Tracing-Bridge (`opentelemetry-appender-tracing`). |
| 186 | + |
| 187 | +We encourage you to share your feedback via GitHub issues or the OTel-Rust Slack |
| 188 | +channel [here](https://cloud-native.slack.com/archives/C03GDP0H023). |
0 commit comments