Skip to content

Commit

Permalink
Remove resource.WithBuiltinDetectors() which has not been maintained (#…
Browse files Browse the repository at this point in the history
…2097)

* remove resource.WithBuiltinDetectors() which has not been maintained

* add changelog file

* Update CHANGELOG.md

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>

* resolved a repeated conflict

* fix unittest error

* fix unittest error

* fix the PR according to suggestion

* fix unittest fail and del repeated testcase in CI system

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 22, 2021
1 parent d57c5a5 commit 25d739b
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 351 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Removed the deprecated package `go.opentelemetry.io/otel/exporters/trace/jaeger`. (#2020)
- Removed the deprecated package `go.opentelemetry.io/otel/exporters/trace/zipkin`. (#2020)
- Removed the `"go.opentelemetry.io/otel/sdk/resource".WithBuiltinDetectors` function.
The explicit `With*` options for every built-in detector should be used instead. (#2026 #2097)
- Removed metrics test package `go.opentelemetry.io/otel/sdk/export/metric/metrictest`. (#2105)

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion sdk/resource/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func StringDetector(schemaURL string, k attribute.Key, f func() (string, error))
return stringDetector{schemaURL: schemaURL, K: k, F: f}
}

// Detect implements Detector.
// Detect returns a *Resource that describes the string as a value
// corresponding to attribute.Key as well as the specific schemaURL.
func (sd stringDetector) Detect(ctx context.Context) (*Resource, error) {
value, err := sd.F()
if err != nil {
Expand Down
91 changes: 84 additions & 7 deletions sdk/resource/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ func (o detectorsOption) apply(cfg *config) {
cfg.detectors = append(cfg.detectors, o.detectors...)
}

// WithBuiltinDetectors adds the built detectors to the configured resource.
func WithBuiltinDetectors() Option {
return WithDetectors(telemetrySDK{},
host{},
fromEnv{})
}

// WithFromEnv adds attributes from environment variables to the configured resource.
func WithFromEnv() Option {
return WithDetectors(fromEnv{})
Expand All @@ -92,3 +85,87 @@ type schemaURLOption string
func (o schemaURLOption) apply(cfg *config) {
cfg.schemaURL = string(o)
}

// WithOS adds all the OS attributes to the configured Resource.
// See individual WithOS* functions to configure specific attributes.
func WithOS() Option {
return WithDetectors(
osTypeDetector{},
osDescriptionDetector{},
)
}

// WithOSType adds an attribute with the operating system type to the configured Resource.
func WithOSType() Option {
return WithDetectors(osTypeDetector{})
}

// WithOSDescription adds an attribute with the operating system description to the
// configured Resource. The formatted string is equivalent to the output of the
// `uname -snrvm` command.
func WithOSDescription() Option {
return WithDetectors(osDescriptionDetector{})
}

// WithProcess adds all the Process attributes to the configured Resource.
// See individual WithProcess* functions to configure specific attributes.
func WithProcess() Option {
return WithDetectors(
processPIDDetector{},
processExecutableNameDetector{},
processExecutablePathDetector{},
processCommandArgsDetector{},
processOwnerDetector{},
processRuntimeNameDetector{},
processRuntimeVersionDetector{},
processRuntimeDescriptionDetector{},
)
}

// WithProcessPID adds an attribute with the process identifier (PID) to the
// configured Resource.
func WithProcessPID() Option {
return WithDetectors(processPIDDetector{})
}

// WithProcessExecutableName adds an attribute with the name of the process
// executable to the configured Resource.
func WithProcessExecutableName() Option {
return WithDetectors(processExecutableNameDetector{})
}

// WithProcessExecutablePath adds an attribute with the full path to the process
// executable to the configured Resource.
func WithProcessExecutablePath() Option {
return WithDetectors(processExecutablePathDetector{})
}

// WithProcessCommandArgs adds an attribute with all the command arguments (including
// the command/executable itself) as received by the process the configured Resource.
func WithProcessCommandArgs() Option {
return WithDetectors(processCommandArgsDetector{})
}

// WithProcessOwner adds an attribute with the username of the user that owns the process
// to the configured Resource.
func WithProcessOwner() Option {
return WithDetectors(processOwnerDetector{})
}

// WithProcessRuntimeName adds an attribute with the name of the runtime of this
// process to the configured Resource.
func WithProcessRuntimeName() Option {
return WithDetectors(processRuntimeNameDetector{})
}

// WithProcessRuntimeVersion adds an attribute with the version of the runtime of
// this process to the configured Resource.
func WithProcessRuntimeVersion() Option {
return WithDetectors(processRuntimeVersionDetector{})
}

// WithProcessRuntimeDescription adds an attribute with an additional description
// about the runtime of the process to the configured Resource.
func WithProcessRuntimeDescription() Option {
return WithDetectors(processRuntimeDescriptionDetector{})
}
21 changes: 0 additions & 21 deletions sdk/resource/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,6 @@ func (osDescriptionDetector) Detect(ctx context.Context) (*Resource, error) {
), nil
}

// WithOSType adds an attribute with the operating system type to the configured Resource.
func WithOSType() Option {
return WithDetectors(osTypeDetector{})
}

// WithOSDescription adds an attribute with the operating system description to the
// configured Resource. The formatted string is equivalent to the output of the
// `uname -snrvm` command.
func WithOSDescription() Option {
return WithDetectors(osDescriptionDetector{})
}

// WithOS adds all the OS attributes to the configured Resource.
// See individual WithOS* functions to configure specific attributes.
func WithOS() Option {
return WithDetectors(
osTypeDetector{},
osDescriptionDetector{},
)
}

// mapRuntimeOSToSemconvOSType translates the OS name as provided by the Go runtime
// into an OS type attribute with the corresponding value defined by the semantic
// conventions. In case the provided OS name isn't mapped, it's transformed to lowercase
Expand Down
50 changes: 0 additions & 50 deletions sdk/resource/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package resource_test

import (
"context"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -38,55 +37,6 @@ func mockRuntimeProviders() {
)
}

func TestWithOSType(t *testing.T) {
mockRuntimeProviders()
t.Cleanup(restoreAttributesProviders)

ctx := context.Background()

res, err := resource.New(ctx,
resource.WithOSType(),
)

require.NoError(t, err)
require.EqualValues(t, map[string]string{
"os.type": "linux",
}, toMap(res))
}

func TestWithOSDescription(t *testing.T) {
mockRuntimeProviders()
t.Cleanup(restoreAttributesProviders)

ctx := context.Background()

res, err := resource.New(ctx,
resource.WithOSDescription(),
)

require.NoError(t, err)
require.EqualValues(t, map[string]string{
"os.description": "Test",
}, toMap(res))
}

func TestWithOS(t *testing.T) {
mockRuntimeProviders()
t.Cleanup(restoreAttributesProviders)

ctx := context.Background()

res, err := resource.New(ctx,
resource.WithOS(),
)

require.NoError(t, err)
require.EqualValues(t, map[string]string{
"os.type": "linux",
"os.description": "Test",
}, toMap(res))
}

func TestMapRuntimeOSToSemconvOSType(t *testing.T) {
tt := []struct {
Name string
Expand Down
63 changes: 0 additions & 63 deletions sdk/resource/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,66 +173,3 @@ func (processRuntimeDescriptionDetector) Detect(ctx context.Context) (*Resource,
semconv.ProcessRuntimeDescriptionKey.String(runtimeDescription),
), nil
}

// WithProcessPID adds an attribute with the process identifier (PID) to the
// configured Resource.
func WithProcessPID() Option {
return WithDetectors(processPIDDetector{})
}

// WithProcessExecutableName adds an attribute with the name of the process
// executable to the configured Resource.
func WithProcessExecutableName() Option {
return WithDetectors(processExecutableNameDetector{})
}

// WithProcessExecutablePath adds an attribute with the full path to the process
// executable to the configured Resource.
func WithProcessExecutablePath() Option {
return WithDetectors(processExecutablePathDetector{})
}

// WithProcessCommandArgs adds an attribute with all the command arguments (including
// the command/executable itself) as received by the process the configured Resource.
func WithProcessCommandArgs() Option {
return WithDetectors(processCommandArgsDetector{})
}

// WithProcessOwner adds an attribute with the username of the user that owns the process
// to the configured Resource.
func WithProcessOwner() Option {
return WithDetectors(processOwnerDetector{})
}

// WithProcessRuntimeName adds an attribute with the name of the runtime of this
// process to the configured Resource.
func WithProcessRuntimeName() Option {
return WithDetectors(processRuntimeNameDetector{})
}

// WithProcessRuntimeVersion adds an attribute with the version of the runtime of
// this process to the configured Resource.
func WithProcessRuntimeVersion() Option {
return WithDetectors(processRuntimeVersionDetector{})
}

// WithProcessRuntimeDescription adds an attribute with an additional description
// about the runtime of the process to the configured Resource.
func WithProcessRuntimeDescription() Option {
return WithDetectors(processRuntimeDescriptionDetector{})
}

// WithProcess adds all the Process attributes to the configured Resource.
// See individual WithProcess* functions to configure specific attributes.
func WithProcess() Option {
return WithDetectors(
processPIDDetector{},
processExecutableNameDetector{},
processExecutablePathDetector{},
processCommandArgsDetector{},
processOwnerDetector{},
processRuntimeNameDetector{},
processRuntimeVersionDetector{},
processRuntimeDescriptionDetector{},
)
}
Loading

0 comments on commit 25d739b

Please sign in to comment.