Skip to content

Commit 4a5cb4c

Browse files
committed
test: verify OTLP scope and span links
Signed-off-by: SoumyaRaikwar <[email protected]>
1 parent d4eaf00 commit 4a5cb4c

File tree

2 files changed

+36
-47
lines changed

2 files changed

+36
-47
lines changed

internal/storage/integration/fixtures/traces/otlp_span_links.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
\{
22
"resourceSpans": [
33
{
44
"resource": {
@@ -13,13 +13,7 @@
1313
{
1414
"scope": {
1515
"name": "span-links-test",
16-
"version": "1.0.0",
17-
"attributes": [
18-
{
19-
"key": "otel.scope.test",
20-
"value": {"stringValue": "true"}
21-
}
22-
]
16+
"version": "1.0.0"
2317
},
2418
"spans": [
2519
{
@@ -33,23 +27,11 @@
3327
"links": [
3428
{
3529
"traceId": "00000000000000000000000000000050",
36-
"spanId": "0000000000000040",
37-
"attributes": [
38-
{
39-
"key": "link.type",
40-
"value": {"stringValue": "parent_link"}
41-
}
42-
]
30+
"spanId": "0000000000000040"
4331
},
4432
{
4533
"traceId": "00000000000000000000000000000060",
46-
"spanId": "0000000000000050",
47-
"attributes": [
48-
{
49-
"key": "link.type",
50-
"value": {"stringValue": "sibling_link"}
51-
}
52-
]
34+
"spanId": "0000000000000050"
5335
}
5436
],
5537
"status": {

internal/storage/integration/integration.go

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -644,18 +644,17 @@ func (s *StorageIntegration) testOTLPScopePreservation(t *testing.T) {
644644

645645
t.Log("Testing OTLP InstrumentationScope preservation through v2 API")
646646

647-
traces := loadOTLPFixture(t, "otlp_scope_attributes")
648-
traceID := extractTraceID(t, traces)
647+
expectedTraces := loadOTLPFixture(t, "otlp_scope_attributes")
648+
traceID := extractTraceID(t, expectedTraces)
649649

650-
s.writeTrace(t, traces)
650+
s.writeTrace(t, expectedTraces)
651651

652652
var retrievedTraces ptrace.Traces
653653

654654
found := s.waitForCondition(t, func(t *testing.T) bool {
655655
ctx := context.Background()
656656
iter := s.TraceReader.GetTraces(ctx, tracestore.GetTraceParams{TraceID: traceID})
657657

658-
// tr is []ptrace.Traces (slice of traces)
659658
for trSlice, err := range iter {
660659
if err != nil {
661660
t.Logf("Error iterating traces: %v", err)
@@ -673,19 +672,24 @@ func (s *StorageIntegration) testOTLPScopePreservation(t *testing.T) {
673672
require.True(t, found, "Failed to retrieve written OTLP trace")
674673
require.Positive(t, retrievedTraces.SpanCount(), "Retrieved trace should have spans")
675674

676-
// Validate OTLP InstrumentationScope metadata directly
675+
// Validate full trace structure
677676
require.Positive(t, retrievedTraces.ResourceSpans().Len(), "Should have resource spans")
678677

679-
rs := retrievedTraces.ResourceSpans().At(0)
680-
require.Positive(t, rs.ScopeSpans().Len(), "Should have scope spans")
678+
expectedRS := expectedTraces.ResourceSpans().At(0)
679+
retrievedRS := retrievedTraces.ResourceSpans().At(0)
681680

682-
scopeSpans := rs.ScopeSpans().At(0)
683-
scope := scopeSpans.Scope()
681+
require.Positive(t, retrievedRS.ScopeSpans().Len(), "Should have scope spans")
684682

685-
assert.Equal(t, "test-instrumentation-library", scope.Name())
686-
assert.Equal(t, "2.1.0", scope.Version())
683+
expectedScope := expectedRS.ScopeSpans().At(0).Scope()
684+
retrievedScope := retrievedRS.ScopeSpans().At(0).Scope()
687685

688-
t.Log("OTLP InstrumentationScope metadata preserved successfully")
686+
// Assert scope metadata
687+
assert.Equal(t, expectedScope.Name(), retrievedScope.Name(),
688+
"InstrumentationScope name should be preserved")
689+
assert.Equal(t, expectedScope.Version(), retrievedScope.Version(),
690+
"InstrumentationScope version should be preserved")
691+
692+
t.Log("✓ OTLP InstrumentationScope metadata preserved successfully")
689693
}
690694

691695
func (s *StorageIntegration) testOTLPSpanLinks(t *testing.T) {
@@ -698,14 +702,14 @@ func (s *StorageIntegration) testOTLPSpanLinks(t *testing.T) {
698702

699703
t.Log("Testing OTLP span links preservation through v2 API")
700704

701-
traces := loadOTLPFixture(t, "otlp_span_links")
702-
traceID := extractTraceID(t, traces)
705+
expectedTraces := loadOTLPFixture(t, "otlp_span_links")
706+
traceID := extractTraceID(t, expectedTraces)
703707

704-
originalSpan := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
705-
expectedLinkCount := originalSpan.Links().Len()
708+
expectedSpan := expectedTraces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
709+
expectedLinkCount := expectedSpan.Links().Len()
706710
require.Greater(t, expectedLinkCount, 0, "Fixture should have span links")
707711

708-
s.writeTrace(t, traces)
712+
s.writeTrace(t, expectedTraces)
709713

710714
var retrievedTraces ptrace.Traces
711715
found := s.waitForCondition(t, func(t *testing.T) bool {
@@ -731,15 +735,18 @@ func (s *StorageIntegration) testOTLPSpanLinks(t *testing.T) {
731735
retrievedSpan := retrievedTraces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
732736
actualLinkCount := retrievedSpan.Links().Len()
733737

734-
assert.Equal(t, expectedLinkCount, actualLinkCount)
738+
// Assert link count
739+
assert.Equal(t, expectedLinkCount, actualLinkCount, "Span links count should match")
735740

736-
if actualLinkCount > 0 {
737-
link := retrievedSpan.Links().At(0)
738-
linkType, exists := link.Attributes().Get("link.type")
739-
assert.True(t, exists)
740-
if exists {
741-
t.Logf("Span link attribute preserved: link.type = %s", linkType.Str())
742-
}
741+
// Verify each link is preserved correctly
742+
for i := 0; i < expectedLinkCount; i++ {
743+
expectedLink := expectedSpan.Links().At(i)
744+
actualLink := retrievedSpan.Links().At(i)
745+
746+
assert.Equal(t, expectedLink.TraceID(), actualLink.TraceID(),
747+
"Link %d TraceID should match", i)
748+
assert.Equal(t, expectedLink.SpanID(), actualLink.SpanID(),
749+
"Link %d SpanID should match", i)
743750
}
744751

745752
t.Log("OTLP span links preserved successfully")

0 commit comments

Comments
 (0)