Skip to content

Commit

Permalink
Demo app: Event update (#605)
Browse files Browse the repository at this point in the history
* created a confirmation of placed order screen

* moved checkout info to a ViewModel

* passed shipping info to checkout confirmation

* in progress

* changed layout a bit and cleared cart when leaving the confirmation screen using lifecycle owner

* fixed the inability to update payment and shipping info by removing an unnecessary remember

* added email address to the confirmation screen

* added an order.placed event

* updated the Manual Instrumentation bullet

* typo

* Update demo-app/README.md

---------

Co-authored-by: jason plumb <[email protected]>
  • Loading branch information
magda-woj and breedx-splk authored Sep 20, 2024
1 parent b4ab2f4 commit 762a67e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 8 additions & 1 deletion demo-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ The OpenTelemetry Android Demo App currently supports the following features:

* Manual Instrumentation
- Provides access to the OpenTelemetry APIs for manual instrumentation, allowing developers to create custom spans and events as needed.
- Note: The only manual instrumentation that has been added to the demo app so far is an event after clicking on the OpenTelemetry logo.
- See `OtelDemoApplication.kt` for an example of a tracer and an event builder initialization.
- In the app, a custom span is emitted in `MainOtelButton.kt` after clicking on the OpenTelemetry logo button.
- Custom events are emitted:
- in `MainOtelButton.kt` after clicking on the OpenTelemetry logo button,
- in `Navigation.kt` for screen changes in the app,
- in `AstronomyShopActivity.kt` after placing an order in the shop,
- in `Cart.kt` after emptying a cart in the shop.
- Note: Events aren't visible in the Jaeger UI, only in the collector output.

### Known Gaps
As of now, there are a few areas where the instrumentation might not be comprehensive:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import io.opentelemetry.android.demo.shop.ui.products.ProductDetails
import io.opentelemetry.android.demo.shop.ui.products.ProductList
import io.opentelemetry.android.demo.shop.ui.cart.CartViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import io.opentelemetry.android.demo.OtelDemoApplication
import io.opentelemetry.android.demo.shop.ui.cart.CheckoutConfirmationScreen
import io.opentelemetry.android.demo.shop.ui.cart.CheckoutInfoViewModel
import io.opentelemetry.android.demo.shop.ui.cart.InfoScreen
Expand Down Expand Up @@ -103,7 +104,11 @@ fun AstronomyShopScreen() {
}
composable(MainDestinations.CHECKOUT_INFO_ROUTE) {
InfoScreen(
onPlaceOrderClick = {astronomyShopNavController.navigateToCheckoutConfirmation()},
onPlaceOrderClick = {instrumentedPlaceOrder(
astronomyShopNavController = astronomyShopNavController,
cartViewModel = cartViewModel,
checkoutInfoViewModel = checkoutInfoViewModel
)},
upPress = {astronomyShopNavController.upPress()},
checkoutInfoViewModel = checkoutInfoViewModel
)
Expand All @@ -119,3 +124,24 @@ fun AstronomyShopScreen() {
}
}
}

private fun instrumentedPlaceOrder(
astronomyShopNavController: InstrumentedAstronomyShopNavController,
cartViewModel: CartViewModel,
checkoutInfoViewModel: CheckoutInfoViewModel
){
generateOrderPlacedEvent(cartViewModel, checkoutInfoViewModel)
astronomyShopNavController.navigateToCheckoutConfirmation()
}

private fun generateOrderPlacedEvent(
cartViewModel: CartViewModel,
checkoutInfoViewModel: CheckoutInfoViewModel
) {
val eventBuilder = OtelDemoApplication.eventBuilder("otel.demo.app", "order.placed")
eventBuilder
.put("order.total.value", cartViewModel.getTotalPrice())
.put("buyer.state", checkoutInfoViewModel.shippingInfo.state)
.emit()
}

0 comments on commit 762a67e

Please sign in to comment.