Skip to content

Commit

Permalink
more trace spans
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Delange committed Jun 17, 2024
1 parent c46b262 commit 64937f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions repositories/decisions_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"github.com/Masterminds/squirrel"
"github.com/cockroachdb/errors"
"github.com/jackc/pgx/v5"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

"github.com/checkmarble/marble-backend/models"
"github.com/checkmarble/marble-backend/models/ast"
"github.com/checkmarble/marble-backend/pure_utils"
"github.com/checkmarble/marble-backend/repositories/dbmodels"
"github.com/checkmarble/marble-backend/utils"
)

type DecisionRepository interface {
Expand Down Expand Up @@ -414,6 +417,13 @@ func (repo *DecisionRepositoryImpl) StoreDecision(
organizationId string,
newDecisionId string,
) error {
tracer := utils.OpenTelemetryTracerFromContext(ctx)
ctx, span := tracer.Start(
ctx,
"DecisionRepository.StoreDecision.store_decision",
trace.WithAttributes(attribute.String("decision_id", newDecisionId)),
trace.WithAttributes(attribute.Int("nb_rule_executions", len(decision.RuleExecutions))))
defer span.End()
if err := validateMarbleDbExecutor(exec); err != nil {
return err
}
Expand Down Expand Up @@ -465,6 +475,12 @@ func (repo *DecisionRepositoryImpl) StoreDecision(
return nil
}

ctx, span = tracer.Start(
ctx,
"DecisionRepository.StoreDecision.store_decision_rules",
trace.WithAttributes(attribute.String("decision_id", newDecisionId)),
trace.WithAttributes(attribute.Int("nb_rule_executions", len(decision.RuleExecutions))))
defer span.End()
builderForRules := NewQueryBuilder().
Insert(dbmodels.TABLE_DECISION_RULES).
Columns(
Expand Down
6 changes: 6 additions & 0 deletions usecases/decision_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ func (usecase *DecisionUsecase) CreateDecision(

decision := models.AdaptScenarExecToDecision(scenarioExecution, payload, nil)

ctx, span = tracer.Start(
ctx,
"DecisionUsecase.CreateDecision.store_decision",
trace.WithAttributes(attribute.String("scenario_id", input.ScenarioId)),
trace.WithAttributes(attribute.Int("nb_rule_executions", len(decision.RuleExecutions))))
defer span.End()
return executor_factory.TransactionReturnValue(ctx, usecase.transactionFactory, func(
tx repositories.Executor,
) (models.DecisionWithRuleExecutions, error) {
Expand Down

0 comments on commit 64937f5

Please sign in to comment.