From e87cf1ad501fd1c88d706d436c2b9a5eae02c1ff Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 13 May 2024 12:15:19 -0700 Subject: [PATCH 1/2] OTLP Examples fixed to be consistent --- .../examples/basic-otlp-http/README.md | 246 +++++++++++++++++- .../basic-otlp-http/docker-compose.yaml | 3 - .../otel-collector-config.yaml | 10 +- .../examples/basic-otlp-http/src/main.rs | 84 +++--- .../examples/basic-otlp/README.md | 10 +- .../examples/basic-otlp/docker-compose.yaml | 3 - .../examples/basic-otlp/src/main.rs | 80 +++--- 7 files changed, 331 insertions(+), 105 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp-http/README.md b/opentelemetry-otlp/examples/basic-otlp-http/README.md index 35d4b711b1..cf3899d38e 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/README.md +++ b/opentelemetry-otlp/examples/basic-otlp-http/README.md @@ -1,9 +1,17 @@ -* The application send data directly to a Collector (port 4318) -* Run the application locally, to run as a docker container you have to change the relative paths from the `Cargo.toml` -* The Collector then sends the data to the appropriate backend, in this case Debug Exporter. The Debug Exporter exports data to console. +# Basic OTLP exporter Example -This demo uses `docker-compose` and by default runs against the `otel/opentelemetry-collector-dev:latest` image, -and uses `http` as the transport. +This example shows how to setup OpenTelemetry OTLP exporter for logs, metrics +and traces to exports them to the [OpenTelemetry +Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP over HTTP. +The Collector then sends the data to the appropriate backend, in this case, +the logging Exporter, which displays data to console. + +## Usage + +### `docker-compose` + +By default runs against the `otel/opentelemetry-collector:latest` image, and uses `reqwest-client` +as the http client, using http as the transport. ```shell docker-compose up @@ -11,12 +19,236 @@ docker-compose up In another terminal run the application `cargo run` -The docker-compose terminal will display logs, metrics and traces. +The docker-compose terminal will display logs, traces, metrics. -Tear it down: +Press Ctrl+C to stop the collector, and then tear it down: ```shell docker-compose down ``` +### Manual + +If you don't want to use `docker-compose`, you can manually run the `otel/opentelemetry-collector` container +and inspect the logs to see traces being transferred. + +```shell +# From the current directory, run `opentelemetry-collector` +$ docker run --rm -it -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml + +# Run the app which exports logs, metrics and traces via OTLP to the collector. +$ cargo run +``` + +## View results +You should be able to see something similar below with different time and ID in the same console that docker runs. + +### Span + +```text +2023-09-08T21:50:35.884Z info ResourceSpans #0 +Resource SchemaURL: +Resource attributes: + -> service.name: Str(basic-otlp-tracing-example) +ScopeSpans #0 +ScopeSpans SchemaURL: +InstrumentationScope ex.com/basic +Span #0 + Trace ID : f8e7ea4dcab43689cea14f708309d682 + Parent ID : 8b560e2e7238eab5 + ID : 9e36b48dc07b32fe + Name : Sub operation... + Kind : Internal + Start time : 2023-09-08 21:50:35.872800345 +0000 UTC + End time : 2023-09-08 21:50:35.87282574 +0000 UTC + Status code : Unset + Status message : +Attributes: + -> lemons: Str(five) +Events: +SpanEvent #0 + -> Name: Sub span event + -> Timestamp: 2023-09-08 21:50:35.872808684 +0000 UTC + -> DroppedAttributesCount: 0 +ResourceSpans #1 +Resource SchemaURL: +Resource attributes: + -> service.name: Str(basic-otlp-tracing-example) +ScopeSpans #0 +ScopeSpans SchemaURL: +InstrumentationScope ex.com/basic +Span #0 + Trace ID : f8e7ea4dcab43689cea14f708309d682 + Parent ID : + ID : 8b560e2e7238eab5 + Name : operation + Kind : Internal + Start time : 2023-09-08 21:50:35.872735497 +0000 UTC + End time : 2023-09-08 21:50:35.872832026 +0000 UTC + Status code : Unset + Status message : +Attributes: + -> ex.com/another: Str(yes) +Events: +SpanEvent #0 + -> Name: Nice operation! + -> Timestamp: 2023-09-08 21:50:35.872750123 +0000 UTC + -> DroppedAttributesCount: 0 + -> Attributes:: + -> bogons: Int(100) + {"kind": "exporter", "data_type": "traces", "name": "logging"} +``` + +### Metric + +```text +2023-09-08T19:14:12.522Z info ResourceMetrics #0 +Resource SchemaURL: +Resource attributes: + -> service.name: Str(basic-otlp-metrics-example) +ScopeMetrics #0 +ScopeMetrics SchemaURL: +InstrumentationScope ex.com/basic +Metric #0 +Descriptor: + -> Name: ex.com.one + -> Description: A gauge set to 1.0 + -> Unit: + -> DataType: Gauge +NumberDataPoints #0 +Data point attributes: + -> A: Str(1) + -> B: Str(2) + -> C: Str(3) + -> lemons: Int(10) +StartTimestamp: 1970-01-01 00:00:00 +0000 UTC +Timestamp: 2023-09-08 19:14:12.468030127 +0000 UTC +Value: 1.000000 +Metric #1 +Descriptor: + -> Name: ex.com.two + -> Description: + -> Unit: + -> DataType: Histogram + -> AggregationTemporality: Cumulative +HistogramDataPoints #0 +Data point attributes: + -> A: Str(1) + -> B: Str(2) + -> C: Str(3) + -> lemons: Int(10) +StartTimestamp: 2023-09-08 19:14:12.466896812 +0000 UTC +Timestamp: 2023-09-08 19:14:12.468052807 +0000 UTC +Count: 1 +Sum: 5.500000 +Min: 5.500000 +Max: 5.500000 +ExplicitBounds #0: 0.000000 +ExplicitBounds #1: 5.000000 +ExplicitBounds #2: 10.000000 +ExplicitBounds #3: 25.000000 +ExplicitBounds #4: 50.000000 +ExplicitBounds #5: 75.000000 +ExplicitBounds #6: 100.000000 +ExplicitBounds #7: 250.000000 +ExplicitBounds #8: 500.000000 +ExplicitBounds #9: 750.000000 +ExplicitBounds #10: 1000.000000 +ExplicitBounds #11: 2500.000000 +ExplicitBounds #12: 5000.000000 +ExplicitBounds #13: 7500.000000 +ExplicitBounds #14: 10000.000000 +Buckets #0, Count: 0 +Buckets #1, Count: 0 +Buckets #2, Count: 1 +Buckets #3, Count: 0 +Buckets #4, Count: 0 +Buckets #5, Count: 0 +Buckets #6, Count: 0 +Buckets #7, Count: 0 +Buckets #8, Count: 0 +Buckets #9, Count: 0 +Buckets #10, Count: 0 +Buckets #11, Count: 0 +Buckets #12, Count: 0 +Buckets #13, Count: 0 +Buckets #14, Count: 0 +Buckets #15, Count: 0 +HistogramDataPoints #1 +StartTimestamp: 2023-09-08 19:14:12.466896812 +0000 UTC +Timestamp: 2023-09-08 19:14:12.468052807 +0000 UTC +Count: 1 +Sum: 1.300000 +Min: 1.300000 +Max: 1.300000 +ExplicitBounds #0: 0.000000 +ExplicitBounds #1: 5.000000 +ExplicitBounds #2: 10.000000 +ExplicitBounds #3: 25.000000 +ExplicitBounds #4: 50.000000 +ExplicitBounds #5: 75.000000 +ExplicitBounds #6: 100.000000 +ExplicitBounds #7: 250.000000 +ExplicitBounds #8: 500.000000 +ExplicitBounds #9: 750.000000 +ExplicitBounds #10: 1000.000000 +ExplicitBounds #11: 2500.000000 +ExplicitBounds #12: 5000.000000 +ExplicitBounds #13: 7500.000000 +ExplicitBounds #14: 10000.000000 +Buckets #0, Count: 0 +Buckets #1, Count: 1 +Buckets #2, Count: 0 +Buckets #3, Count: 0 +Buckets #4, Count: 0 +Buckets #5, Count: 0 +Buckets #6, Count: 0 +Buckets #7, Count: 0 +Buckets #8, Count: 0 +Buckets #9, Count: 0 +Buckets #10, Count: 0 +Buckets #11, Count: 0 +Buckets #12, Count: 0 +Buckets #13, Count: 0 +Buckets #14, Count: 0 +Buckets #15, Count: 0 + {"kind": "exporter", "data_type": "metrics", "name": "logging"} +``` + +### Logs + +```text +2023-09-08T21:50:35.884Z info ResourceLog #0 +Resource SchemaURL: +Resource attributes: + -> service.name: Str(basic-otlp-logging-example) +ScopeLogs #0 +ScopeLogs SchemaURL: +InstrumentationScope opentelemetry-log-appender 0.1.0 +LogRecord #0 +ObservedTimestamp: 2023-09-08 21:50:35.872759168 +0000 UTC +Timestamp: 1970-01-01 00:00:00 +0000 UTC +SeverityText: INFO +SeverityNumber: Info(9) +Body: Str(hello from banana. My price is 2.99. I am also inside a Span!) +Trace ID: f8e7ea4dcab43689cea14f708309d682 +Span ID: 8b560e2e7238eab5 +Flags: 1 +ResourceLog #1 +Resource SchemaURL: +Resource attributes: + -> service.name: Str(basic-otlp-logging-example) +ScopeLogs #0 +ScopeLogs SchemaURL: +InstrumentationScope opentelemetry-log-appender 0.1.0 +LogRecord #0 +ObservedTimestamp: 2023-09-08 21:50:35.872833713 +0000 UTC +Timestamp: 1970-01-01 00:00:00 +0000 UTC +SeverityText: INFO +SeverityNumber: Info(9) +Body: Str(hello from apple. My price is 1.99) +Trace ID: +Span ID: +Flags: 0 +``` diff --git a/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml b/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml index ce5f41e13d..dc9d1e7a5d 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml +++ b/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml @@ -8,10 +8,7 @@ services: volumes: - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml ports: - - "1888:1888" # pprof extension - - "13133:13133" # health_check extension - "4318:4318" # OTLP HTTP receiver - - "55670:55679" # zpages extension diff --git a/opentelemetry-otlp/examples/basic-otlp-http/otel-collector-config.yaml b/opentelemetry-otlp/examples/basic-otlp-http/otel-collector-config.yaml index 1c6d258426..0735e7c69a 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/otel-collector-config.yaml +++ b/opentelemetry-otlp/examples/basic-otlp-http/otel-collector-config.yaml @@ -11,17 +11,17 @@ receivers: http: exporters: - debug: - verbosity: detailed + logging: + loglevel: debug service: pipelines: traces: receivers: [otlp] - exporters: [debug] + exporters: [logging] metrics: receivers: [otlp] - exporters: [debug] + exporters: [logging] logs: receivers: [otlp] - exporters: [debug] \ No newline at end of file + exporters: [logging] \ No newline at end of file diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index 06ddaed292..450ff8d184 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -1,30 +1,33 @@ use once_cell::sync::Lazy; use opentelemetry::{ global, - metrics::MetricsError, - trace::{TraceContextExt, TraceError, Tracer}, + metrics::{MetricsError, Unit}, + trace::{TraceContextExt, TraceError, Tracer, TracerProvider as _}, Key, KeyValue, }; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; use opentelemetry_otlp::WithExportConfig; -use opentelemetry_sdk::logs as sdklogs; -use opentelemetry_sdk::resource; use opentelemetry_sdk::trace as sdktrace; +use opentelemetry_sdk::{ + logs::{self as sdklogs, Config}, + Resource, +}; use std::error::Error; use tracing::info; use tracing_subscriber::prelude::*; +static RESOURCE: Lazy = Lazy::new(|| { + Resource::new(vec![KeyValue::new( + opentelemetry_semantic_conventions::resource::SERVICE_NAME, + "basic-otlp-example", + )]) +}); + fn init_logs() -> Result { - let service_name = env!("CARGO_BIN_NAME"); opentelemetry_otlp::new_pipeline() .logging() - .with_log_config( - sdklogs::Config::default().with_resource(resource::Resource::new(vec![KeyValue::new( - opentelemetry_semantic_conventions::resource::SERVICE_NAME, - service_name, - )])), - ) + .with_log_config(Config::default().with_resource(RESOURCE.clone())) .with_exporter( opentelemetry_otlp::new_exporter() .http() @@ -41,6 +44,7 @@ fn init_tracer() -> Result { .http() .with_endpoint("http://localhost:4318/v1/traces"), ) + .with_trace_config(sdktrace::config().with_resource(RESOURCE.clone())) .install_batch(opentelemetry_sdk::runtime::Tokio) } @@ -56,6 +60,7 @@ fn init_metrics() -> Result Ok(provider), @@ -63,18 +68,6 @@ fn init_metrics() -> Result = Lazy::new(|| { - [ - LEMONS_KEY.i64(10), - KeyValue::new("A", "1"), - KeyValue::new("B", "2"), - KeyValue::new("C", "3"), - ] -}); - #[tokio::main] async fn main() -> Result<(), Box> { let result = init_tracer(); @@ -93,35 +86,54 @@ async fn main() -> Result<(), Box> { let meter_provider = result.unwrap(); - // Opentelemetry will not provide a global API to manage the logger provider. Application users must manage the lifecycle of the logger provider on their own. Dropping logger providers will disable log emitting. + // Opentelemetry will not provide a global API to manage the logger + // provider. Application users must manage the lifecycle of the logger + // provider on their own. Dropping logger providers will disable log + // emitting. let logger_provider = init_logs().unwrap(); - - let tracer = global::tracer("ex.com/basic"); - let meter = global::meter("ex.com/basic"); - let layer = OpenTelemetryTracingBridge::new(&logger_provider); tracing_subscriber::registry().with(layer).init(); - tracer.in_span("operation", |cx| { + let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")]; + let tracer = global::tracer_provider() + .tracer_builder("basic") + .with_attributes(common_scope_attributes.clone()) + .build(); + let meter = global::meter_with_version( + "basic", + Some("v1.0"), + Some("schema_url"), + Some(common_scope_attributes.clone()), + ); + + let counter = meter + .u64_counter("test_counter") + .with_description("a simple counter for demo purposes.") + .with_unit(Unit::new("my_unit")) + .init(); + for _ in 0..10 { + counter.add(1, &[KeyValue::new("test_key", "test_value")]); + } + counter.add(1, &[KeyValue::new("test_key", "test_value")]); + + tracer.in_span("Main operation", |cx| { let span = cx.span(); span.add_event( "Nice operation!".to_string(), vec![Key::new("bogons").i64(100)], ); - span.set_attribute(KeyValue::new(ANOTHER_KEY, "yes")); + span.set_attribute(KeyValue::new("another.key", "yes")); + + info!(target: "my-target", "hello from {}. My price is {}. I am also inside a Span!", "banana", 2.99); tracer.in_span("Sub operation...", |cx| { let span = cx.span(); - span.set_attribute(KeyValue::new(LEMONS_KEY, "five")); - + span.set_attribute(KeyValue::new("another.key", "yes")); span.add_event("Sub span event", vec![]); }); - info!(target: "my-target", "hello from {}. My price is {}. I am also inside a Span!", "banana", 2.99); }); - info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99); - let histogram = meter.f64_histogram("ex.com.two").init(); - histogram.record(5.5, COMMON_ATTRIBUTES.as_ref()); + info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99); global::shutdown_tracer_provider(); logger_provider.shutdown(); diff --git a/opentelemetry-otlp/examples/basic-otlp/README.md b/opentelemetry-otlp/examples/basic-otlp/README.md index cc090a6eea..1d9d81534d 100644 --- a/opentelemetry-otlp/examples/basic-otlp/README.md +++ b/opentelemetry-otlp/examples/basic-otlp/README.md @@ -2,15 +2,15 @@ This example shows how to setup OpenTelemetry OTLP exporter for logs, metrics and traces to exports them to the [OpenTelemetry -Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP. -The Collector then sends the data to the appropriate backend, in this case -Debug Exporter. The Debug Exporter exports data to console. +Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP over gRPC. +The Collector then sends the data to the appropriate backend, in this case, +the logging Exporter, which displays data to console. ## Usage ### `docker-compose` -By default runs against the `otel/opentelemetry-collector-dev:latest` image, and uses the `tonic`'s +By default runs against the `otel/opentelemetry-collector:latest` image, and uses the `tonic`'s `grpc` example as the transport. ```shell @@ -21,7 +21,7 @@ In another terminal run the application `cargo run` The docker-compose terminal will display logs, traces, metrics. -Tear it down: +Press Ctrl+C to stop the collector, and then tear it down: ```shell docker-compose down diff --git a/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml b/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml index a193518f3f..fc9b3f1948 100644 --- a/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml +++ b/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml @@ -8,10 +8,7 @@ services: volumes: - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml ports: - - "1888:1888" # pprof extension - - "13133:13133" # health_check extension - "4317:4317" # OTLP gRPC receiver - - "55670:55679" # zpages extension diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index b966b6efbf..96d818dc6b 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -2,8 +2,8 @@ use log::{info, Level}; use once_cell::sync::Lazy; use opentelemetry::global; use opentelemetry::logs::LogError; -use opentelemetry::metrics::MetricsError; -use opentelemetry::trace::TraceError; +use opentelemetry::metrics::{MetricsError, Unit}; +use opentelemetry::trace::{TraceError, TracerProvider}; use opentelemetry::{ trace::{TraceContextExt, Tracer}, Key, KeyValue, @@ -14,6 +14,13 @@ use opentelemetry_sdk::logs::Config; use opentelemetry_sdk::{runtime, trace as sdktrace, Resource}; use std::error::Error; +static RESOURCE: Lazy = Lazy::new(|| { + Resource::new(vec![KeyValue::new( + opentelemetry_semantic_conventions::resource::SERVICE_NAME, + "basic-otlp-example", + )]) +}); + fn init_tracer() -> Result { opentelemetry_otlp::new_pipeline() .tracing() @@ -22,12 +29,7 @@ fn init_tracer() -> Result { .tonic() .with_endpoint("http://localhost:4317"), ) - .with_trace_config( - sdktrace::config().with_resource(Resource::new(vec![KeyValue::new( - opentelemetry_semantic_conventions::resource::SERVICE_NAME, - "basic-otlp-tracing-example", - )])), - ) + .with_trace_config(sdktrace::config().with_resource(RESOURCE.clone())) .install_batch(runtime::Tokio) } @@ -43,10 +45,7 @@ fn init_metrics() -> Result Ok(provider), @@ -55,15 +54,9 @@ fn init_metrics() -> Result Result { - let service_name = env!("CARGO_BIN_NAME"); opentelemetry_otlp::new_pipeline() .logging() - .with_log_config( - Config::default().with_resource(Resource::new(vec![KeyValue::new( - opentelemetry_semantic_conventions::resource::SERVICE_NAME, - service_name, - )])), - ) + .with_log_config(Config::default().with_resource(RESOURCE.clone())) .with_exporter( opentelemetry_otlp::new_exporter() .tonic() @@ -72,18 +65,6 @@ fn init_logs() -> Result { .install_batch(runtime::Tokio) } -const LEMONS_KEY: Key = Key::from_static_str("lemons"); -const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another"); - -static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| { - [ - LEMONS_KEY.i64(10), - KeyValue::new("A", "1"), - KeyValue::new("B", "2"), - KeyValue::new("C", "3"), - ] -}); - #[tokio::main] async fn main() -> Result<(), Box> { // By binding the result to an unused variable, the lifetime of the variable @@ -113,35 +94,42 @@ async fn main() -> Result<(), Box> { log::set_boxed_logger(Box::new(otel_log_appender)).unwrap(); log::set_max_level(Level::Info.to_level_filter()); - let tracer = global::tracer("ex.com/basic"); - let meter = global::meter("ex.com/basic"); + let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")]; + let tracer = global::tracer_provider() + .tracer_builder("basic") + .with_attributes(common_scope_attributes.clone()) + .build(); + let meter = global::meter_with_version( + "basic", + Some("v1.0"), + Some("schema_url"), + Some(common_scope_attributes.clone()), + ); - let _gauge = meter - .f64_observable_gauge("ex.com.one") - .with_description("A gauge set to 1.0") - .with_callback(|observer| observer.observe(1.0, COMMON_ATTRIBUTES.as_ref())) + let counter = meter + .u64_counter("test_counter") + .with_description("a simple counter for demo purposes.") + .with_unit(Unit::new("my_unit")) .init(); + for _ in 0..10 { + counter.add(1, &[KeyValue::new("test_key", "test_value")]); + } + counter.add(1, &[KeyValue::new("test_key", "test_value")]); - let histogram = meter.f64_histogram("ex.com.two").init(); - histogram.record(5.5, COMMON_ATTRIBUTES.as_ref()); - - tracer.in_span("operation", |cx| { + tracer.in_span("Main operation", |cx| { let span = cx.span(); span.add_event( "Nice operation!".to_string(), vec![Key::new("bogons").i64(100)], ); - span.set_attribute(KeyValue::new(ANOTHER_KEY, "yes")); + span.set_attribute(KeyValue::new("another.key", "yes")); info!(target: "my-target", "hello from {}. My price is {}. I am also inside a Span!", "banana", 2.99); tracer.in_span("Sub operation...", |cx| { let span = cx.span(); - span.set_attribute(KeyValue::new(LEMONS_KEY, "five")); - + span.set_attribute(KeyValue::new("another.key", "yes")); span.add_event("Sub span event", vec![]); - - histogram.record(1.3, &[]); }); }); From c628077cf0b1a85e37a28539113d7357d390ced3 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 13 May 2024 17:06:23 -0700 Subject: [PATCH 2/2] fix url and shutdown --- opentelemetry-otlp/examples/basic-otlp-http/src/main.rs | 4 ++-- opentelemetry-otlp/examples/basic-otlp/src/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index 450ff8d184..949ed61bc6 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -31,7 +31,7 @@ fn init_logs() -> Result .with_exporter( opentelemetry_otlp::new_exporter() .http() - .with_endpoint("http://localhost:4318"), + .with_endpoint("http://localhost:4318/v1/logs"), ) .install_batch(opentelemetry_sdk::runtime::Tokio) } @@ -136,7 +136,7 @@ async fn main() -> Result<(), Box> { info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99); global::shutdown_tracer_provider(); - logger_provider.shutdown(); + logger_provider.shutdown()?; meter_provider.shutdown()?; Ok(()) diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index 96d818dc6b..112a142696 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -136,7 +136,7 @@ async fn main() -> Result<(), Box> { info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99); global::shutdown_tracer_provider(); - logger_provider.shutdown(); + logger_provider.shutdown()?; meter_provider.shutdown()?; Ok(())