Skip to content

Commit ee4d18a

Browse files
committed
few comments on otlp
1 parent 61b0125 commit ee4d18a

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

docs/migration_0.28.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Please note the following:
6565
`opentelemetry-otlp`. grpc-tonic, reqwest-blocking-client In other words,
6666
`reqwest` and `hyper` are not supported. If using `grpc-tonic`, the OTLP
6767
Exporter must be created from within a Tokio runtime.
68+
If using exporters other than `opentelemetry-otlp`, consult the docs
69+
for the same to know if there are any restrictions/requirements on async
70+
runtime.
6871
2. Timeout enforcement is now moved to Exporters. i.e
6972
BatchProcessor,PeriodicReader does not enforce timeouts. For logs and traces,
7073
`max_export_timeout` (on Processors) or `OTEL_BLRP_EXPORT_TIMEOUT` or
@@ -134,7 +137,6 @@ fed back to OTel, creating an infinite loop. This can be achieved via proper
134137
filtering. The OTLP Examples in the repo shows how to achieve this. It also
135138
shows how to send OTel's internal logs to stdtout using `tracing::Fmt`.
136139

137-
138140
## Full example
139141

140142
A fully runnable example application using OTLP Exporter is provided in this
@@ -144,7 +146,8 @@ the changes required to be made.
144146
[Basic OTLP Example
145147
(0.27)](https://github.com/open-telemetry/opentelemetry-rust/tree/opentelemetry-otlp-0.27.0/opentelemetry-otlp/examples)
146148
[Basic OTLP Example
147-
(0.28)](https://github.com/open-telemetry/opentelemetry-rust/tree/opentelemetry-otlp-0.28.0/opentelemetry-otlp/examples)
149+
(0.28)](https://github.com/open-telemetry/opentelemetry-rust/tree/opentelemetry-otlp-0.27.0/opentelemetry-otlp/examples)
150+
// TODO: Update this link after github tag is created.
148151

149152
This guide covers only the most common breaking changes. If you’re using custom
150153
exporters or processors (or authoring one), please consult the changelog for

opentelemetry-otlp/examples/basic-otlp-http/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// To use hyper as the HTTP client - cargo run --features="hyper" --no-default-features
21
use once_cell::sync::Lazy;
32
use opentelemetry::{
43
global,
@@ -19,7 +18,7 @@ use tracing_subscriber::EnvFilter;
1918

2019
static RESOURCE: Lazy<Resource> = Lazy::new(|| {
2120
Resource::builder()
22-
.with_service_name("basic-otlp-example")
21+
.with_service_name("basic-otlp-example-http")
2322
.build()
2423
});
2524

@@ -102,10 +101,25 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
102101
.with(fmt_layer)
103102
.init();
104103

104+
// At this point Logs (OTel Logs and Fmt Logs) are initialized, which will
105+
// allow internal-logs from Tracing/Metrics initializer to be captured.
106+
105107
let tracer_provider = init_traces();
108+
// Set the global tracer provider using a clone of the tracer_provider.
109+
// Setting global tracer provider is required if other parts of the application
110+
// uses global::tracer() or global::tracer_with_version() to get a tracer.
111+
// Cloning simply creates a new reference to the same tracer provider. It is
112+
// important to hold on to the tracer_provider here, so as to invoke
113+
// shutdown on it when application ends.
106114
global::set_tracer_provider(tracer_provider.clone());
107115

108116
let meter_provider = init_metrics();
117+
// Set the global meter provider using a clone of the meter_provider.
118+
// Setting global meter provider is required if other parts of the application
119+
// uses global::meter() or global::meter_with_version() to get a meter.
120+
// Cloning simply creates a new reference to the same meter provider. It is
121+
// important to hold on to the meter_provider here, so as to invoke
122+
// shutdown on it when application ends.
109123
global::set_meter_provider(meter_provider.clone());
110124

111125
let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")];
@@ -147,8 +161,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
147161
info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99);
148162

149163
tracer_provider.shutdown()?;
150-
logger_provider.shutdown()?;
151164
meter_provider.shutdown()?;
165+
logger_provider.shutdown()?;
152166

153167
Ok(())
154168
}

opentelemetry-otlp/examples/basic-otlp/src/main.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tracing_subscriber::EnvFilter;
1515

1616
static RESOURCE: Lazy<Resource> = Lazy::new(|| {
1717
Resource::builder()
18-
.with_service_name("basic-otlp-example")
18+
.with_service_name("basic-otlp-example-grpc")
1919
.build()
2020
});
2121

@@ -94,10 +94,25 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9494
.with(fmt_layer)
9595
.init();
9696

97+
// At this point Logs (OTel Logs and Fmt Logs) are initialized, which will
98+
// allow internal-logs from Tracing/Metrics initializer to be captured.
99+
97100
let tracer_provider = init_traces();
101+
// Set the global tracer provider using a clone of the tracer_provider.
102+
// Setting global tracer provider is required if other parts of the application
103+
// uses global::tracer() or global::tracer_with_version() to get a tracer.
104+
// Cloning simply creates a new reference to the same tracer provider. It is
105+
// important to hold on to the tracer_provider here, so as to invoke
106+
// shutdown on it when application ends.
98107
global::set_tracer_provider(tracer_provider.clone());
99108

100109
let meter_provider = init_metrics();
110+
// Set the global meter provider using a clone of the meter_provider.
111+
// Setting global meter provider is required if other parts of the application
112+
// uses global::meter() or global::meter_with_version() to get a meter.
113+
// Cloning simply creates a new reference to the same meter provider. It is
114+
// important to hold on to the meter_provider here, so as to invoke
115+
// shutdown on it when application ends.
101116
global::set_meter_provider(meter_provider.clone());
102117

103118
let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")];

0 commit comments

Comments
 (0)