Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove resource.WithBuiltinDetectors which has not been maintained #2097

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 resource.WithBuiltinDetectors() function in favor of explicit WithFeature() options for every built-in detector. (#2026)
hanyuancheung marked this conversation as resolved.
Show resolved Hide resolved

### 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 k as well as the specific schemaURL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does k refer to here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It stands for attribute.Key .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comment here to make it clear.

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.
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
// 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