January 2020
Intermediate to advanced
640 pages
16h 56m
English
The gateway service is nothing more than a wrapper on top of a gRPC client. The interesting bit of its implementation is the CollectQuotes method, which is what our main package will invoke to begin a new trace:
func (gw *Gateway) CollectQuotes(ctx context.Context, SKU string) (map[string]float64, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "CollectQuotes") defer span.Finish() res, err := gw.client.GetQuote(ctx, &proto.QuotesRequest{SKU: SKU}) if err != nil { return nil, err } quoteMap := make(map[string]float64, len(res.Quotes)) for _, quote := range res.Quotes { quoteMap[quote.Vendor] = quote.Price } return quoteMap, nil }
Here, we use StartSpanFromContext to create a new named span and embed its trace details ...