-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate the sdk/telemetry pkg (#1238)
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
Showing
30 changed files
with
2,591 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=" | ||
} | ||
} | ||
]`))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.