Skip to content

Commit

Permalink
few comments on otlp
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Feb 6, 2025
1 parent 61b0125 commit ee4d18a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
7 changes: 5 additions & 2 deletions docs/migration_0.28.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Please note the following:
`opentelemetry-otlp`. grpc-tonic, reqwest-blocking-client In other words,
`reqwest` and `hyper` are not supported. If using `grpc-tonic`, the OTLP
Exporter must be created from within a Tokio runtime.
If using exporters other than `opentelemetry-otlp`, consult the docs
for the same to know if there are any restrictions/requirements on async
runtime.
2. Timeout enforcement is now moved to Exporters. i.e
BatchProcessor,PeriodicReader does not enforce timeouts. For logs and traces,
`max_export_timeout` (on Processors) or `OTEL_BLRP_EXPORT_TIMEOUT` or
Expand Down Expand Up @@ -134,7 +137,6 @@ fed back to OTel, creating an infinite loop. This can be achieved via proper
filtering. The OTLP Examples in the repo shows how to achieve this. It also
shows how to send OTel's internal logs to stdtout using `tracing::Fmt`.


## Full example

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

This guide covers only the most common breaking changes. If you’re using custom
exporters or processors (or authoring one), please consult the changelog for
Expand Down
20 changes: 17 additions & 3 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// To use hyper as the HTTP client - cargo run --features="hyper" --no-default-features
use once_cell::sync::Lazy;
use opentelemetry::{
global,
Expand All @@ -19,7 +18,7 @@ use tracing_subscriber::EnvFilter;

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::builder()
.with_service_name("basic-otlp-example")
.with_service_name("basic-otlp-example-http")
.build()
});

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

// At this point Logs (OTel Logs and Fmt Logs) are initialized, which will
// allow internal-logs from Tracing/Metrics initializer to be captured.

let tracer_provider = init_traces();
// Set the global tracer provider using a clone of the tracer_provider.
// Setting global tracer provider is required if other parts of the application
// uses global::tracer() or global::tracer_with_version() to get a tracer.
// Cloning simply creates a new reference to the same tracer provider. It is
// important to hold on to the tracer_provider here, so as to invoke
// shutdown on it when application ends.
global::set_tracer_provider(tracer_provider.clone());

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

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

tracer_provider.shutdown()?;
logger_provider.shutdown()?;
meter_provider.shutdown()?;
logger_provider.shutdown()?;

Ok(())
}
17 changes: 16 additions & 1 deletion opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing_subscriber::EnvFilter;

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::builder()
.with_service_name("basic-otlp-example")
.with_service_name("basic-otlp-example-grpc")
.build()
});

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

// At this point Logs (OTel Logs and Fmt Logs) are initialized, which will
// allow internal-logs from Tracing/Metrics initializer to be captured.

let tracer_provider = init_traces();
// Set the global tracer provider using a clone of the tracer_provider.
// Setting global tracer provider is required if other parts of the application
// uses global::tracer() or global::tracer_with_version() to get a tracer.
// Cloning simply creates a new reference to the same tracer provider. It is
// important to hold on to the tracer_provider here, so as to invoke
// shutdown on it when application ends.
global::set_tracer_provider(tracer_provider.clone());

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

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

0 comments on commit ee4d18a

Please sign in to comment.