in pkg/export/transform.go [526:573]
func buildExemplarAttachments(lset labels.Labels) []*anypb.Any {
var projectID, spanID, traceID string
var attachments []*anypb.Any
droppedLabels := make(map[string]string)
lset.Range(func(label labels.Label) {
switch label.Name {
case projectIDLabel:
projectID = label.Value
case spanIDLabel:
spanID = label.Value
case traceIDLabel:
traceID = label.Value
default:
droppedLabels[label.Name] = label.Value
}
})
if projectID != "" && spanID != "" && traceID != "" {
spanCtx, err := anypb.New(&monitoring_pb.SpanContext{
SpanName: fmt.Sprintf(spanContextFormat, projectID, traceID, spanID),
})
if err != nil {
prometheusExemplarsDiscarded.WithLabelValues("error-creating-span-context").Inc()
} else {
attachments = append(attachments, spanCtx)
}
} else {
if projectID != "" {
droppedLabels[projectIDLabel] = projectID
}
if spanID != "" {
droppedLabels[spanIDLabel] = spanID
}
if traceID != "" {
droppedLabels[traceIDLabel] = traceID
}
}
if len(droppedLabels) > 0 {
droppedLabels, err := anypb.New(&monitoring_pb.DroppedLabels{
Label: droppedLabels,
})
if err != nil {
prometheusExemplarsDiscarded.WithLabelValues("error-creating-dropped-labels").Inc()
} else {
attachments = append(attachments, droppedLabels)
}
}
return attachments
}