Skip to content

Commit

Permalink
Merge branch 'main' into sync-gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Dec 12, 2023
2 parents 8ef2526 + 1dd269a commit c1ac8dd
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 101 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contributing to opentelemetry-rust

The Rust special interest group (SIG) meets weekly on Tuesdays at 8 AM Pacific
Time (16:00 UTC). The meeting is subject to change depending on contributors'
The Rust special interest group (SIG) meets weekly on Tuesdays at 9 AM Pacific
Time. The meeting is subject to change depending on contributors'
availability. Check the [OpenTelemetry community
calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com)
for specific dates and for Zoom meeting links. "OTel Rust SIG" is the name of
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ maintained by the `opentelemetry` project. These include:
Application Insights] exporter.
* [`opentelemetry-tide`] provides integration for the [`Tide`] web server and
ecosystem.
* [`trillium-opentelemetry`] provides metrics instrumentation for [`trillium`] http servers following [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md).

If you're the maintainer of an `opentelemetry` ecosystem crate not listed
above, please let us know! We'd love to add your project to the list!
Expand Down Expand Up @@ -161,6 +162,8 @@ above, please let us know! We'd love to add your project to the list!
[`Tide`]: https://crates.io/crates/tide
[`opentelemetry-stackdriver`]: https://crates.io/crates/opentelemetry-stackdriver
[Cloud Trace]: https://cloud.google.com/trace/
[`trillium-opentelemetry`]: https://github.com/trillium-rs/trillium-opentelemetry
[`trillium`]: https://github.com/trillium-rs/trillium

## Supported Rust Versions

Expand All @@ -179,8 +182,8 @@ this policy.

See the [contributing file](CONTRIBUTING.md).

The Rust special interest group (SIG) meets weekly on Tuesdays at 8 AM Pacific
Time (16:00 UTC). The meeting is subject to change depending on contributors'
The Rust special interest group (SIG) meets weekly on Tuesdays at 9 AM Pacific
Time. The meeting is subject to change depending on contributors'
availability. Check the [OpenTelemetry community
calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com)
for specific dates and for Zoom meeting links. "OTel Rust SIG" is the name of
Expand Down
10 changes: 3 additions & 7 deletions examples/tracing-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ name = "grpc-client"
path = "src/client.rs"

[dependencies]
opentelemetry = { version = "0.20" }
opentelemetry_sdk = { version = "0.20", features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "0.19", features = ["rt-tokio"] }
opentelemetry = { path = "../../opentelemetry" }
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["rt-tokio"]}
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["trace"] }
prost = "0.11"
tokio = { version = "1.28", features = ["full"] }
tonic = "0.9.2"
tracing = "0.1"
tracing-futures = "0.2"
tracing-opentelemetry = "0.20"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[build-dependencies]
tonic-build = "0.9.2"
70 changes: 43 additions & 27 deletions examples/tracing-grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
use hello_world::greeter_client::GreeterClient;
use hello_world::HelloRequest;
use opentelemetry::{global, propagation::Injector};
use tracing::*;
use tracing_futures::Instrument;
use tracing_opentelemetry::OpenTelemetrySpanExt;
use tracing_subscriber::prelude::*;
use opentelemetry_sdk::{
propagation::TraceContextPropagator, runtime::Tokio, trace::TracerProvider,
};
use opentelemetry_stdout::SpanExporter;

use opentelemetry::{
trace::{SpanKind, TraceContextExt, Tracer},
Context, KeyValue,
};

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)
.build();

global::set_tracer_provider(provider);
}

struct MetadataMap<'a>(&'a mut tonic::metadata::MetadataMap);

Expand All @@ -24,45 +39,46 @@ pub mod hello_world {
tonic::include_proto!("helloworld");
}

#[instrument]
async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut client = GreeterClient::connect("http://[::1]:50051")
.instrument(info_span!("client connect"))
.await?;
let tracer = global::tracer("example/client");
let span = tracer
.span_builder(String::from("Greeter/client"))
.with_kind(SpanKind::Client)
.with_attributes(vec![KeyValue::new("component", "grpc")])
.start(&tracer);
let cx = Context::current_with_span(span);
let mut client = GreeterClient::connect("http://[::1]:50051").await?;

let mut request = tonic::Request::new(HelloRequest {
name: "Tonic".into(),
});

global::get_text_map_propagator(|propagator| {
propagator.inject_context(
&tracing::Span::current().context(),
&mut MetadataMap(request.metadata_mut()),
)
propagator.inject_context(&cx, &mut MetadataMap(request.metadata_mut()))
});

let response = client
.say_hello(request)
.instrument(info_span!("say_hello"))
.await?;
let response = client.say_hello(request).await;

