You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	sdk/trace: trace id high 64 bit tests (#7212)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7160 - Modified `testIDGenerator` to have both low and high bits (in uint64 form) since we can't store 128 bits integer - start with high seed values (taken from https://github.com/open-telemetry/opentelemetry-go/pull/7155) - validate both high and low 64 bits of trace id Does not need a CHANGELOG entry - test only. --------- Co-authored-by: Damien Mathieu <42@dmathieu.com> Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: dmathieu <damien.mathieu@elastic.co>
This commit is contained in:
		| @@ -1931,14 +1931,15 @@ func TestSamplerTraceState(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| type testIDGenerator struct { | type testIDGenerator struct { | ||||||
| 	traceID uint64 | 	traceIDHigh uint64 | ||||||
| 	spanID  uint64 | 	traceIDLow  uint64 | ||||||
|  | 	spanID      uint64 | ||||||
| } | } | ||||||
|  |  | ||||||
| func (gen *testIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.SpanID) { | func (gen *testIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.SpanID) { | ||||||
| 	traceIDHex := fmt.Sprintf("%032x", gen.traceID) | 	traceIDHex := fmt.Sprintf("%016x%016x", gen.traceIDHigh, gen.traceIDLow) | ||||||
| 	traceID, _ := trace.TraceIDFromHex(traceIDHex) | 	traceID, _ := trace.TraceIDFromHex(traceIDHex) | ||||||
| 	gen.traceID++ | 	gen.traceIDLow++ | ||||||
|  |  | ||||||
| 	spanID := gen.NewSpanID(ctx, traceID) | 	spanID := gen.NewSpanID(ctx, traceID) | ||||||
| 	return traceID, spanID | 	return traceID, spanID | ||||||
| @@ -1955,12 +1956,13 @@ var _ IDGenerator = (*testIDGenerator)(nil) | |||||||
|  |  | ||||||
| func TestWithIDGenerator(t *testing.T) { | func TestWithIDGenerator(t *testing.T) { | ||||||
| 	const ( | 	const ( | ||||||
| 		startTraceID = 0x1001_1001_1001_1001 | 		startTraceIDHigh uint64 = 0x1001_1001_1001_1001 | ||||||
| 		startSpanID  = 0x2001_2001_2001_2001 | 		startTraceIDLow  uint64 = 0x2002_2002_2002_2002 | ||||||
| 		numSpan      = 5 | 		startSpanID      uint64 = 0x3003_3003_3003_3003 | ||||||
|  | 		numSpan                 = 5 | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
| 	gen := &testIDGenerator{traceID: startTraceID, spanID: startSpanID} | 	gen := &testIDGenerator{traceIDHigh: startTraceIDHigh, traceIDLow: startTraceIDLow, spanID: startSpanID} | ||||||
| 	te := NewTestExporter() | 	te := NewTestExporter() | ||||||
| 	tp := NewTracerProvider( | 	tp := NewTracerProvider( | ||||||
| 		WithSyncer(te), | 		WithSyncer(te), | ||||||
| @@ -1973,11 +1975,19 @@ func TestWithIDGenerator(t *testing.T) { | |||||||
|  |  | ||||||
| 			gotSpanID, err := strconv.ParseUint(span.SpanContext().SpanID().String(), 16, 64) | 			gotSpanID, err := strconv.ParseUint(span.SpanContext().SpanID().String(), 16, 64) | ||||||
| 			require.NoError(t, err) | 			require.NoError(t, err) | ||||||
| 			assert.Equal(t, uint64(startSpanID)+uint64(i), gotSpanID) | 			assert.Equal(t, startSpanID+uint64(i), gotSpanID) | ||||||
|  |  | ||||||
| 			gotTraceID, err := strconv.ParseUint(span.SpanContext().TraceID().String(), 16, 64) | 			traceIdStr := span.SpanContext().TraceID().String() | ||||||
| 			require.NoError(t, err) | 			highBitsStr := traceIdStr[:16] | ||||||
| 			assert.Equal(t, uint64(startTraceID)+uint64(i), gotTraceID) | 			lowBitsStr := traceIdStr[16:] | ||||||
|  |  | ||||||
|  | 			traceIdValidator := func(t *testing.T, id string, expected uint64) { | ||||||
|  | 				gotTraceID, err := strconv.ParseUint(id, 16, 64) | ||||||
|  | 				require.NoError(t, err) | ||||||
|  | 				assert.Equal(t, expected, gotTraceID) | ||||||
|  | 			} | ||||||
|  | 			traceIdValidator(t, highBitsStr, startTraceIDHigh) | ||||||
|  | 			traceIdValidator(t, lowBitsStr, startTraceIDLow+uint64(i)) | ||||||
| 		}() | 		}() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user