Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {"stringValue": "resource-test-service"}
},
{
"key": "host.name",
"value": {"stringValue": "test-host-01"}
},
{
"key": "k8s.pod.name",
"value": {"stringValue": "test-pod-123"}
},
{
"key": "k8s.namespace.name",
"value": {"stringValue": "production"}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "resource-test",
"version": "1.0.0"
},
"spans": [
{
"traceId": "00000000000000000000000000000030",
"spanId": "0000000000000020",
"name": "resource-attributes-operation",
"startTimeUnixNano": "1485445591639875000",
"endTimeUnixNano": "1485445591739875000",
"attributes": []
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {"stringValue": "otlp-test-service"}
},
{
"key": "service.version",
"value": {"stringValue": "1.0.0"}
},
{
"key": "deployment.environment",
"value": {"stringValue": "test"}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "test-instrumentation-library",
"version": "2.1.0",
"attributes": [
{
"key": "otel.scope.name",
"value": {"stringValue": "custom-tracer"}
},
{
"key": "instrumentation.provider",
"value": {"stringValue": "opentelemetry"}
}
]
},
"spans": [
{
"traceId": "00000000000000000000000000000020",
"spanId": "0000000000000010",
"name": "otlp-scope-test-operation",
"kind": 2,
"startTimeUnixNano": "1485445591639875000",
"endTimeUnixNano": "1485445591739875000",
"attributes": [
{
"key": "http.method",
"value": {"stringValue": "GET"}
},
{
"key": "http.status_code",
"value": {"intValue": "200"}
}
],
"status": {
"code": 0
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {"stringValue": "span-links-service"}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "span-links-test",
"version": "1.0.0",
"attributes": [
{
"key": "otel.scope.test",
"value": {"stringValue": "true"}
}
]
},
"spans": [
{
"traceId": "00000000000000000000000000000040",
"spanId": "0000000000000030",
"name": "parent-span-with-links",
"kind": 1,
"startTimeUnixNano": "1485445591639875000",
"endTimeUnixNano": "1485445591939875000",
"attributes": [],
"links": [
{
"traceId": "00000000000000000000000000000050",
"spanId": "0000000000000040",
"attributes": [
{
"key": "link.type",
"value": {"stringValue": "parent_link"}
}
]
},
{
"traceId": "00000000000000000000000000000060",
"spanId": "0000000000000050",
"attributes": [
{
"key": "link.type",
"value": {"stringValue": "sibling_link"}
}
]
}
],
"status": {
"code": 0
}
}
]
}
]
}
]
}
22 changes: 14 additions & 8 deletions internal/storage/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/jaegertracing/jaeger-idl/model/v1"
"github.com/jaegertracing/jaeger/internal/storage/v1/api/samplingstore"
Expand Down Expand Up @@ -368,7 +369,9 @@ func (s *StorageIntegration) testFindTraces(t *testing.T) {
trace, ok := allTraceFixtures[traceFixture]
if !ok {
trace = s.getTraceFixture(t, traceFixture)
s.writeTrace(t, trace)
otelTraces := v1adapter.V1TraceToOtelTrace(trace)
s.writeTrace(t, otelTraces)

allTraceFixtures[traceFixture] = trace
}
expected = append(expected, trace)
Expand Down Expand Up @@ -409,20 +412,21 @@ func (s *StorageIntegration) findTracesByQuery(t *testing.T, query *tracestore.T
return traces
}

func (s *StorageIntegration) writeTrace(t *testing.T, trace *model.Trace) {
t.Logf("%-23s Writing trace with %d spans", time.Now().Format("2006-01-02 15:04:05.999"), len(trace.Spans))
func (s *StorageIntegration) writeTrace(t *testing.T, traces ptrace.Traces) {
spanCount := traces.SpanCount()
t.Logf("%-23s Writing trace with %d spans", time.Now().Format("2006-01-02 15:04:05.999"), spanCount)
ctx, cx := context.WithTimeout(context.Background(), 5*time.Minute)
defer cx()
otelTraces := v1adapter.V1TraceToOtelTrace(trace)
err := s.TraceWriter.WriteTraces(ctx, otelTraces)
err := s.TraceWriter.WriteTraces(ctx, traces)
require.NoError(t, err, "Not expecting error when writing trace to storage")

t.Logf("%-23s Finished writing trace with %d spans", time.Now().Format("2006-01-02 15:04:05.999"), len(trace.Spans))
t.Logf("%-23s Finished writing trace with %d spans", time.Now().Format("2006-01-02 15:04:05.999"), spanCount)
}

func (s *StorageIntegration) loadParseAndWriteExampleTrace(t *testing.T) *model.Trace {
trace := s.getTraceFixture(t, "example_trace")
s.writeTrace(t, trace)
otelTraces := v1adapter.V1TraceToOtelTrace(trace)
s.writeTrace(t, otelTraces)
return trace
}

Expand All @@ -446,7 +450,9 @@ func (s *StorageIntegration) writeLargeTraceWithDuplicateSpanIds(
newSpan.StartTime = newSpan.StartTime.Add(time.Second * time.Duration(i+1))
trace.Spans[i] = newSpan
}
s.writeTrace(t, trace)
// Convert to OTLP for writing
otelTraces := v1adapter.V1TraceToOtelTrace(trace)
s.writeTrace(t, otelTraces)
return trace
}

Expand Down
5 changes: 5 additions & 0 deletions internal/storage/v2/v1adapter/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func V1TraceToOtelTrace(jTrace *model.Trace) ptrace.Traces {
return V1BatchesToTraces(batches)
}

// V1TraceFromOtelTrace converts a single OTLP trace to v1 model.Trace
func V1TraceFromOtelTrace(otelTrace ptrace.Traces) *model.Trace {
return modelTraceFromOtelTrace(otelTrace)
}

func createBatchesFromModelTrace(jTrace *model.Trace) []*model.Batch {
spans := jTrace.Spans

Expand Down
34 changes: 22 additions & 12 deletions internal/storage/v2/v1adapter/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,34 +255,44 @@ func TestV1TracesFromSeq2(t *testing.T) {
}
}

func TestV1TraceToOtelTrace_ReturnsExptectedOtelTrace(t *testing.T) {
func TestV1TraceFromOtelTrace_ReturnsExpectedModelTrace(t *testing.T) {
jTrace := &model.Trace{
Spans: []*model.Span{
{
TraceID: model.NewTraceID(2, 3),
SpanID: model.NewSpanID(1),
Process: model.NewProcess("Service1", nil),
OperationName: "two-resources-1",
}, {
OperationName: "test-operation-1",
},
{
TraceID: model.NewTraceID(2, 3),
SpanID: model.NewSpanID(2),
Process: model.NewProcess("service2", nil),
OperationName: "two-resources-2",
Process: model.NewProcess("Service1", nil),
OperationName: "test-operation-2",
},
},
}
actualTrace := V1TraceToOtelTrace(jTrace)

otelTraces := V1TraceToOtelTrace(jTrace)

actualTrace := V1TraceFromOtelTrace(otelTraces)

require.NotEmpty(t, actualTrace)
require.Equal(t, 2, actualTrace.ResourceSpans().Len())
require.Len(t, actualTrace.Spans, 2)
assert.Equal(t, model.NewTraceID(2, 3), actualTrace.Spans[0].TraceID)
assert.Equal(t, model.NewSpanID(1), actualTrace.Spans[0].SpanID)
assert.Equal(t, "test-operation-1", actualTrace.Spans[0].OperationName)
assert.Equal(t, "Service1", actualTrace.Spans[0].Process.ServiceName)
assert.Equal(t, model.NewSpanID(2), actualTrace.Spans[1].SpanID)
assert.Equal(t, "test-operation-2", actualTrace.Spans[1].OperationName)
}

func TestV1TraceToOtelTrace_ReturnEmptyOtelTrace(t *testing.T) {
jTrace := &model.Trace{}
eTrace := ptrace.NewTraces()
aTrace := V1TraceToOtelTrace(jTrace)
func TestV1TraceFromOtelTrace_ReturnEmptyModelTrace(t *testing.T) {
otelTraces := ptrace.NewTraces()
actualTrace := V1TraceFromOtelTrace(otelTraces)

require.Equal(t, eTrace.SpanCount(), aTrace.SpanCount(), 0)
require.NotNil(t, actualTrace)
require.Empty(t, actualTrace.Spans)
}

func TestV1TraceIDsFromSeq2(t *testing.T) {
Expand Down
Loading