-
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.
[v2][adjuster] Implement otlp to model translator with post processing (
#6394) ## Which problem is this PR solving? - Towards #6344 ## Description of the changes - Implemented a translator in `jptrace` with a function `ProtoFromTraces` that is a wrapper of the upstream `ProtoFromTraces` in opentelemetry-collector-contrib jaeger translator. This function appends the warnings in `jaeger.internal.warnings` to the corresponding warnings field in the proto model. ## How was this change tested? - Added unit tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab <[email protected]>
- Loading branch information
1 parent
6bec1ad
commit 4ecb086
Showing
9 changed files
with
197 additions
and
8 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
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