mirror of
https://github.com/hanzoai/otel-collector.git
synced 2026-10-30 18:26:25 +00:00
- Go module: github.com/SigNoz/signoz-otel-collector → github.com/hanzoai/otel-collector - All signoz-prefixed packages → o11y-prefixed - Docker: signoz/* → ghcr.io/hanzoai/otel-collector - ClickHouse exporter → Hanzo Datastore - Env vars: SIGNOZ_* → HANZO_* - Directory renames for all processor/receiver/exporter packages
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package traces
|
|
|
|
import (
|
|
"github.com/hanzoai/otel-collector/utils"
|
|
"go.opentelemetry.io/collector/pdata/pcommon"
|
|
"go.opentelemetry.io/collector/pdata/ptrace"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
type OtelSpanRef struct {
|
|
TraceId string `json:"traceId,omitempty"`
|
|
SpanId string `json:"spanId,omitempty"`
|
|
RefType string `json:"refType,omitempty"`
|
|
}
|
|
|
|
func NewOtelSpanRefs(links ptrace.SpanLinkSlice, parentSpanID pcommon.SpanID, traceID pcommon.TraceID) ([]OtelSpanRef, error) {
|
|
parentSpanIDSet := len([8]byte(parentSpanID)) != 0
|
|
if !parentSpanIDSet && links.Len() == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
refsCount := links.Len()
|
|
if parentSpanIDSet {
|
|
refsCount++
|
|
}
|
|
|
|
refs := make([]OtelSpanRef, 0, refsCount)
|
|
|
|
// Put parent span ID at the first place because usually backends look for it
|
|
// as the first CHILD_OF item in the model.SpanRef slice.
|
|
if parentSpanIDSet {
|
|
refs = append(refs, OtelSpanRef{
|
|
TraceId: utils.TraceIDToHexOrEmptyString(traceID),
|
|
SpanId: utils.SpanIDToHexOrEmptyString(parentSpanID),
|
|
RefType: "CHILD_OF",
|
|
})
|
|
}
|
|
|
|
for i := 0; i < links.Len(); i++ {
|
|
link := links.At(i)
|
|
|
|
refs = append(refs, OtelSpanRef{
|
|
TraceId: utils.TraceIDToHexOrEmptyString(link.TraceID()),
|
|
SpanId: utils.SpanIDToHexOrEmptyString(link.SpanID()),
|
|
|
|
// Since Jaeger RefType is not captured in internal data,
|
|
// use SpanRefType_FOLLOWS_FROM by default.
|
|
// SpanRefType_CHILD_OF supposed to be set only from parentSpanID.
|
|
RefType: "FOLLOWS_FROM",
|
|
})
|
|
}
|
|
|
|
return refs, nil
|
|
}
|
|
|
|
func (r *OtelSpanRef) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
|
enc.AddString("traceId", r.TraceId)
|
|
enc.AddString("spanId", r.SpanId)
|
|
enc.AddString("refType", r.RefType)
|
|
return nil
|
|
}
|