Skip to content

Commit dfd2688

Browse files
committed
feat(backend): propagate otel trace through queued jobs
## Problem MMseqs2-App lost request trace context as soon as work was enqueued, so request-side and worker-side logs could not be correlated reliably. The existing plain-text logs also only exposed `traceparent`, which is harder to parse in systems like SigNoz or Datadog. ## Solution Add an OTEL trace context payload to `JobRequest`, populate it once from HTTP middleware, and pass it through the job constructors so the same context is available when the worker executes the job. Update job-scoped worker logs to append that context, and include explicit `trace_id` and `span_id` fields derived from `traceparent` for easier downstream parsing.
1 parent 384b4ee commit dfd2688

13 files changed

Lines changed: 289 additions & 105 deletions

backend/complexsearchjob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r ComplexSearchJob) WritePDB(path string) error {
4848
return nil
4949
}
5050

51-
func NewComplexSearchJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, taxfilter string) (JobRequest, error) {
51+
func NewComplexSearchJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, taxfilter string, otelTrace OtelTraceContext) (JobRequest, error) {
5252
job := ComplexSearchJob{
5353
max(strings.Count(query, "HEADER"), 1),
5454
dbs,
@@ -58,11 +58,12 @@ func NewComplexSearchJobRequest(query string, dbs []string, validDbs []Params, m
5858
}
5959

6060
request := JobRequest{
61-
job.Hash(),
62-
StatusPending,
63-
JobComplexSearch,
64-
job,
65-
email,
61+
Id: job.Hash(),
62+
Status: StatusPending,
63+
Type: JobComplexSearch,
64+
Job: job,
65+
Email: email,
66+
OtelTrace: otelTrace.Ptr(),
6667
}
6768

6869
ids := make([]string, 0)

backend/folddiscojob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (r FoldDiscoJob) WritePDB(path string) error {
5353
return nil
5454
}
5555

56-
func NewFoldDiscoJobRequest(query string, motif string, dbs []string, validDbs []Params, resultPath string, email string) (JobRequest, error) {
56+
func NewFoldDiscoJobRequest(query string, motif string, dbs []string, validDbs []Params, resultPath string, email string, otelTrace OtelTraceContext) (JobRequest, error) {
5757
job := FoldDiscoJob{
5858
max(strings.Count(query, "HEADER"), 1),
5959
dbs,
@@ -64,11 +64,12 @@ func NewFoldDiscoJobRequest(query string, motif string, dbs []string, validDbs [
6464
}
6565

6666
request := JobRequest{
67-
job.Hash(),
68-
StatusPending,
69-
JobFoldDisco,
70-
job,
71-
email,
67+
Id: job.Hash(),
68+
Status: StatusPending,
69+
Type: JobFoldDisco,
70+
Job: job,
71+
Email: email,
72+
OtelTrace: otelTrace.Ptr(),
7273
}
7374

7475
ids := make([]string, 0)

backend/foldmasonmsa.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,19 @@ func NewFoldMasonMSAJobRequest(
7777
fileNames []string,
7878
gapOpen int64,
7979
gapExtend int64,
80+
otelTrace OtelTraceContext,
8081
) (JobRequest, error) {
8182
job := FoldMasonMSAJob{
8283
queries,
8384
fileNames,
8485
}
8586
request := JobRequest{
86-
job.Hash(),
87-
StatusPending,
88-
JobFoldMasonMSA,
89-
job,
90-
"",
87+
Id: job.Hash(),
88+
Status: StatusPending,
89+
Type: JobFoldMasonMSA,
90+
Job: job,
91+
Email: "",
92+
OtelTrace: otelTrace.Ptr(),
9193
}
9294
return request, nil
9395
}

backend/indexjob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ func (r IndexJob) Rank() float64 {
2222
return float64(0)
2323
}
2424

25-
func NewIndexJobRequest(path string, email string) (JobRequest, error) {
25+
func NewIndexJobRequest(path string, email string, otelTrace OtelTraceContext) (JobRequest, error) {
2626
job := IndexJob{
2727
path,
2828
}
2929

3030
request := JobRequest{
31-
job.Hash(),
32-
StatusPending,
33-
JobIndex,
34-
job,
35-
email,
31+
Id: job.Hash(),
32+
Status: StatusPending,
33+
Type: JobIndex,
34+
Job: job,
35+
Email: email,
36+
OtelTrace: otelTrace.Ptr(),
3637
}
3738

3839
return request, nil

backend/interfacesearchjob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r InterfaceSearchJob) WritePDB(path string) error {
4848
return nil
4949
}
5050

51-
func NewInterfaceSearchJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, taxfilter string) (JobRequest, error) {
51+
func NewInterfaceSearchJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, taxfilter string, otelTrace OtelTraceContext) (JobRequest, error) {
5252
job := InterfaceSearchJob{
5353
max(strings.Count(query, "HEADER"), 1),
5454
dbs,
@@ -58,11 +58,12 @@ func NewInterfaceSearchJobRequest(query string, dbs []string, validDbs []Params,
5858
}
5959

6060
request := JobRequest{
61-
job.Hash(),
62-
StatusPending,
63-
JobInterfaceSearch,
64-
job,
65-
email,
61+
Id: job.Hash(),
62+
Status: StatusPending,
63+
Type: JobInterfaceSearch,
64+
Job: job,
65+
Email: email,
66+
OtelTrace: otelTrace.Ptr(),
6667
}
6768

6869
ids := make([]string, 0)

backend/jobsystem.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ const (
3131
)
3232

3333
type JobRequest struct {
34-
Id Id `json:"id" validate:"required"`
35-
Status Status `json:"status" validate:"required"`
36-
Type JobType `json:"type" validate:"required"`
37-
Job interface{} `json:"job" validate:"required"`
38-
Email string `json:"email" validate:"omitempty,email"`
34+
Id Id `json:"id" validate:"required"`
35+
Status Status `json:"status" validate:"required"`
36+
Type JobType `json:"type" validate:"required"`
37+
Job interface{} `json:"job" validate:"required"`
38+
Email string `json:"email" validate:"omitempty,email"`
39+
OtelTrace *OtelTraceContext `json:"otelTrace,omitempty"`
40+
}
41+
42+
func (r JobRequest) String() string {
43+
if r.OtelTrace == nil {
44+
return fmt.Sprintf("ticket=%s type=%s status=%s", r.Id, r.Type, r.Status)
45+
}
46+
return fmt.Sprintf("ticket=%s type=%s status=%s%s", r.Id, r.Type, r.Status, *r.OtelTrace)
3947
}
4048

4149
type jobRequest JobRequest

backend/msajob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (r MsaJob) WriteFasta(path string) error {
4343
return nil
4444
}
4545

46-
func NewMsaJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string) (JobRequest, error) {
46+
func NewMsaJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, otelTrace OtelTraceContext) (JobRequest, error) {
4747
job := MsaJob{
4848
max(strings.Count(query, ">"), 1),
4949
dbs,
@@ -52,11 +52,12 @@ func NewMsaJobRequest(query string, dbs []string, validDbs []Params, mode string
5252
}
5353

5454
request := JobRequest{
55-
job.Hash(),
56-
StatusPending,
57-
JobMsa,
58-
job,
59-
email,
55+
Id: job.Hash(),
56+
Status: StatusPending,
57+
Type: JobMsa,
58+
Job: job,
59+
Email: email,
60+
OtelTrace: otelTrace.Ptr(),
6061
}
6162

6263
ids := make([]string, len(validDbs))

backend/pairjob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,20 @@ func (r PairJob) WriteFasta(path string) error {
3434
return nil
3535
}
3636

37-
func NewPairJobRequest(query string, mode string, mail string) (JobRequest, error) {
37+
func NewPairJobRequest(query string, mode string, mail string, otelTrace OtelTraceContext) (JobRequest, error) {
3838
job := PairJob{
3939
max(strings.Count(query, ">"), 1),
4040
mode,
4141
query,
4242
}
4343

4444
request := JobRequest{
45-
job.Hash(),
46-
StatusPending,
47-
JobPair,
48-
job,
49-
mail,
45+
Id: job.Hash(),
46+
Status: StatusPending,
47+
Type: JobPair,
48+
Job: job,
49+
Email: mail,
50+
OtelTrace: otelTrace.Ptr(),
5051
}
5152

5253
return request, nil

backend/searchjob.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func isIn(num string, params []string) int {
6868

6969
var validTaxonFilter = regexp.MustCompile(`^[0-9]+(,!?[0-9]+)*$|^$`).MatchString
7070

71-
func NewSearchJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, taxfilter string) (JobRequest, error) {
71+
func NewSearchJobRequest(query string, dbs []string, validDbs []Params, mode string, resultPath string, email string, taxfilter string, otelTrace OtelTraceContext) (JobRequest, error) {
7272
job := SearchJob{
7373
max(strings.Count(query, ">"), 1),
7474
dbs,
@@ -78,11 +78,12 @@ func NewSearchJobRequest(query string, dbs []string, validDbs []Params, mode str
7878
}
7979

8080
request := JobRequest{
81-
job.Hash(),
82-
StatusPending,
83-
JobSearch,
84-
job,
85-
email,
81+
Id: job.Hash(),
82+
Status: StatusPending,
83+
Type: JobSearch,
84+
Job: job,
85+
Email: email,
86+
OtelTrace: otelTrace.Ptr(),
8687
}
8788

8889
ids := make([]string, len(validDbs))

0 commit comments

Comments
 (0)