-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into standard-adjusters
- Loading branch information
Showing
11 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package jptrace | ||
|
||
import ( | ||
jaegerTranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
// ProtoFromTraces converts OpenTelemetry traces (ptrace.Traces) | ||
// to Jaeger model batches ([]*model.Batch). | ||
func ProtoFromTraces(traces ptrace.Traces) []*model.Batch { | ||
batches := jaegerTranslator.ProtoFromTraces(traces) | ||
spanMap := createSpanMapFromBatches(batches) | ||
transferWarnings(traces, spanMap) | ||
return batches | ||
} | ||
|
||
func createSpanMapFromBatches(batches []*model.Batch) map[model.SpanID]*model.Span { | ||
spanMap := make(map[model.SpanID]*model.Span) | ||
for _, batch := range batches { | ||
for _, span := range batch.Spans { | ||
spanMap[span.SpanID] = span | ||
} | ||
} | ||
return spanMap | ||
} | ||
|
||
func transferWarnings(traces ptrace.Traces, spanMap map[model.SpanID]*model.Span) { | ||
resources := traces.ResourceSpans() | ||
for i := 0; i < resources.Len(); i++ { | ||
scopes := resources.At(i).ScopeSpans() | ||
for j := 0; j < scopes.Len(); j++ { | ||
spans := scopes.At(j).Spans() | ||
for k := 0; k < spans.Len(); k++ { | ||
otelSpan := spans.At(k) | ||
warnings := GetWarnings(otelSpan) | ||
span := spanMap[model.SpanIDFromOTEL(otelSpan.SpanID())] | ||
span.Warnings = append(span.Warnings, warnings...) | ||
// filter out the warning tag | ||
span.Tags = filterTags(span.Tags, warningsAttribute) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func filterTags(tags []model.KeyValue, keyToRemove string) []model.KeyValue { | ||
var filteredTags []model.KeyValue | ||
for _, tag := range tags { | ||
if tag.Key != keyToRemove { | ||
filteredTags = append(filteredTags, tag) | ||
} | ||
} | ||
return filteredTags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package jptrace | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
func TestProtoFromTraces_AddsWarnings(t *testing.T) { | ||
traces := ptrace.NewTraces() | ||
rs1 := traces.ResourceSpans().AppendEmpty() | ||
ss1 := rs1.ScopeSpans().AppendEmpty() | ||
span1 := ss1.Spans().AppendEmpty() | ||
span1.SetName("test-span-1") | ||
span1.SetSpanID(pcommon.SpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})) | ||
AddWarning(span1, "test-warning-1") | ||
AddWarning(span1, "test-warning-2") | ||
span1.Attributes().PutStr("key", "value") | ||
|
||
ss2 := rs1.ScopeSpans().AppendEmpty() | ||
span2 := ss2.Spans().AppendEmpty() | ||
span2.SetName("test-span-2") | ||
span2.SetSpanID(pcommon.SpanID([8]byte{9, 10, 11, 12, 13, 14, 15, 16})) | ||
|
||
rs2 := traces.ResourceSpans().AppendEmpty() | ||
ss3 := rs2.ScopeSpans().AppendEmpty() | ||
span3 := ss3.Spans().AppendEmpty() | ||
span3.SetName("test-span-3") | ||
span3.SetSpanID(pcommon.SpanID([8]byte{17, 18, 19, 20, 21, 22, 23, 24})) | ||
AddWarning(span3, "test-warning-3") | ||
|
||
batches := ProtoFromTraces(traces) | ||
|
||
assert.Len(t, batches, 2) | ||
|
||
assert.Len(t, batches[0].Spans, 2) | ||
assert.Equal(t, "test-span-1", batches[0].Spans[0].OperationName) | ||
assert.Equal(t, []string{"test-warning-1", "test-warning-2"}, batches[0].Spans[0].Warnings) | ||
assert.Equal(t, []model.KeyValue{{Key: "key", VStr: "value"}}, batches[0].Spans[0].Tags) | ||
assert.Equal(t, "test-span-2", batches[0].Spans[1].OperationName) | ||
assert.Empty(t, batches[0].Spans[1].Warnings) | ||
assert.Empty(t, batches[0].Spans[1].Tags) | ||
|
||
assert.Len(t, batches[1].Spans, 1) | ||
assert.Equal(t, "test-span-3", batches[1].Spans[0].OperationName) | ||
assert.Equal(t, []string{"test-warning-3"}, batches[1].Spans[0].Warnings) | ||
assert.Empty(t, batches[1].Spans[0].Tags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters