Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shippingservice] - Add events #344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#332](https://github.com/open-telemetry/opentelemetry-demo/pull/332))
* Add `synthetic_request=true` baggage to load generator requests
([#331](https://github.com/open-telemetry/opentelemetry-demo/pull/331))
* Add span events to shipping service
([#344](https://github.com/open-telemetry/opentelemetry-demo/pull/344))
20 changes: 19 additions & 1 deletion src/shippingservice/src/shipping_service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opentelemetry::trace::{mark_span_as_active, Span, Tracer};
use opentelemetry::trace::{get_active_span, mark_span_as_active, Span, Tracer};
use opentelemetry::{global, propagation::Extractor, KeyValue};
use shop::shipping_service_server::ShippingService;
use shop::{GetQuoteRequest, GetQuoteResponse, Money, ShipOrderRequest, ShipOrderResponse};
Expand Down Expand Up @@ -64,6 +64,10 @@ impl ShippingService for ShippingServer {
let span = tracer.start_with_context("get-quote", &parent_cx);
let _guard = mark_span_as_active(span);

get_active_span(|span| {
span.add_event("Processing get quote request".to_string(), vec![]);
});

let q = create_quote_from_count(itemct);
let reply = GetQuoteResponse {
cost_usd: Some(Money {
Expand All @@ -74,6 +78,13 @@ impl ShippingService for ShippingServer {
};
info!("Sending Quote: {}", q);

get_active_span(|span| {
span.add_event(
"Get quote request completed, response sent back".to_string(),
vec![],
);
});

Ok(Response::new(reply))
}
async fn ship_order(
Expand All @@ -89,10 +100,17 @@ impl ShippingService for ShippingServer {
let mut span = global::tracer("shippingservice/ship-order")
.start_with_context("ship-order", &parent_cx);

span.add_event("Processing shipping order request".to_string(), vec![]);

let tid = create_tracking_id();
span.set_attribute(KeyValue::new("app.shipping.tracking.id", tid.clone()));
info!("Tracking ID Created: {}", tid);

span.add_event(
"Shipping tracking id created, response sent back".to_string(),
vec![],
);

Ok(Response::new(ShipOrderResponse { tracking_id: tid }))
}
}
Expand Down