1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-23 22:34:47 +02:00
Files
opentelemetry-go/trace/internal/telemetry/number.go
Tyler Yahn 9aae208463 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:

-
aea085dd2a/sdk/tracer_provider.go
-
aea085dd2a/sdk/tracer.go
-
aea085dd2a/sdk/span.go
-
aea085dd2a/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:

-
aea085dd2a/sdk/tracer_provider_test.go
-
aea085dd2a/sdk/tracer_test.go
-
aea085dd2a/sdk/span_test.go
-
aea085dd2a/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
aea085dd2a/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
aea085dd2a/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

68 lines
1.6 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
import (
"encoding/json"
"strconv"
)
// protoInt64 represents the protobuf encoding of integers which can be either
// strings or integers.
type protoInt64 int64
// Int64 returns the protoInt64 as an int64.
func (i *protoInt64) Int64() int64 { return int64(*i) }
// UnmarshalJSON decodes both strings and integers.
func (i *protoInt64) UnmarshalJSON(data []byte) error {
if data[0] == '"' {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
parsedInt, err := strconv.ParseInt(str, 10, 64)
if err != nil {
return err
}
*i = protoInt64(parsedInt)
} else {
var parsedInt int64
if err := json.Unmarshal(data, &parsedInt); err != nil {
return err
}
*i = protoInt64(parsedInt)
}
return nil
}
// protoUint64 represents the protobuf encoding of integers which can be either
// strings or integers.
type protoUint64 uint64
// Int64 returns the protoUint64 as a uint64.
func (i *protoUint64) Uint64() uint64 { return uint64(*i) }
// UnmarshalJSON decodes both strings and integers.
func (i *protoUint64) UnmarshalJSON(data []byte) error {
if data[0] == '"' {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
parsedUint, err := strconv.ParseUint(str, 10, 64)
if err != nil {
return err
}
*i = protoUint64(parsedUint)
} else {
var parsedUint uint64
if err := json.Unmarshal(data, &parsedUint); err != nil {
return err
}
*i = protoUint64(parsedUint)
}
return nil
}