From d110d123519415e8d0228e3bc74dc46b2d428417 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 15 Nov 2022 13:19:05 -0800 Subject: [PATCH 1/9] encode zipcode as a string --- pb/demo.proto | 2 +- src/frontend/components/CheckoutForm/CheckoutForm.tsx | 7 +++---- src/frontend/components/CheckoutItem/CheckoutItem.tsx | 2 +- src/shippingservice/src/shipping_service.rs | 7 ++++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pb/demo.proto b/pb/demo.proto index 882752e9e2..fef5cb6383 100644 --- a/pb/demo.proto +++ b/pb/demo.proto @@ -134,7 +134,7 @@ message Address { string city = 2; string state = 3; string country = 4; - int32 zip_code = 5; + string zip_code = 5; } // -----------------Currency service----------------- diff --git a/src/frontend/components/CheckoutForm/CheckoutForm.tsx b/src/frontend/components/CheckoutForm/CheckoutForm.tsx index 88f6465c89..a259521a7e 100644 --- a/src/frontend/components/CheckoutForm/CheckoutForm.tsx +++ b/src/frontend/components/CheckoutForm/CheckoutForm.tsx @@ -13,7 +13,7 @@ export interface IFormData { city: string; state: string; country: string; - zipCode: number; + zipCode: string; creditCardNumber: string; creditCardCvv: number; creditCardExpirationYear: number; @@ -45,7 +45,7 @@ const CheckoutForm = ({ onSubmit }: IProps) => { city: 'Mountain View', state: 'CA', country: 'United States', - zipCode: 94043, + zipCode: "94043", creditCardNumber: '4432-8015-6152-0454', creditCardCvv: 672, creditCardExpirationYear: 2030, @@ -99,13 +99,12 @@ const CheckoutForm = ({ onSubmit }: IProps) => { /> diff --git a/src/frontend/components/CheckoutItem/CheckoutItem.tsx b/src/frontend/components/CheckoutItem/CheckoutItem.tsx index fba9adf6b8..05c7a3525b 100644 --- a/src/frontend/components/CheckoutItem/CheckoutItem.tsx +++ b/src/frontend/components/CheckoutItem/CheckoutItem.tsx @@ -19,7 +19,7 @@ const CheckoutItem = ({ }, cost = { currencyCode: 'USD', units: 0, nanos: 0 }, }, - address: { streetAddress = '', city = '', state = '', zipCode = 0, country = '' }, + address: { streetAddress = '', city = '', state = '', zipCode = '', country = '' }, }: IProps) => { const [isCollapsed, setIsCollapsed] = useState(false); diff --git a/src/shippingservice/src/shipping_service.rs b/src/shippingservice/src/shipping_service.rs index 94a14a30d5..38142f25e2 100644 --- a/src/shippingservice/src/shipping_service.rs +++ b/src/shippingservice/src/shipping_service.rs @@ -51,8 +51,9 @@ impl ShippingService for ShippingServer { let parent_cx = global::get_text_map_propagator(|prop| prop.extract(&MetadataMap(request.metadata()))); - let itemct: u32 = request - .into_inner() + let request_message = request.into_inner(); + + let itemct: u32 = request_message .items .into_iter() .fold(0, |accum, cart_item| accum + (cart_item.quantity as u32)); @@ -62,8 +63,8 @@ impl ShippingService for ShippingServer { // check out the create_quote_from_count method to see how we use the span created here let tracer = global::tracer("shippingservice/get-quote"); let mut span = tracer.start_with_context("get-quote", &parent_cx); - span.add_event("Processing get quote request".to_string(), vec![]); + span.set_attribute(KeyValue::new("app.shipping.zip_code", request_message.address.unwrap().zip_code)); let q = match create_quote_from_count(itemct) .with_context(Context::current_with_span(span)) From 28e761908f65e462c14f2eeba2faf0c048b27061 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 15 Nov 2022 13:24:51 -0800 Subject: [PATCH 2/9] encode zipcode as a string --- src/loadgenerator/locustfile.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 4dd90a9352..7abe25e5a0 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -50,7 +50,7 @@ "email": "larry_sergei@example.com", "address": { "streetAddress": "1600 Amphitheatre Parkway", - "zipCode": 94043, + "zipCode": "94043", "city": "Mountain View", "state": "CA", "country": "United States", @@ -67,7 +67,7 @@ "email": "bill@example.com", "address": { "streetAddress": "One Microsoft Way", - "zipCode": 98052, + "zipCode": "98052", "city": "Redmond", "state": "WA", "country": "United States", @@ -84,7 +84,7 @@ "email": "steve@example.com", "address": { "streetAddress": "One Apple Park Way", - "zipCode": 95014, + "zipCode": "95014", "city": "Cupertino", "state": "CA", "country": "United States", @@ -101,7 +101,7 @@ "email": "mark@example.com", "address": { "streetAddress": "1 Hacker Way", - "zipCode": 94025, + "zipCode": "94025", "city": "Menlo Park", "state": "CA", "country": "United States", @@ -118,7 +118,7 @@ "email": "jeff@example.com", "address": { "streetAddress": "410 Terry Ave N", - "zipCode": 98109, + "zipCode": "98109", "city": "Seattle", "state": "WA", "country": "United States", @@ -135,7 +135,7 @@ "email": "reed@example.com", "address": { "streetAddress": "100 Winchester Circle", - "zipCode": 95032, + "zipCode": "95032", "city": "Los Gatos", "state": "CA", "country": "United States", @@ -152,7 +152,7 @@ "email": "tobias@example.com", "address": { "streetAddress": "150 Elgin St", - "zipCode": 214, + "zipCode": ""N9J3"Z6", "city": "Ottawa", "state": "ON", "country": "Canada", @@ -169,7 +169,7 @@ "email": "jack@example.com", "address": { "streetAddress": "1355 Market St", - "zipCode": 94103, + "zipCode": "94103", "city": "San Francisco", "state": "CA", "country": "United States", @@ -186,7 +186,7 @@ "email": "moore@example.com", "address": { "streetAddress": "2200 Mission College Blvd", - "zipCode": 95054, + "zipCode": "95054", "city": "Santa Clara", "state": "CA", "country": "United States", From 76e18ee2728642a884538a7f2e10911147e5873d Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 15 Nov 2022 13:28:43 -0800 Subject: [PATCH 3/9] encode zipcode as a string --- src/loadgenerator/locustfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 7abe25e5a0..d58ec9e8f0 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -152,7 +152,7 @@ "email": "tobias@example.com", "address": { "streetAddress": "150 Elgin St", - "zipCode": ""N9J3"Z6", + "zipCode": "N9J3Z6", "city": "Ottawa", "state": "ON", "country": "Canada", From fda8cf1554b7ec1f282d454083a4a59d43096e18 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 15 Nov 2022 15:14:59 -0800 Subject: [PATCH 4/9] add zip_code attribute --- docs/manual_span_attributes.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/manual_span_attributes.md b/docs/manual_span_attributes.md index 31c5828802..bb8fe232bd 100644 --- a/docs/manual_span_attributes.md +++ b/docs/manual_span_attributes.md @@ -116,8 +116,9 @@ This document contains the list of manual Span Attributes used throughout the de ## ShippingService -| Name | Type | Description | -|----------------------------|--------|----------------------| -| `app.shipping.cost.total` | number | Total shipping cost | -| `app.shipping.items.count` | number | Total items to ship | -| `app.shipping.tracking.id` | string | Shipping tracking Id | +| Name | Type | Description | +|----------------------------|--------|-------------------------------| +| `app.shipping.cost.total` | number | Total shipping cost | +| `app.shipping.items.count` | number | Total items to ship | +| `app.shipping.tracking.id` | string | Shipping tracking Id | +| `app.shipping.zip_code` | string | Zip code used to ship item(s) | From 06aa8710808b3bb94564ef30492020c2442492b6 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 15 Nov 2022 15:44:20 -0800 Subject: [PATCH 5/9] update zipCode to string type --- test/data.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/data.json b/test/data.json index 85db134e2c..e575f2b314 100644 --- a/test/data.json +++ b/test/data.json @@ -17,7 +17,7 @@ "city": "Seattle", "state": "Washington", "country": "United States", - "zipCode": 98109 + "zipCode": "98109" }, "email": "amazon@example.com", "creditCard": { @@ -50,7 +50,7 @@ "city": "Mountain View", "state": "California", "country": "United States", - "zipCode": 94043 + "zipCode": "94043" }, "items": [ { @@ -90,7 +90,7 @@ "city": "Redmond", "state": "Washington", "country": "United States", - "zipCode": 98052 + "zipCode": "98052" }, "items": [ { From 64dcd54e2b748322169264235d24ea3d7a31a0d4 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 15 Nov 2022 15:55:07 -0800 Subject: [PATCH 6/9] update zipCode to string type --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d43282d2..07ef136d16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -138,3 +138,5 @@ significant modifications will be credited to OpenTelemetry Authors. ([#569](https://github.com/open-telemetry/opentelemetry-demo/pull/569)) * Optimize GitHub Builds and fix broken emulation of featureflag ([#536](https://github.com/open-telemetry/opentelemetry-demo/pull/536)) +* Change ZipCode data type from int to string +([#587](https://github.com/open-telemetry/opentelemetry-demo/pull/587)) From eface651d674f1fd5bcf381c3a037ce6264cb1b4 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Fri, 18 Nov 2022 21:41:23 -0500 Subject: [PATCH 7/9] add address to shipping api call --- src/frontend/components/CartItems/CartItems.tsx | 9 ++++++++- src/frontend/gateways/Api.gateway.ts | 3 ++- src/frontend/gateways/rpc/Shipping.gateway.ts | 6 +++--- src/frontend/pages/api/shipping.ts | 4 ++-- src/paymentservice/package-lock.json | 5 +++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/frontend/components/CartItems/CartItems.tsx b/src/frontend/components/CartItems/CartItems.tsx index aee57995ab..92a46952dd 100644 --- a/src/frontend/components/CartItems/CartItems.tsx +++ b/src/frontend/components/CartItems/CartItems.tsx @@ -15,8 +15,15 @@ interface IProps { const CartItems = ({ productList, shouldShowPrice = true }: IProps) => { const { selectedCurrency } = useCurrency(); + const address = { + streetAddress: '1600 Amphitheatre Parkway', + city: 'Mountain View', + state: 'CA', + country: 'United States', + zipCode: "94043", + }; const { data: shippingConst = { units: 0, currencyCode: 'USD', nanos: 0 } } = useQuery('shipping', () => - ApiGateway.getShippingCost(productList, selectedCurrency) + ApiGateway.getShippingCost(productList, selectedCurrency, address) ); const total = useMemo( diff --git a/src/frontend/gateways/Api.gateway.ts b/src/frontend/gateways/Api.gateway.ts index 5d495d4b8e..33aab0caa7 100644 --- a/src/frontend/gateways/Api.gateway.ts +++ b/src/frontend/gateways/Api.gateway.ts @@ -36,12 +36,13 @@ const ApiGateway = () => ({ }); }, - getShippingCost(itemList: IProductCartItem[], currencyCode: string) { + getShippingCost(itemList: IProductCartItem[], currencyCode: string, address: {}) { return request({ url: `${basePath}/shipping`, queryParams: { itemList: JSON.stringify(itemList.map(({ productId, quantity }) => ({ productId, quantity }))), currencyCode, + address, }, }); }, diff --git a/src/frontend/gateways/rpc/Shipping.gateway.ts b/src/frontend/gateways/rpc/Shipping.gateway.ts index b64c266fe3..14ebcb3acf 100644 --- a/src/frontend/gateways/rpc/Shipping.gateway.ts +++ b/src/frontend/gateways/rpc/Shipping.gateway.ts @@ -1,14 +1,14 @@ import { ChannelCredentials } from '@grpc/grpc-js'; -import { CartItem, GetQuoteResponse, ShippingServiceClient } from '../../protos/demo'; +import { Address, CartItem, GetQuoteResponse, ShippingServiceClient } from '../../protos/demo'; const { SHIPPING_SERVICE_ADDR = '' } = process.env; const client = new ShippingServiceClient(SHIPPING_SERVICE_ADDR, ChannelCredentials.createInsecure()); const AdGateway = () => ({ - getShippingCost(itemList: CartItem[]) { + getShippingCost(itemList: CartItem[], address: Address) { return new Promise((resolve, reject) => - client.getQuote({ items: itemList, address: undefined }, (error, response) => + client.getQuote({ items: itemList, address: address }, (error, response) => error ? reject(error) : resolve(response) ) ); diff --git a/src/frontend/pages/api/shipping.ts b/src/frontend/pages/api/shipping.ts index 280d666f88..f5b9405f89 100644 --- a/src/frontend/pages/api/shipping.ts +++ b/src/frontend/pages/api/shipping.ts @@ -9,8 +9,8 @@ type TResponse = Money | Empty; const handler = async ({ method, query }: NextApiRequest, res: NextApiResponse) => { switch (method) { case 'GET': { - const { itemList = '', currencyCode = 'USD' } = query; - const { costUsd } = await ShippingGateway.getShippingCost(JSON.parse(itemList as string) as CartItem[]); + const { itemList = '', currencyCode = 'USD', address = '' } = query; + const { costUsd } = await ShippingGateway.getShippingCost(JSON.parse(itemList as string, JSON.parse(address as string)) as CartItem[]); const cost = await CurrencyGateway.convert(costUsd!, currencyCode as string); return res.status(200).json(cost!); diff --git a/src/paymentservice/package-lock.json b/src/paymentservice/package-lock.json index 23858ae5d9..64e3aafec9 100644 --- a/src/paymentservice/package-lock.json +++ b/src/paymentservice/package-lock.json @@ -12,11 +12,12 @@ "@grpc/grpc-js": "1.7.3", "@grpc/proto-loader": "^0.7.3", "@opentelemetry/api": "^1.2.0", - "@opentelemetry/api-metrics": "^0.33.0", + "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/auto-instrumentations-node": "0.33.1", "@opentelemetry/core": "1.7.0", - "@opentelemetry/exporter-metrics-otlp-grpc": "^0.33.0", + "@opentelemetry/exporter-metrics-otlp-grpc": "0.33.0", "@opentelemetry/exporter-trace-otlp-grpc": "0.33.0", + "@opentelemetry/sdk-metrics": "0.33.0", "@opentelemetry/sdk-node": "0.33.0", "grpc-js-health-check": "^1.0.2", "pino": "8.7.0", From 46ffb403044dd0e4b7ccaeff38c9bce9473ae4e6 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Fri, 18 Nov 2022 23:29:44 -0500 Subject: [PATCH 8/9] add address to shipping api call --- src/frontend/components/CartItems/CartItems.tsx | 4 ++-- src/frontend/gateways/Api.gateway.ts | 6 +++--- src/frontend/pages/api/shipping.ts | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/frontend/components/CartItems/CartItems.tsx b/src/frontend/components/CartItems/CartItems.tsx index 92a46952dd..b192ff245d 100644 --- a/src/frontend/components/CartItems/CartItems.tsx +++ b/src/frontend/components/CartItems/CartItems.tsx @@ -1,7 +1,7 @@ import { useMemo } from 'react'; import { useQuery } from 'react-query'; import ApiGateway from '../../gateways/Api.gateway'; -import { Money } from '../../protos/demo'; +import { Address, Money } from '../../protos/demo'; import { useCurrency } from '../../providers/Currency.provider'; import { IProductCartItem } from '../../types/Cart'; import ProductPrice from '../ProductPrice'; @@ -15,7 +15,7 @@ interface IProps { const CartItems = ({ productList, shouldShowPrice = true }: IProps) => { const { selectedCurrency } = useCurrency(); - const address = { + const address: Address = { streetAddress: '1600 Amphitheatre Parkway', city: 'Mountain View', state: 'CA', diff --git a/src/frontend/gateways/Api.gateway.ts b/src/frontend/gateways/Api.gateway.ts index 33aab0caa7..1b754084d3 100644 --- a/src/frontend/gateways/Api.gateway.ts +++ b/src/frontend/gateways/Api.gateway.ts @@ -1,4 +1,4 @@ -import { Ad, Cart, CartItem, Money, PlaceOrderRequest, Product } from '../protos/demo'; +import { Ad, Address, Cart, CartItem, Money, PlaceOrderRequest, Product } from '../protos/demo'; import { IProductCart, IProductCartItem, IProductCheckout } from '../types/Cart'; import request from '../utils/Request'; import SessionGateway from './Session.gateway'; @@ -36,13 +36,13 @@ const ApiGateway = () => ({ }); }, - getShippingCost(itemList: IProductCartItem[], currencyCode: string, address: {}) { + getShippingCost(itemList: IProductCartItem[], currencyCode: string, address: Address) { return request({ url: `${basePath}/shipping`, queryParams: { itemList: JSON.stringify(itemList.map(({ productId, quantity }) => ({ productId, quantity }))), currencyCode, - address, + address: JSON.stringify(address), }, }); }, diff --git a/src/frontend/pages/api/shipping.ts b/src/frontend/pages/api/shipping.ts index f5b9405f89..9a1cf2520c 100644 --- a/src/frontend/pages/api/shipping.ts +++ b/src/frontend/pages/api/shipping.ts @@ -1,7 +1,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import InstrumentationMiddleware from '../../utils/telemetry/InstrumentationMiddleware'; import ShippingGateway from '../../gateways/rpc/Shipping.gateway'; -import { CartItem, Empty, Money } from '../../protos/demo'; +import { Address, CartItem, Empty, Money } from '../../protos/demo'; import CurrencyGateway from '../../gateways/rpc/Currency.gateway'; type TResponse = Money | Empty; @@ -10,7 +10,8 @@ const handler = async ({ method, query }: NextApiRequest, res: NextApiResponse Date: Fri, 18 Nov 2022 23:36:44 -0500 Subject: [PATCH 9/9] zipcode as string --- src/loadgenerator/locustfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index d58ec9e8f0..afcf29cb78 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -152,7 +152,7 @@ "email": "tobias@example.com", "address": { "streetAddress": "150 Elgin St", - "zipCode": "N9J3Z6", + "zipCode": "K2P1L4", "city": "Ottawa", "state": "ON", "country": "Canada",