Skip to content

Commit

Permalink
[productcatalog] span attributes update (#336)
Browse files Browse the repository at this point in the history
* update span attributes

* update product catalog span attributes
  • Loading branch information
puckpuck authored Aug 23, 2022
1 parent 42956f2 commit 11834cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions docs/manual_span_attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ This document contains the list of manual Span Attributes used throughout the de

## ProductCatalogService

| Name | Type | Description |
|----------------------|--------|---------------------------------------|
| `app.product.id` | string | Product Id |
| `app.product.name` | string | Product name |
| `app.products.count` | number | Number of products returned in search |
| Name | Type | Description |
|-----------------------------|--------|---------------------------------------|
| `app.product.id` | string | Product Id |
| `app.product.name` | string | Product name |
| `app.products.count` | number | Number of products in catalog |
| `app.products_search.count` | number | Number of products returned in search |

## RecommendationService

Expand Down
8 changes: 4 additions & 4 deletions src/productcatalogservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
)

var (
Expand Down Expand Up @@ -113,7 +113,7 @@ func readCatalogFile() []*pb.Product {
if err := protojson.Unmarshal(catalogJSON, &res); err != nil {
log.Fatalf("Parsing Catalog JSON: %v", err)
}

return res.Products
}

Expand Down Expand Up @@ -186,11 +186,11 @@ func (p *productCatalog) SearchProducts(ctx context.Context, req *pb.SearchProdu
for _, product := range catalog {
if strings.Contains(strings.ToLower(product.Name), strings.ToLower(req.Query)) ||
strings.Contains(strings.ToLower(product.Description), strings.ToLower(req.Query)) {
result = append(result, product)
result = append(result, product)
}
}
span.SetAttributes(
attribute.Int("app.products.count", len(result)),
attribute.Int("app.products_search.count", len(result)),
)
return &pb.SearchProductsResponse{Results: result}, nil
}
Expand Down

0 comments on commit 11834cc

Please sign in to comment.