1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

opencensus: add TestOCSpanContextToOTel (#6600)

Fixes #6562

I ignored `tracestate` for the following note in the Issue.

> The full depth of conversion for each field is out of scope. That is
left for unit-tests of the oc2otel package.

---------

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
This commit is contained in:
Tetsuya KIKUCHI
2025-04-07 19:28:42 +09:00
committed by GitHub
parent ec513a2d78
commit 0ed4af71a0

View File

@@ -10,8 +10,11 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
octrace "go.opencensus.io/trace"
"go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest" "go.opentelemetry.io/otel/sdk/trace/tracetest"
oteltrace "go.opentelemetry.io/otel/trace"
) )
func TestNewTraceBridge(t *testing.T) { func TestNewTraceBridge(t *testing.T) {
@@ -26,3 +29,18 @@ func TestNewTraceBridge(t *testing.T) {
assert.Equal(t, scopeName, gotSpan.InstrumentationScope.Name) assert.Equal(t, scopeName, gotSpan.InstrumentationScope.Name)
assert.Equal(t, gotSpan.InstrumentationScope.Version, Version()) assert.Equal(t, gotSpan.InstrumentationScope.Version, Version())
} }
func TestOCSpanContextToOTel(t *testing.T) {
input := octrace.SpanContext{
TraceID: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
SpanID: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
TraceOptions: octrace.TraceOptions(1),
}
want := oteltrace.NewSpanContext(oteltrace.SpanContextConfig{
TraceID: oteltrace.TraceID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
SpanID: oteltrace.SpanID{1, 2, 3, 4, 5, 6, 7, 8},
TraceFlags: oteltrace.TraceFlags(1),
})
got := OCSpanContextToOTel(input)
assert.Equal(t, want, got)
}