Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(trace): support mqtt 5 trace #3394

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/io/mqtt/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"github.com/lf-edge/ekuiper/v2/internal/conf"
"github.com/lf-edge/ekuiper/v2/internal/pkg/util"
"github.com/lf-edge/ekuiper/v2/internal/topo/node/tracenode"
"github.com/lf-edge/ekuiper/v2/pkg/cast"
"github.com/lf-edge/ekuiper/v2/pkg/connection"
)
Expand Down Expand Up @@ -115,7 +116,16 @@
}
}
}

traced, _, span := tracenode.TraceInput(ctx, item, fmt.Sprintf("%s_emit", ctx.GetOpId()))
if traced {
defer span.End()
traceID := span.SpanContext().TraceID()
spanID := span.SpanContext().SpanID()
if props == nil {
props = make(map[string]string)
}
props["traceparent"] = tracenode.BuildTraceParentId(traceID, spanID)

Check warning on line 127 in internal/io/mqtt/sink.go

View check run for this annotation

Codecov / codecov/patch

internal/io/mqtt/sink.go#L121-L127

Added lines #L121 - L127 were not covered by tests
}
ctx.GetLogger().Debugf("publishing to topic %s", tpc)
return ms.cli.Publish(ctx, tpc, ms.adconf.Qos, ms.adconf.Retained, item.Raw(), props)
}
Expand Down
9 changes: 7 additions & 2 deletions internal/io/mqtt/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@

func (ms *SourceConnector) onMessage(ctx api.StreamContext, msg any, ingest api.BytesIngest) {
rcvTime := timex.GetNow()
payload, meta, _ := ms.cli.ParseMsg(ctx, msg)
payload, meta, props := ms.cli.ParseMsg(ctx, msg)
if ms.eof != nil && ms.eofPayload != nil && bytes.Equal(ms.eofPayload, payload) {
ms.eof(ctx)
return
}
// TODO property trace
// extract trace id
if props != nil {
if tid, ok := props["traceparent"]; ok {
meta["traceId"] = tid
}

Check warning on line 125 in internal/io/mqtt/source.go

View check run for this annotation

Codecov / codecov/patch

internal/io/mqtt/source.go#L123-L125

Added lines #L123 - L125 were not covered by tests
}
ingest(ctx, payload, meta, rcvTime)
}

Expand Down
Loading