-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support uploading traces to UI in OpenTelemetry format (OTLP JSON) (#…
…5155) ## Which problem is this PR solving? * Solves #4949 * In combination with jaegertracing/jaeger-ui#2145 ## Description of the changes - Incorporates changes from previous draft PR review - Adds middleware in frontend as well ## How was this change tested? - Unit tests and supplying valid and invalid OTLP traces using insomnia to test the API ## 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`: `yarn lint` and `yarn test` --------- Signed-off-by: Navin Shrinivas <karupal2002@gmail.com> Signed-off-by: Yuri Shkuro <github@ysh.us> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Co-authored-by: Yuri Shkuro <github@ysh.us>
- Loading branch information
1 parent
8ae2e05
commit b60a7fc
Showing
5 changed files
with
312 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"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": {} | ||
}, | ||
{ | ||
"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,98 @@ | ||
{ | ||
"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 | ||
}, | ||
{ | ||
"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,55 @@ | ||
// 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 otlp2traces(otlpSpans []byte) ([]*model.Trace, error) { | ||
ptraceUnmarshaler := ptrace.JSONUnmarshaler{} | ||
otlpTraces, err := ptraceUnmarshaler.UnmarshalTraces(otlpSpans) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot unmarshal OTLP : %w", err) | ||
} | ||
jaegerBatches, _ := model2otel.ProtoFromTraces(otlpTraces) | ||
// ProtoFromTraces will not give an 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 | ||
} |