-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[v2][adjuster] Implement otlp to model translator with post processing #6394
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
71184aa
Add OTLP to Jaeger Translator With Warnings Translation
mahadzaryab1 3278ad4
Add Unit Tests
mahadzaryab1 4a00a5d
Change Callsites To Use Internal Translator
mahadzaryab1 f8352b9
Run Formatter
mahadzaryab1 fa1f5bf
Add Linter Rule To Disable Collector Contrib
mahadzaryab1 54c1549
Add Helper For Converting To OTEL's Span ID
mahadzaryab1 e6f51e0
Change Implementation To Be More Robust
mahadzaryab1 07bd0a6
Fix Linting
mahadzaryab1 a4fbd0f
Filter Warnings Tag Out
mahadzaryab1 9654453
Fix Missing Code Coverage
mahadzaryab1 a1e26ac
Fix Imports
mahadzaryab1 8adf587
Merge branch 'main' into translation
mahadzaryab1 c7ee60c
Implement Helper For Converting To Model Span ID
mahadzaryab1 52c01c6
Flip Map Conversion
mahadzaryab1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 { | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.