Skip to content

Commit

Permalink
Deprecate the sdk/telemetry pkg (#1238)
Browse files Browse the repository at this point in the history
Resolve #1234

The `sdk/telemetry` package is no longer used in the `auto` package
since the merge of #1207. It is not needed outside of the `sdk` package
and needs to be removed prior to stabilization of the
`go.opentelemetry.io/auto/sdk` module.
  • Loading branch information
MrAlias authored Nov 5, 2024
1 parent 493c236 commit 9b2d3f9
Show file tree
Hide file tree
Showing 30 changed files with 2,591 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ updates:
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /sdk/internal/telemetry/test
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /sdk/telemetry/test
labels:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
- Sporadic shutdown deadlock. ([#1220](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1220))
- Only support gRPC status codes for gRPC >= 1.40. ([#1235](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1235))

### Deprecated

- The `go.opentelemetry.io/auto/sdk/telemetry` package is deprecated.
This package will be removed in the next release. ([#1238](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1238))
- The `go.opentelemetry.io/auto/sdk/telemetry/test` module is deprecated.
This module will be removed in the next release. ([#1238](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1238))

## [v0.16.0-alpha] - 2024-10-22

### Added
Expand Down
58 changes: 58 additions & 0 deletions sdk/internal/telemetry/attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package telemetry

// Attr is a key-value pair.
type Attr struct {
Key string `json:"key,omitempty"`
Value Value `json:"value,omitempty"`
}

// String returns an Attr for a string value.
func String(key, value string) Attr {
return Attr{key, StringValue(value)}
}

// Int64 returns an Attr for an int64 value.
func Int64(key string, value int64) Attr {
return Attr{key, Int64Value(value)}
}

// Int returns an Attr for an int value.
func Int(key string, value int) Attr {
return Int64(key, int64(value))
}

// Float64 returns an Attr for a float64 value.
func Float64(key string, value float64) Attr {
return Attr{key, Float64Value(value)}
}

// Bool returns an Attr for a bool value.
func Bool(key string, value bool) Attr {
return Attr{key, BoolValue(value)}
}

// Bytes returns an Attr for a []byte value.
// The passed slice must not be changed after it is passed.
func Bytes(key string, value []byte) Attr {
return Attr{key, BytesValue(value)}
}

// Slice returns an Attr for a []Value value.
// The passed slice must not be changed after it is passed.
func Slice(key string, value ...Value) Attr {
return Attr{key, SliceValue(value...)}
}

// Map returns an Attr for a map value.
// The passed slice must not be changed after it is passed.
func Map(key string, value ...Attr) Attr {
return Attr{key, MapValue(value...)}
}

// Equal returns if a is equal to b.
func (a Attr) Equal(b Attr) bool {
return a.Key == b.Key && a.Value.Equal(b.Value)
}
156 changes: 156 additions & 0 deletions sdk/internal/telemetry/attr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// 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="
}
}
]`)))
}
70 changes: 70 additions & 0 deletions sdk/internal/telemetry/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package telemetry

import (
"bytes"
"encoding/json"
"testing"
"time"
)

var (
traceID = [16]byte{0x1}

spanID1 = [8]byte{0x1}
spanID2 = [8]byte{0x2}

now = time.Now()
nowPlus1 = now.Add(1 * time.Second)

spanA = &Span{
TraceID: traceID,
SpanID: spanID2,
ParentSpanID: spanID1,
Flags: 1,
Name: "span-a",
StartTime: now,
EndTime: nowPlus1,
Status: &Status{
Message: "test status",
Code: StatusCodeOK,
},
}

spanB = &Span{}

scopeSpans = &ScopeSpans{
Scope: &Scope{
Name: "TestTracer",
Version: "v0.1.0",
},
SchemaURL: "http://go.opentelemetry.io/test",
Spans: []*Span{spanA, spanB},
}
)

func BenchmarkJSONMarshalUnmarshal(b *testing.B) {
var out ScopeSpans

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
var inBuf bytes.Buffer
enc := json.NewEncoder(&inBuf)
err := enc.Encode(scopeSpans)
if err != nil {
b.Fatal(err)
}

payload := inBuf.Bytes()

dec := json.NewDecoder(bytes.NewReader(payload))
err = dec.Decode(&out)
if err != nil {
b.Fatal(err)
}
}
_ = out
}
50 changes: 50 additions & 0 deletions sdk/internal/telemetry/conv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package telemetry

import (
"bytes"
"encoding/json"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const schema100 = "http://go.opentelemetry.io/schema/v1.0.0"

var y2k = time.Unix(0, time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC).UnixNano()) // No location.

func runJSONEncodingTests[T any](decoded T, encoded []byte) func(*testing.T) {
return func(t *testing.T) {
t.Helper()

t.Run("Unmarshal", runJSONUnmarshalTest(decoded, encoded))
t.Run("Marshal", runJSONMarshalTest(decoded, encoded))
}
}

func runJSONMarshalTest[T any](decoded T, encoded []byte) func(*testing.T) {
return func(t *testing.T) {
t.Helper()

got, err := json.Marshal(decoded)
require.NoError(t, err)

var want bytes.Buffer
require.NoError(t, json.Compact(&want, encoded))
assert.Equal(t, want.String(), string(got))
}
}

func runJSONUnmarshalTest[T any](decoded T, encoded []byte) func(*testing.T) {
return func(t *testing.T) {
t.Helper()

var got T
require.NoError(t, json.Unmarshal(encoded, &got))
assert.Equal(t, decoded, got)
}
}
8 changes: 8 additions & 0 deletions sdk/internal/telemetry/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

/*
Package telemetry provides a lightweight representations of OpenTelemetry
telemetry that is compatible with the OTLP JSON protobuf encoding.
*/
package telemetry
Loading

0 comments on commit 9b2d3f9

Please sign in to comment.