Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
}
}
]
}
]
}
]
}
44 changes: 34 additions & 10 deletions internal/storage/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"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 @@ -367,8 +368,11 @@
for _, traceFixture := range queryTestCase.ExpectedFixtures {
trace, ok := allTraceFixtures[traceFixture]
if !ok {
trace = s.getTraceFixture(t, traceFixture)

Check failure on line 371 in internal/storage/integration/integration.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to trace (ineffassign)
s.writeTrace(t, trace)
trace = s.getTraceFixture(t, traceFixture)
otelTraces := v1adapter.V1TraceToOtelTrace(trace)
s.writeTrace(t, otelTraces)

allTraceFixtures[traceFixture] = trace
}
expected = append(expected, trace)
Expand Down Expand Up @@ -409,21 +413,23 @@
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)
return trace
traces := s.getTraceFixtureOTLP(t, "example_trace")
s.writeTrace(t, traces)
// Convert back to v1 for backward compatibility with tests that still need it
v1Trace := v1adapter.V1TraceFromOtelTrace(traces)
return v1Trace
}

func (s *StorageIntegration) writeLargeTraceWithDuplicateSpanIds(
Expand All @@ -446,10 +452,28 @@
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
}

func (*StorageIntegration) getTraceFixtureOTLP(t *testing.T, fixture string) ptrace.Traces {
fileName := fmt.Sprintf("fixtures/traces/%s.json", fixture)
return getTraceFixtureExactOTLP(t, fileName)
}

func getTraceFixtureExactOTLP(t *testing.T, fileName string) ptrace.Traces {
unmarshaler := &ptrace.JSONUnmarshaler{}
inStr, err := fixtures.ReadFile(fileName)
require.NoError(t, err, "Failed to read fixture file: %s", fileName)

traces, err := unmarshaler.UnmarshalTraces(correctTime(inStr))
require.NoError(t, err, "Failed to unmarshal OTLP traces from %s", fileName)

return traces
}

func (*StorageIntegration) getTraceFixture(t *testing.T, fixture string) *model.Trace {
fileName := fmt.Sprintf("fixtures/traces/%s.json", fixture)
return getTraceFixtureExact(t, fileName)
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
Loading