You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
This copes the `go.opentelemetry.io/auto/sdk` package into the `go.opentelemetry.io/otel/trace` package. This is done to avoid package import cycles and still provide an auto-instrumentable SDK (see https://github.com/open-telemetry/opentelemetry-go-instrumentation/issues/974). ## Overview of changes The code copied is updated with the following changes. The over-all goal is to ensure none of this is exported and follows the `auto/sdk` as close as possible to help maintenance. ### `trace/auto.go` Consolidation of the following into a single file: -aea085dd2a/sdk/tracer_provider.go-aea085dd2a/sdk/tracer.go-aea085dd2a/sdk/span.go-aea085dd2a/sdk/limit.goHas the following changes: - `func TracerProvider()` renamed to `newAutoTracerProvider` - `type tracerProvider struct` renamed to `autoTracerProvider` - `type tracer struct` renamed to `autoTracer` - `type span struct` renamed to `autoSpan` - Lint issues addressed based on this repositories configuration (these changes are being back-ported upstream) ### `trace/auto_test.go` Consolidation of the following into a single file: -aea085dd2a/sdk/tracer_provider_test.go-aea085dd2a/sdk/tracer_test.go-aea085dd2a/sdk/span_test.go-aea085dd2a/sdk/limit_test.goHas the following changes: - Renames in `trace/auto.go` are applied here - Lint issues addressed based on this repositories configuration (these changes are being back-ported upstream) ### `trace/internal/telemetry` Copied fromaea085dd2a/sdk/internal/telemetry- Pacakge vanity URLs added - Lint issues addressed based on this repositories configuration (these changes are being back-ported upstream) - Use of the package name has been updated #### `trace/internal/telemetry/test` Copied fromaea085dd2a/sdk/internal/telemetry/test- Module name updated - Documentation updated with new package name - Testing values updated with new package name --------- Co-authored-by: Ron Federman <73110295+RonFed@users.noreply.github.com>
146 lines
2.8 KiB
Go
146 lines
2.8 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package telemetry
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTracesEncoding(t *testing.T) {
|
|
traces := &Traces{
|
|
ResourceSpans: []*ResourceSpans{{}},
|
|
}
|
|
|
|
t.Run("CamelCase", runJSONEncodingTests(traces, []byte(`{
|
|
"resourceSpans": [
|
|
{
|
|
"resource": {}
|
|
}
|
|
]
|
|
}`)))
|
|
|
|
t.Run("SnakeCase/Unmarshal", runJSONUnmarshalTest(traces, []byte(`{
|
|
"resource_spans": [
|
|
{
|
|
"resource": {}
|
|
}
|
|
]
|
|
}`)))
|
|
}
|
|
|
|
func TestResourceSpansEncoding(t *testing.T) {
|
|
rs := &ResourceSpans{
|
|
Resource: Resource{
|
|
Attrs: []Attr{String("key", "val")},
|
|
},
|
|
ScopeSpans: []*ScopeSpans{{}},
|
|
SchemaURL: schema100,
|
|
}
|
|
|
|
t.Run("CamelCase", runJSONEncodingTests(rs, []byte(`{
|
|
"resource": {
|
|
"attributes": [
|
|
{
|
|
"key": "key",
|
|
"value": {
|
|
"stringValue": "val"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"scopeSpans": [
|
|
{
|
|
"scope": null
|
|
}
|
|
],
|
|
"schemaUrl": "http://go.opentelemetry.io/schema/v1.0.0"
|
|
}`)))
|
|
|
|
t.Run("SnakeCase/Unmarshal", runJSONUnmarshalTest(rs, []byte(`{
|
|
"resource": {
|
|
"attributes": [
|
|
{
|
|
"key": "key",
|
|
"value": {
|
|
"string_value": "val"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"scope_spans": [
|
|
{
|
|
"scope": null
|
|
}
|
|
],
|
|
"schema_url": "http://go.opentelemetry.io/schema/v1.0.0"
|
|
}`)))
|
|
}
|
|
|
|
func TestScopeSpansEncoding(t *testing.T) {
|
|
ss := &ScopeSpans{
|
|
Scope: &Scope{Name: "scope"},
|
|
Spans: []*Span{{
|
|
TraceID: [16]byte{0x1},
|
|
SpanID: [8]byte{0x2},
|
|
Name: "A",
|
|
StartTime: y2k,
|
|
EndTime: y2k.Add(time.Second),
|
|
}, {
|
|
TraceID: [16]byte{0x1},
|
|
SpanID: [8]byte{0x3},
|
|
Name: "B",
|
|
StartTime: y2k.Add(time.Second),
|
|
EndTime: y2k.Add(2 * time.Second),
|
|
}},
|
|
SchemaURL: schema100,
|
|
}
|
|
|
|
t.Run("CamelCase", runJSONEncodingTests(ss, []byte(`{
|
|
"scope": {
|
|
"name": "scope"
|
|
},
|
|
"spans": [
|
|
{
|
|
"traceId": "01000000000000000000000000000000",
|
|
"spanId": "0200000000000000",
|
|
"name": "A",
|
|
"startTimeUnixNano": 946684800000000000,
|
|
"endTimeUnixNano": 946684801000000000
|
|
},
|
|
{
|
|
"traceId": "01000000000000000000000000000000",
|
|
"spanId": "0300000000000000",
|
|
"name": "B",
|
|
"startTimeUnixNano": 946684801000000000,
|
|
"endTimeUnixNano": 946684802000000000
|
|
}
|
|
],
|
|
"schemaUrl": "http://go.opentelemetry.io/schema/v1.0.0"
|
|
}`)))
|
|
|
|
t.Run("SnakeCase/Unmarshal", runJSONUnmarshalTest(ss, []byte(`{
|
|
"scope": {
|
|
"name": "scope"
|
|
},
|
|
"spans": [
|
|
{
|
|
"trace_id": "01000000000000000000000000000000",
|
|
"span_id": "0200000000000000",
|
|
"name": "A",
|
|
"start_time_unix_nano": 946684800000000000,
|
|
"end_time_unix_nano": 946684801000000000
|
|
},
|
|
{
|
|
"trace_id": "01000000000000000000000000000000",
|
|
"span_id": "0300000000000000",
|
|
"name": "B",
|
|
"start_time_unix_nano": 946684801000000000,
|
|
"end_time_unix_nano": 946684802000000000
|
|
}
|
|
],
|
|
"schema_url": "http://go.opentelemetry.io/schema/v1.0.0"
|
|
}`)))
|
|
}
|