Skip to content

Commit

Permalink
Merge branch 'main' into bounded_instruments
Browse files Browse the repository at this point in the history
# Conflicts:
#	opentelemetry-sdk/benches/metric_counter.rs
#	opentelemetry-sdk/src/metrics/instrument.rs
#	opentelemetry-sdk/src/metrics/internal/sum.rs
#	opentelemetry/src/metrics/instruments/counter.rs
#	opentelemetry/src/metrics/instruments/up_down_counter.rs
#	opentelemetry/src/metrics/noop.rs
#	stress/Cargo.toml
  • Loading branch information
Matthew Shapiro committed Jan 29, 2024
2 parents 09039f6 + 8237f87 commit e88a102
Show file tree
Hide file tree
Showing 94 changed files with 3,787 additions and 1,230 deletions.
1 change: 0 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"Lalit",
"msrv",
"Ochtman",
"openetelemetry",
"opentelemetry",
"OTLP",
"protoc",
Expand Down
8 changes: 4 additions & 4 deletions .github/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ ignore:
- "opentelemetry-jaeger/examples"
- "opentelemetry-zipkin/examples"
- "opentelemetry-otlp/examples"
- "opentelemetry-aws/examples"
- "opentelemetry-datadog/examples"
- "opentelemetry-dynatrace/examples"
- "opentelemetry-http/examples"
- "opentelemetry-prometheus/examples"
- "opentelemetry-zpages/examples"
- "opentelemetry-appender-tracing/examples"
- "opentelemetry-appender-log/examples"
# stress test
- "stress"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ For a deeper discussion, see:

Currently, the Opentelemetry Rust SDK has two ways to handle errors. In the situation where errors are not allowed to return. One should call global error handler to process the errors. Otherwise, one should return the errors.

The Opentelemetry Rust SDK comes with an error type `openetelemetry::Error`. For different function, one error has been defined. All error returned by trace module MUST be wrapped in `opentelemetry::trace::TraceError`. All errors returned by metrics module MUST be wrapped in `opentelemetry::metrics::MetricsError`.
The Opentelemetry Rust SDK comes with an error type `opentelemetry::Error`. For different function, one error has been defined. All error returned by trace module MUST be wrapped in `opentelemetry::trace::TraceError`. All errors returned by metrics module MUST be wrapped in `opentelemetry::metrics::MetricsError`. All errors returned by logs module MUST be wrapped in `opentelemetry::logs::LogsError`.

For users that want to implement their own exporters. It's RECOMMENDED to wrap all errors from the exporter into a crate-level error type, and implement `ExporterError` trait.

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"opentelemetry-jaeger",
"opentelemetry-jaeger/examples/actix-udp",
"opentelemetry-jaeger/examples/remote-sampler",
"opentelemetry-jaeger-propagator",
"opentelemetry-appender-log",
"opentelemetry-appender-tracing",
"opentelemetry-otlp",
Expand Down
5 changes: 3 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ This example uses following crates from this repo:
**Tracing**

This example uses following crates from this repo:

- opentelemetry(tracing)
- opentelemetry-jaeger
- opentelemetry-stdout

The application is built using `tokio`.

Check this example if you want to understand *how to integrate tracing with opentelemetry*.
Check this example if you want to understand *how to create spans and propagate/restore context in OpenTelemetry*.
16 changes: 7 additions & 9 deletions examples/metrics-basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use opentelemetry::metrics::Unit;
use opentelemetry::AttributeSet;
use opentelemetry::{metrics::MeterProvider as _, KeyValue};
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider};
use opentelemetry_sdk::{runtime, Resource};
Expand Down Expand Up @@ -52,11 +53,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
observer.observe_u64(
&observable_counter,
100,
[
AttributeSet::from(&[
KeyValue::new("mykey1", "myvalue1"),
KeyValue::new("mykey2", "myvalue2"),
]
.as_ref(),
]),
)
})?;

Expand Down Expand Up @@ -84,11 +84,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
observer.observe_i64(
&observable_up_down_counter,
100,
[
AttributeSet::from(&[
KeyValue::new("mykey1", "myvalue1"),
KeyValue::new("mykey2", "myvalue2"),
]
.as_ref(),
]),
)
})?;

Expand Down Expand Up @@ -142,11 +141,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
observer.observe_f64(
&observable_gauge,
1.0,
[
AttributeSet::from(&[
KeyValue::new("mykey1", "myvalue1"),
KeyValue::new("mykey2", "myvalue2"),
]
.as_ref(),
]),
)
})?;

