Skip to content

Commit

Permalink
fix: Add missing telemetry for Templates API endpoints
Browse files Browse the repository at this point in the history
Missing attributes to identify which project suffers from using
templates
  • Loading branch information
Matovidlo committed Nov 25, 2024
1 parent 849e4bf commit e7eb1ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *Project) MappersFor(state *state.State) (mapper.Mappers, error) {
return MappersFor(state, p.deps)
}

func (p *Project) LoadState(options loadState.Options, d dependencies) (*State, error) {
func (p *Project) LoadState(ctx context.Context, options loadState.Options, d dependencies) (*State, error) {
p.deps = d

// Use filter from the project manifest
Expand All @@ -106,7 +106,7 @@ func (p *Project) LoadState(options loadState.Options, d dependencies) (*State,
}

// Load state
s, err := loadState.Run(p.ctx, p, loadOptionsWithFilter, d)
s, err := loadState.Run(ctx, p, loadOptionsWithFilter, d)
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion internal/pkg/service/templates/api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-utils/pkg/deepcopy"
"github.com/spf13/cast"
"go.opentelemetry.io/otel/attribute"

"github.com/keboola/keboola-as-code/internal/pkg/filesystem"
"github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs"
"github.com/keboola/keboola-as-code/internal/pkg/log"
"github.com/keboola/keboola-as-code/internal/pkg/model"
"github.com/keboola/keboola-as-code/internal/pkg/project"
"github.com/keboola/keboola-as-code/internal/pkg/service/common/ctxattr"
. "github.com/keboola/keboola-as-code/internal/pkg/service/common/errors"
"github.com/keboola/keboola-as-code/internal/pkg/service/common/etcdop"
"github.com/keboola/keboola-as-code/internal/pkg/service/common/task"
Expand Down Expand Up @@ -255,6 +257,9 @@ func (s *service) UseTemplateVersion(ctx context.Context, d dependencies.Project
}

func (s *service) InstancesIndex(ctx context.Context, d dependencies.ProjectRequestScope, payload *InstancesIndexPayload) (res *Instances, err error) {
_, span := d.Telemetry().Tracer().Start(ctx, "api.server.templates.service.InstancesIndex")
defer span.End(&err)

branchKey, err := getBranch(ctx, d, payload.Branch)
if err != nil {
return nil, err
Expand All @@ -270,8 +275,12 @@ func (s *service) InstancesIndex(ctx context.Context, d dependencies.ProjectRequ
m.Filter().SetAllowedBranches(model.AllowedBranches{model.AllowedBranch(cast.ToString(branchKey.ID))})
prj := project.NewWithManifest(ctx, fs, m)

ctx = ctxattr.ContextWith(ctx,
attribute.String("branch.id", branchKey.ID.String()),
attribute.String("project.id", d.ProjectID().String()),
)
// Load project state
prjState, err := prj.LoadState(loadState.Options{LoadRemoteState: true}, d)
prjState, err := prj.LoadState(ctx, loadState.Options{LoadRemoteState: true}, d)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e7eb1ce

Please sign in to comment.