let status = match response {
Ok(_res) => "OK".to_string(),
Err(status) => {
// Access the status code
let status_code = status.code();
status_code.to_string()
}
};
cx.span().add_event(
"Got response!".to_string(),
vec![KeyValue::new("status", status)],
);

info!("Response received: {:?}", response);
Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_agent_pipeline()
.with_service_name("grpc-client")
.install_simple()?;
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new("INFO"))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.try_init()?;

init_tracer();
greet().await?;

opentelemetry::global::shutdown_tracer_provider();

Ok(())
Expand Down
46 changes: 28 additions & 18 deletions examples/tracing-grpc/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use opentelemetry::{global, propagation::Extractor};
use opentelemetry::{
global,
propagation::Extractor,
trace::{Span, SpanKind, Tracer},
};
use opentelemetry_sdk::{
propagation::TraceContextPropagator, runtime::Tokio, trace::TracerProvider,
};
use opentelemetry_stdout::SpanExporter;
use tonic::{transport::Server, Request, Response, Status};
use tracing::*;
use tracing_opentelemetry::OpenTelemetrySpanExt;
use tracing_subscriber::prelude::*;

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)
.build();

global::set_tracer_provider(provider);
}

#[allow(clippy::derive_partial_eq_without_eq)] // tonic don't derive Eq for generated types. We shouldn't manually change it.
pub mod hello_world {
Expand All @@ -31,28 +46,30 @@ impl<'a> Extractor for MetadataMap<'a> {
}
}

#[instrument]
fn expensive_fn(to_print: String) {
fn expensive_fn<S: Span>(to_print: String, span: &mut S) {
std::thread::sleep(std::time::Duration::from_millis(20));
info!("{}", to_print);
span.add_event(to_print, vec![]);
}

#[derive(Debug, Default)]
pub struct MyGreeter {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
#[instrument]
async fn say_hello(
&self,
request: Request<HelloRequest>, // Accept request of type HelloRequest
) -> Result<Response<HelloReply>, Status> {
let parent_cx =
global::get_text_map_propagator(|prop| prop.extract(&MetadataMap(request.metadata())));
tracing::Span::current().set_parent(parent_cx);
let tracer = global::tracer("example/server");
let mut span = tracer
.span_builder("Greeter/server")
.with_kind(SpanKind::Server)
.start_with_context(&tracer, &parent_cx);

let name = request.into_inner().name;
expensive_fn(format!("Got name: {name:?}"));
expensive_fn(format!("Got name: {name:?}"), &mut span);

// Return an instance of type HelloReply
let reply = hello_world::HelloReply {
Expand All @@ -65,14 +82,7 @@ impl Greeter for MyGreeter {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_agent_pipeline()
.with_service_name("grpc-server")
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new("INFO"))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.try_init()?;
init_tracer();

let addr = "[::1]:50051".parse()?;
let greeter = MyGreeter::default();
Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-appender-tracing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
### Added

- Add log appender versions to loggers (#1182)
- New experimental metadata attributes feature (experimental\_metadata\_attributes) [#1380](https://github.com/open-telemetry/opentelemetry-rust/pull/1380)
- Experimental new attributes for tracing metadata
- Fixes the following for events emitted using log crate
- Normalized metadata fields
- Remove redundant metadata

## v0.1.0

Expand Down
9 changes: 6 additions & 3 deletions opentelemetry-appender-tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ license = "Apache-2.0"
rust-version = "1.65"

[dependencies]
log = { version = "0.4", optional = true }
opentelemetry = { version = "0.21", path = "../opentelemetry", features = ["logs"] }
opentelemetry_sdk = { version = "0.21", path = "../opentelemetry-sdk", features = ["logs"] }
tracing = {version = "0.1", default-features = false, features = ["std"]}
tracing-core = "0.1.31"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["registry", "std"] }
tracing-core = "0.1"
tracing-log = { version = "0.2", optional = true }
tracing-subscriber = { version = "0.3", default-features = false, features = ["registry", "std"] }
once_cell = "1.13.0"

[dev-dependencies]
opentelemetry-stdout = { path = "../opentelemetry-stdout", features = ["logs"] }

[features]
experimental_metadata_attributes = ["dep:tracing-log"]
logs_level_enabled = ["opentelemetry/logs_level_enabled", "opentelemetry_sdk/logs_level_enabled"]
default = ["logs_level_enabled"]
testing = ["opentelemetry_sdk/testing"]
testing = ["opentelemetry_sdk/testing", "dep:tracing-log", "dep:log"]
Loading

0 comments on commit c1ac8dd

Please sign in to comment.