Expand Down
1 change: 1 addition & 0 deletions examples/tracing-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["trace
prost = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tonic = { workspace = true }
serde_json = { workspace = true }

[build-dependencies]
tonic-build = "0.9.2"
23 changes: 12 additions & 11 deletions examples/tracing-grpc/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# GRPC example

Example showing [Tonic] client and server interaction with OpenTelemetry context propagation. [tracing_opentelemetry](https://docs.rs/tracing-opentelemetry/0.4.0/tracing_opentelemetry/) is used to hook into the [tracing](https://github.com/tokio-rs/tracing) ecosystem, which enables drop-in replacements for [log](https://github.com/rust-lang/log) macros and an `#[instrument]` macro that will automatically add spans to your functions.
Example showing [Tonic] client and server interaction with OpenTelemetry context
propagation. Traces are exported to stdout.

[Tonic]: https://github.com/hyperium/tonic

Examples
--------
## Running the example

```shell
# Run jaeger in background
$ docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest

# Run the server
# Run the server first
$ cargo run --bin grpc-server

# Now run the client to make a request to the server
$ cargo run --bin grpc-client

# View spans (see the image below)
$ firefox http://localhost:16686/
```

![Jaeger UI](trace.png)
Observe that the traces are exported to stdout, and that they share the same
TraceId. Also, the server span would be parented to the client span. The example
demonstrates how to propagate and restore OpenTelemetry context when making
out-of-process calls, so as to ensure the same trace is continued in the next
process. The client here initiates the trace by creating the root client span,
and it propagates its context to the server. The server, extracts the context,
and creates its own server span using the extracted context, ensuring both spans
are correlated.
12 changes: 10 additions & 2 deletions examples/tracing-grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use opentelemetry::{global, propagation::Injector};
use opentelemetry_sdk::{
propagation::TraceContextPropagator, runtime::Tokio, trace::TracerProvider,
};
use opentelemetry_stdout::SpanExporter;
use opentelemetry_stdout::SpanExporterBuilder;

use opentelemetry::{
trace::{SpanKind, TraceContextExt, Tracer},
Expand All @@ -15,7 +15,15 @@ fn init_tracer() {
global::set_text_map_propagator(TraceContextPropagator::new());
// Install stdout exporter pipeline to be able to retrieve the collected spans.
let provider = TracerProvider::builder()
.with_batch_exporter(SpanExporter::default(), Tokio)
.with_batch_exporter(
SpanExporterBuilder::default()
.with_encoder(|writer, data| {
serde_json::to_writer_pretty(writer, &data).unwrap();
Ok(())
})
.build(),
Tokio,
)
.build();

global::set_tracer_provider(provider);
Expand Down
12 changes: 10 additions & 2 deletions examples/tracing-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ use opentelemetry::{
use opentelemetry_sdk::{
propagation::TraceContextPropagator, runtime::Tokio, trace::TracerProvider,
};
use opentelemetry_stdout::SpanExporter;
use opentelemetry_stdout::SpanExporterBuilder;
use tonic::{transport::Server, Request, Response, Status};

fn init_tracer() {
global::set_text_map_propagator(TraceContextPropagator::new());
// Install stdout exporter pipeline to be able to retrieve the collected spans.
let provider = TracerProvider::builder()
.with_batch_exporter(SpanExporter::default(), Tokio)
.with_batch_exporter(
SpanExporterBuilder::default()
.with_encoder(|writer, data| {
serde_json::to_writer_pretty(writer, &data).unwrap();
Ok(())
})
.build(),
Tokio,
)
.build();

global::set_tracer_provider(provider);
Expand Down
9 changes: 9 additions & 0 deletions opentelemetry-jaeger-propagator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## vNext

## v0.1.0

### Added

- As part of the gradual deprecation of the exporter functionality of the opentelemetry-jaeger crate, move the opentelemetry-jaeger propagator functionality to a new crate named opentelemetry-jaeger-propagator [#1487](https://github.com/open-telemetry/opentelemetry-rust/pull/1487)
37 changes: 37 additions & 0 deletions opentelemetry-jaeger-propagator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "opentelemetry-jaeger-propagator"
version = "0.1.0"
description = "Jaeger propagator for OpenTelemetry"
homepage = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-jaeger-propagator"
repository = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-jaeger-propagator"
readme = "README.md"
categories = [
"development-tools::debugging",
"development-tools::profiling",
"asynchronous",
]
keywords = ["opentelemetry", "jaeger", "propagator"]
license = "Apache-2.0"
edition = "2021"
rust-version = "1.65"


[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
opentelemetry = { version = "0.21", default-features = false, features = [
"trace",
], path = "../opentelemetry" }

tonic = { workspace = true, optional = true }
prost = { version = "0.11.6", optional = true }
prost-types = { version = "0.11.6", optional = true }

[dev-dependencies]
opentelemetry_sdk = { features = ["testing"], path = "../opentelemetry-sdk" }

[features]
default = []
integration_test = []
Loading

0 comments on commit e88a102

Please sign in to comment.