-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support uploading traces to UI in OpenTelemetry format (OTLP JSON) #5155
Merged
yurishkuro
merged 14 commits into
jaegertracing:main
from
NavinShrinivas:uploading_jaeger_traces
Feb 14, 2024
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
817db96
Add endpoints to allow uploading OTLP traces
NavinShrinivas 18cd089
Refactoring and fixes for endpoint in backend
NavinShrinivas d1f2e8c
Placing functions in correct files
NavinShrinivas c98bb4d
Add fixtures and Unit tests for API
NavinShrinivas 58c92be
Fixing test and complying with linter
NavinShrinivas 06130e0
Merge branch 'main' into uploading_jaeger_traces
NavinShrinivas ceb88d4
Merge branch 'main' into uploading_jaeger_traces
yurishkuro ea7a80c
Fixings tests and merging into one function
NavinShrinivas e5716a1
Merge branch 'main' into uploading_jaeger_traces
yurishkuro 43cf0ee
Reducing marshalling and Unmarshal in test and higher test coverage
NavinShrinivas 55a1f84
Making tests simpler
NavinShrinivas 1685cd2
Merge branch 'main' into uploading_jaeger_traces
yurishkuro 6e20daf
improve tests
yurishkuro 463556c
use same trace id, two spans
yurishkuro 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 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,52 @@ | ||
{ | ||
"resourceSpans":[ | ||
{ | ||
"resource":{ | ||
"attributes":[ | ||
{ | ||
"key":"service.name", | ||
"value":{ | ||
"stringValue":"telemetrygen" | ||
} | ||
} | ||
] | ||
}, | ||
"scopeSpans":[ | ||
{ | ||
"scope":{ | ||
"name":"telemetrygen" | ||
}, | ||
"spans":[ | ||
{ | ||
"traceId":"83a9efd15c1c98a977e0711cc93ee28b", | ||
"spanId":"e127af99e3b3e074", | ||
"parentSpanId":"909541b92cf05311", | ||
"name":"okey-dokey-0", | ||
"kind":2, | ||
"startTimeUnixNano":"1706678909209712000", | ||
"endTimeUnixNano":"1706678909209835000", | ||
"attributes":[ | ||
{ | ||
"key":"net.peer.ip", | ||
"value":{ | ||
"stringValue":"1.2.3.4" | ||
} | ||
}, | ||
{ | ||
"key":"peer.service", | ||
"value":{ | ||
"stringValue":"telemetrygen-client" | ||
} | ||
} | ||
], | ||
"status":{ | ||
|
||
} | ||
} | ||
] | ||
} | ||
], | ||
"schemaUrl":"https://opentelemetry.io/schemas/1.4.0" | ||
} | ||
] | ||
} |
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,59 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"traceID": "83a9efd15c1c98a977e0711cc93ee28b", | ||
"spans": [ | ||
{ | ||
"traceID": "83a9efd15c1c98a977e0711cc93ee28b", | ||
"spanID": "e127af99e3b3e074", | ||
"operationName": "okey-dokey-0", | ||
"references": [ | ||
{ | ||
"refType": "CHILD_OF", | ||
"traceID": "83a9efd15c1c98a977e0711cc93ee28b", | ||
"spanID": "909541b92cf05311" | ||
} | ||
], | ||
"startTime": 1706678909209712, | ||
"duration": 123, | ||
"tags": [ | ||
{ | ||
"key": "otel.library.name", | ||
"type": "string", | ||
"value": "telemetrygen" | ||
}, | ||
{ | ||
"key": "net.peer.ip", | ||
"type": "string", | ||
"value": "1.2.3.4" | ||
}, | ||
{ | ||
"key": "peer.service", | ||
"type": "string", | ||
"value": "telemetrygen-client" | ||
}, | ||
{ | ||
"key": "span.kind", | ||
"type": "string", | ||
"value": "server" | ||
} | ||
], | ||
"logs": [], | ||
"processID": "p1", | ||
"warnings": null | ||
} | ||
], | ||
"processes": { | ||
"p1": { | ||
"serviceName": "telemetrygen", | ||
"tags": [] | ||
} | ||
}, | ||
"warnings": null | ||
} | ||
], | ||
"total": 0, | ||
"limit": 0, | ||
"offset": 0, | ||
"errors": null | ||
} |
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,60 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package app | ||
|
||
import ( | ||
"fmt" | ||
|
||
model2otel "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
func otlp2model(otlpSpans []byte) ([]*model.Batch, error) { | ||
ptraceUnmarshaler := ptrace.JSONUnmarshaler{} | ||
otlpTraces, err := ptraceUnmarshaler.UnmarshalTraces(otlpSpans) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot unmarshal OTLP : %w", err) | ||
} | ||
jaegerBatches, err := model2otel.ProtoFromTraces(otlpTraces) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot transform OTLP to Jaeger: %w", err) | ||
} | ||
return jaegerBatches, nil | ||
} | ||
|
||
func batchesToTraces(jaegerBatches []*model.Batch) ([]*model.Trace, error) { | ||
var traces []*model.Trace | ||
traceMap := make(map[model.TraceID]*model.Trace) | ||
for _, batch := range jaegerBatches { | ||
for _, span := range batch.Spans { | ||
if span.Process == nil { | ||
span.Process = batch.Process | ||
} | ||
trace, ok := traceMap[span.TraceID] | ||
if !ok { | ||
newtrace := model.Trace{ | ||
Spans: []*model.Span{span}, | ||
} | ||
traceMap[span.TraceID] = &newtrace | ||
traces = append(traces, &newtrace) | ||
} else { | ||
trace.Spans = append(trace.Spans, span) | ||
} | ||
} | ||
} | ||
return traces, nil | ||
} |
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,68 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
func TestBatchesToTraces(t *testing.T) { | ||
b1 := &model.Batch{ | ||
Spans: []*model.Span{ | ||
{TraceID: model.NewTraceID(1, 2), SpanID: model.NewSpanID(1), OperationName: "x"}, | ||
{TraceID: model.NewTraceID(1, 3), SpanID: model.NewSpanID(2), OperationName: "y"}, | ||
}, | ||
Process: model.NewProcess("process1", model.KeyValues{}), | ||
} | ||
|
||
b2 := &model.Batch{ | ||
Spans: []*model.Span{ | ||
{TraceID: model.NewTraceID(1, 2), SpanID: model.NewSpanID(2), OperationName: "z"}, | ||
}, | ||
Process: model.NewProcess("process2", model.KeyValues{}), | ||
} | ||
|
||
mainBatch := []*model.Batch{b1, b2} | ||
|
||
traces, err := batchesToTraces(mainBatch) | ||
require.NoError(t, err) | ||
|
||
s1 := []*model.Span{ | ||
{ | ||
TraceID: model.NewTraceID(1, 2), | ||
SpanID: model.NewSpanID(1), | ||
OperationName: "x", | ||
Process: model.NewProcess("process1", model.KeyValues{}), | ||
}, | ||
{ | ||
TraceID: model.NewTraceID(1, 2), | ||
SpanID: model.NewSpanID(2), | ||
OperationName: "z", | ||
Process: model.NewProcess("process2", model.KeyValues{}), | ||
}, | ||
} | ||
|
||
s2 := []*model.Span{ | ||
{ | ||
TraceID: model.NewTraceID(1, 3), | ||
SpanID: model.NewSpanID(2), | ||
OperationName: "y", | ||
Process: model.NewProcess("process1", model.KeyValues{}), | ||
}, | ||
} | ||
|
||
t1 := model.Trace{ | ||
Spans: s1, | ||
} | ||
t2 := model.Trace{ | ||
Spans: s2, | ||
} | ||
mainTrace := []*model.Trace{&t1, &t2} | ||
assert.Equal(t, mainTrace, traces) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformatted per
cat file | jq .