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>
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
// Scope is the identifying values of the instrumentation scope.
|
|
type Scope struct {
|
|
Name string `json:"name,omitempty"`
|
|
Version string `json:"version,omitempty"`
|
|
Attrs []Attr `json:"attributes,omitempty"`
|
|
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
|
}
|
|
|
|
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into r.
|
|
func (s *Scope) UnmarshalJSON(data []byte) error {
|
|
decoder := json.NewDecoder(bytes.NewReader(data))
|
|
|
|
t, err := decoder.Token()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if t != json.Delim('{') {
|
|
return errors.New("invalid Scope type")
|
|
}
|
|
|
|
for decoder.More() {
|
|
keyIface, err := decoder.Token()
|
|
if err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
// Empty.
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
key, ok := keyIface.(string)
|
|
if !ok {
|
|
return fmt.Errorf("invalid Scope field: %#v", keyIface)
|
|
}
|
|
|
|
switch key {
|
|
case "name":
|
|
err = decoder.Decode(&s.Name)
|
|
case "version":
|
|
err = decoder.Decode(&s.Version)
|
|
case "attributes":
|
|
err = decoder.Decode(&s.Attrs)
|
|
case "droppedAttributesCount", "dropped_attributes_count":
|
|
err = decoder.Decode(&s.DroppedAttrs)
|
|
default:
|
|
// Skip unknown.
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|