Skip to content

Commit

Permalink
fix: grpc tracing context being unused due to http server trace context
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Nov 28, 2024
1 parent 536d83a commit bf3b62c
Show file tree
Hide file tree
Showing 12 changed files with 3,447 additions and 3,129 deletions.
71 changes: 60 additions & 11 deletions gen/go/proto/resources/documents/workflow.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions gen/go/proto/resources/documents/workflow.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions gen/go/proto/services/docstore/workflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package docstore

import (
"context"
"database/sql"
"fmt"

"github.com/fivenet-app/fivenet/gen/go/proto/resources/common/cron"
"github.com/fivenet-app/fivenet/gen/go/proto/resources/documents"
"github.com/fivenet-app/fivenet/pkg/croner"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
"go.uber.org/fx"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

type WorkflowParams struct {
fx.In

LC fx.Lifecycle

Logger *zap.Logger
DB *sql.DB
TP *tracesdk.TracerProvider
Cron croner.ICron
CronHandlers *croner.Handlers
}

type Workflow struct {
logger *zap.Logger
tracer trace.Tracer

db *sql.DB
}

func NewWorkflow(p WorkflowParams) *Workflow {
w := &Workflow{
logger: p.Logger,
tracer: p.TP.Tracer("docstore_workflow"),
db: p.DB,
}

p.LC.Append(fx.StartHook(func(ctx context.Context) error {
if err := p.Cron.RegisterCronjob(ctx, &cron.Cronjob{
Name: "docstore.workflow_run",
Schedule: "@always", // Every minute
}); err != nil {
return err
}

return nil
}))

p.CronHandlers.Add("docstore.workflow_run", func(ctx context.Context, data *cron.CronjobData) error {
ctx, span := w.tracer.Start(ctx, "docstore.workflow_run")
defer span.End()

dest := &documents.CronData{}
if err := anypb.UnmarshalTo(data.Data, dest, proto.UnmarshalOptions{}); err != nil {
return fmt.Errorf("failed to unmarshal document workflow cron data. %w", err)
}

if err := w.handle(ctx, dest); err != nil {
return fmt.Errorf("error during docstore workflow handling. %w", err)
}

if err := data.Data.MarshalFrom(dest); err != nil {
return fmt.Errorf("failed to marshal document workflow cron data. %w", err)
}

return nil
})

return w
}

func (w *Workflow) handle(ctx context.Context, data *documents.CronData) error {
// TODO

return nil
}
2 changes: 2 additions & 0 deletions gen/go/proto/services/wiki/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func (s *Server) ListPages(ctx context.Context, req *ListPagesRequest) (*ListPag
}

func (s *Server) GetPage(ctx context.Context, req *GetPageRequest) (*GetPageResponse, error) {
trace.SpanFromContext(ctx).SetAttributes(attribute.Int64("fivenet.wiki.page_id", int64(req.Id)))

userInfo := auth.MustGetUserInfoFromContext(ctx)

auditEntry := &model.FivenetAuditLog{
Expand Down
Loading

0 comments on commit bf3b62c

Please sign in to comment.