Skip to content

Commit 4240837

Browse files
authored
Merge branch 'main' into set_precommit_pwd
2 parents b21bd3f + eeb367d commit 4240837

File tree

145 files changed

+4989
-2693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+4989
-2693
lines changed

.cspell.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626
// workspace dictionary.
2727
"words": [
2828
"actix",
29+
"anyvalue",
2930
"appender",
3031
"appenders",
3132
"Bhasin",
33+
"BLRP",
3234
"Cijo",
3335
"clippy",
3436
"clonable",
3537
"codecov",
3638
"datapoint",
3739
"deque",
3840
"Dirkjan",
41+
"docsrs",
42+
"Dwarnings",
3943
"EPYC",
4044
"flamegraph",
4145
"hasher",
@@ -54,12 +58,14 @@
5458
"OTELCOL",
5559
"OTLP",
5660
"periodicreader",
61+
"Pillai",
5762
"pprof",
5863
"prost",
5964
"protoc",
6065
"quantile",
6166
"Redelmeier",
6267
"reqwest",
68+
"rstest",
6369
"runtimes",
6470
"rustc",
6571
"serde",
@@ -70,7 +76,9 @@
7076
"testresults",
7177
"thiserror",
7278
"tracerprovider",
79+
"Umesan",
7380
"updown",
81+
"Utkarsh",
7482
"Zhongyang",
7583
"zipkin"
7684
],

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ members = [
88
"stress",
99
]
1010
resolver = "2"
11+
# Avoid applying patch to force use of workspace members for this
12+
# not actively maintained crate
13+
exclude = ["opentelemetry-prometheus"]
1114

1215
[profile.bench]
1316
# https://doc.rust-lang.org/cargo/reference/profiles.html#bench
@@ -50,3 +53,9 @@ tracing = { version = ">=0.1.40", default-features = false }
5053
tracing-core = { version = ">=0.1.33", default-features = false }
5154
tracing-subscriber = { version = "0.3", default-features = false }
5255
url = { version = "2.5", default-features = false }
56+
57+
# Aviod use of crates.io version of these crates through the tracing-opentelemetry dependencies
58+
[patch.crates-io]
59+
opentelemetry = { path = "opentelemetry" }
60+
opentelemetry_sdk = { path = "opentelemetry-sdk" }
61+
opentelemetry-stdout = { path = "opentelemetry-stdout" }

README.md

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ documentation.
3030

3131
| Signal/Component | Overall Status |
3232
| -------------------- | ------------------ |
33-
| Logs-API | RC* |
34-
| Logs-SDK | Beta |
35-
| Logs-OTLP Exporter | Beta |
36-
| Logs-Appender-Tracing | Beta |
37-
| Metrics-API | RC |
38-
| Metrics-SDK | Beta |
39-
| Metrics-OTLP Exporter | Beta |
33+
| Logs-API | Stable* |
34+
| Logs-SDK | RC |
35+
| Logs-OTLP Exporter | RC |
36+
| Logs-Appender-Tracing | RC |
37+
| Metrics-API | Stable |
38+
| Metrics-SDK | RC |
39+
| Metrics-OTLP Exporter | RC |
4040
| Traces-API | Beta |
4141
| Traces-SDK | Beta |
4242
| Traces-OTLP Exporter | Beta |
@@ -55,49 +55,28 @@ If you already use the logging APIs from above, continue to use them, and use
5555
the appenders above to bridge the logs to OpenTelemetry. If you are using a
5656
library not listed here, feel free to contribute a new appender for the same.
5757

58-
If you are starting fresh, then consider using
58+
If you are starting fresh, we recommend using
5959
[tracing](https://github.com/tokio-rs/tracing) as your logging API. It supports
60-
structured logging and is actively maintained.
60+
structured logging and is actively maintained. `OpenTelemetry` itself uses
61+
`tracing` for its internal logging.
6162

6263
Project versioning information and stability guarantees can be found
6364
[here](VERSIONING.md).
6465

6566
## Getting Started
6667

67-
```rust
68-
use opentelemetry::{
69-
global,
70-
trace::{Tracer, TracerProvider as _},
71-
};
72-
use opentelemetry_sdk::trace::TracerProvider;
73-
74-
fn main() {
75-
// Create a new trace pipeline that prints to stdout
76-
let provider = TracerProvider::builder()
77-
.with_simple_exporter(opentelemetry_stdout::SpanExporter::default())
78-
.build();
79-
let tracer = provider.tracer("readme_example");
80-
81-
tracer.in_span("doing_work", |cx| {
82-
// Traced app logic here...
83-
});
84-
85-
// Shutdown trace pipeline
86-
provider.shutdown().expect("TracerProvider should shutdown successfully")
87-
}
88-
```
89-
90-
The example above requires the following packages:
91-
92-
```toml
93-
# Cargo.toml
94-
[dependencies]
95-
opentelemetry = "0.22"
96-
opentelemetry_sdk = "0.22"
97-
opentelemetry-stdout = { version = "0.3", features = ["trace"] }
98-
```
99-
100-
See the [examples](./examples) directory for different integration patterns.
68+
If you are new to OpenTelemetry, start with the [Stdout
69+
Example](./opentelemetry-stdout/examples/basic.rs). This example demonstrates
70+
how to use OpenTelemetry for logs, metrics, and traces, and display
71+
telemetry data on your console.
72+
73+
For those using OTLP, the recommended OpenTelemetry Exporter for production
74+
scenarios, refer to the [OTLP Example -
75+
HTTP](./opentelemetry-otlp/examples/basic-otlp-http/README.md) and the [OTLP
76+
Example - gRPC](./opentelemetry-otlp/examples/basic-otlp/README.md).
77+
78+
Additional examples for various integration patterns can be found in the
79+
[examples](./examples) directory.
10180

10281
## Overview of crates
10382

docs/migration_0.28.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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).

examples/logs-basic/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use opentelemetry_appender_tracing::layer;
2-
use opentelemetry_sdk::logs::LoggerProvider;
2+
use opentelemetry_sdk::logs::SdkLoggerProvider;
33
use opentelemetry_sdk::Resource;
44
use tracing::error;
55
use tracing_subscriber::prelude::*;
66

77
fn main() {
88
let exporter = opentelemetry_stdout::LogExporter::default();
9-
let provider: LoggerProvider = LoggerProvider::builder()
9+
let provider: SdkLoggerProvider = SdkLoggerProvider::builder()
1010
.with_resource(
1111
Resource::builder()
1212
.with_service_name("log-appender-tracing-example")

examples/metrics-advanced/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
4949
.with_temporality(Temporality::Delta)
5050
.build();
5151

52-
let reader = PeriodicReader::builder(exporter).build();
53-
5452
let resource = Resource::builder()
5553
.with_service_name("metrics-advanced-example")
5654
.build();
5755

5856
let provider = SdkMeterProvider::builder()
59-
.with_reader(reader)
57+
.with_periodic_exporter(exporter)
6058
.with_resource(resource)
6159
.with_view(my_view_rename_and_unit)
6260
.with_view(my_view_drop_attributes)

0 commit comments

Comments
 (0)