Skip to content

Commit 4657643

Browse files
committed
feat: improve logging to demo Triage and Log grouping
1. Remove explicit attributes from log records (we want Log Grouping to extract them) 2. Mark severity as Errors for logs about product not found (LogAI does not override the severity_number set by the log bridge) 3. Remove error event, we have logs now instead 4. Add stacktrace to error log
1 parent d49dbc4 commit 4657643

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/productcatalogservice/main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductReque
287287

288288
// GetProduct will fail on a specific product when feature flag is enabled
289289
if p.checkProductFailure(ctx, req.Id) {
290-
msg := fmt.Sprintf("Error: ProductCatalogService Fail Feature Flag Enabled")
290+
msg := fmt.Sprintf("Product Id Lookup Failed: %s", req.Id)
291+
err := fmt.Errorf("ProductCatalogService Fail Feature Flag Enabled")
291292
span.SetStatus(otelcodes.Error, msg)
292-
span.AddEvent(msg)
293-
log.WithContext(ctx).WithField("request.id", req.Id).Println("ProductCatalogService Fail Feature Flag Enabled")
293+
log.WithContext(ctx).WithError(err).Errorln(msg)
294294
return nil, status.Errorf(codes.Internal, msg)
295295
}
296296

@@ -303,10 +303,10 @@ func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductReque
303303
}
304304

305305
if found == nil {
306-
msg := fmt.Sprintf("Product Not Found: %s", req.Id)
306+
msg := fmt.Sprintf("Product Id Not Found: %s", req.Id)
307307
span.SetStatus(otelcodes.Error, msg)
308308
span.AddEvent(msg)
309-
log.WithContext(ctx).WithField("request.id", req.Id).Error("Product Not Found")
309+
log.WithContext(ctx).Error("Product Not Found")
310310
return nil, status.Errorf(codes.NotFound, msg)
311311
}
312312

@@ -315,7 +315,7 @@ func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductReque
315315
span.SetAttributes(
316316
attribute.String("app.product.name", found.Name),
317317
)
318-
log.WithContext(ctx).WithField("app.product.name", found.Name).Println(msg)
318+
log.WithContext(ctx).Println(msg)
319319
return found, nil
320320
}
321321

0 commit comments

Comments
 (0)