Skip to content

Commit

Permalink
refactor(repository): change SaveSpans method signature to accept a s…
Browse files Browse the repository at this point in the history
…lice instead of a pointer to a slice for better usability

refactor(trace_service): update ProcessSpan method to accept a slice instead of a pointer to a slice for consistency
refactor(trace_server): modify Export method to pass spans as a slice instead of a pointer to a slice for improved clarity
  • Loading branch information
HyunSu1768 committed Sep 25, 2024
1 parent 7f7b70b commit 6a7a1a0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/repository/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (

type Repository interface {
SaveTraces(ctx context.Context, traces []*models.Trace) error
SaveSpans(ctx context.Context, spans *[]models.Span) error
SaveSpans(ctx context.Context, spans []models.Span) error
}
8 changes: 4 additions & 4 deletions internal/repository/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ func (r *MongoRepository) SaveTraces(ctx context.Context, traces []*models.Trace
return nil
}

func (r *MongoRepository) SaveSpans(ctx context.Context, spans *[]models.Span) error {
if len(*spans) == 0 {
func (r *MongoRepository) SaveSpans(ctx context.Context, spans []models.Span) error {
if len(spans) == 0 {
return nil
}

documents := make([]interface{}, len(*spans))
for i, span := range *spans {
documents := make([]interface{}, len(spans))
for i, span := range spans {
doc := bson.M{
"id": span.ID,
"traceId": span.TraceID,
Expand Down
2 changes: 1 addition & 1 deletion internal/server/trace_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *TraceServer) Export(ctx context.Context, req *collectorpb.ExportTraceSe
for _, resourceSpans := range req.ResourceSpans {
spans := telemetry.ConvertResourceSpansToSpans(resourceSpans)

err := s.traceService.ProcessSpan(ctx, &spans)
err := s.traceService.ProcessSpan(ctx, spans)
if err != nil {
fmt.Printf("Failed to process span: %v\n", err)
return nil, status.Errorf(codes.Internal, "Failed to process span: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/trace_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func (s *TraceService) ProcessTrace(ctx context.Context, traces []*models.Trace)
return s.repo.SaveTraces(ctx, traces)
}

func (s *TraceService) ProcessSpan(ctx context.Context, spans *[]models.Span) error {
func (s *TraceService) ProcessSpan(ctx context.Context, spans []models.Span) error {
return s.repo.SaveSpans(ctx, spans)
}

0 comments on commit 6a7a1a0

Please sign in to comment.