1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-27 22:49:15 +02:00
Files
opentelemetry-go/trace/internal/telemetry/attr_test.go

157 lines
2.4 KiB
Go
Raw Normal View History

Add an auto-instrumentable no-op implementation to the `trace` package (#6203) 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: - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer_provider.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/span.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/limit.go Has 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: - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer_provider_test.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer_test.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/span_test.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/limit_test.go Has 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 from https://github.com/open-telemetry/opentelemetry-go-instrumentation/tree/aea085dd2a3640630ac07a2187cbda9d15d2dd00/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 from https://github.com/open-telemetry/opentelemetry-go-instrumentation/tree/aea085dd2a3640630ac07a2187cbda9d15d2dd00/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>
2025-02-04 08:04:14 -08:00
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package telemetry
import "testing"
func TestAttrEncoding(t *testing.T) {
attrs := []Attr{
String("user", "Alice"),
Bool("admin", true),
Int64("floor", -2),
Float64("impact", 0.21362),
Slice("reports", StringValue("Bob"), StringValue("Dave")),
Map("favorites", String("food", "hot dog"), Int("number", 13)),
Bytes("secret", []byte("NUI4RUZGRjc5ODAzODEwM0QyNjlCNjMzODEzRkM2MEM=")),
}
t.Run("CamelCase", runJSONEncodingTests(attrs, []byte(`[
{
"key": "user",
"value": {
"stringValue": "Alice"
}
},
{
"key": "admin",
"value": {
"boolValue": true
}
},
{
"key": "floor",
"value": {
"intValue": "-2"
}
},
{
"key": "impact",
"value": {
"doubleValue": 0.21362
}
},
{
"key": "reports",
"value": {
"arrayValue": {
"values": [
{
"stringValue": "Bob"
},
{
"stringValue": "Dave"
}
]
}
}
},
{
"key": "favorites",
"value": {
"kvlistValue": {
"values": [
{
"key": "food",
"value": {
"stringValue": "hot dog"
}
},
{
"key": "number",
"value": {
"intValue": "13"
}
}
]
}
}
},
{
"key": "secret",
"value": {
"bytesValue": "TlVJNFJVWkdSamM1T0RBek9ERXdNMFF5TmpsQ05qTXpPREV6UmtNMk1FTT0="
}
}
]`)))
t.Run("SnakeCase/Unmarshal", runJSONUnmarshalTest(attrs, []byte(`[
{
"key": "user",
"value": {
"string_value": "Alice"
}
},
{
"key": "admin",
"value": {
"bool_value": true
}
},
{
"key": "floor",
"value": {
"int_value": "-2"
}
},
{
"key": "impact",
"value": {
"double_value": 0.21362
}
},
{
"key": "reports",
"value": {
"array_value": {
"values": [
{
"string_value": "Bob"
},
{
"string_value": "Dave"
}
]
}
}
},
{
"key": "favorites",
"value": {
"kvlist_value": {
"values": [
{
"key": "food",
"value": {
"string_value": "hot dog"
}
},
{
"key": "number",
"value": {
"int_value": "13"
}
}
]
}
}
},
{
"key": "secret",
"value": {
"bytes_value": "TlVJNFJVWkdSamM1T0RBek9ERXdNMFF5TmpsQ05qTXpPREV6UmtNMk1FTT0="
}
}
]`)))
}