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 2 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 @@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Removed the deprecated package `go.opentelemetry.io/otel/exporters/metric/prometheus`. (#2020)
- 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 which has not been maintained. (#2026)
hanyuancheung marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
4 changes: 3 additions & 1 deletion sdk/resource/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
// disable them.
host struct{}

// stringDetector is a Detector that provides information about the
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an incomplete sentence. Maybe something got cutoff?

stringDetector struct {
schemaURL string
K attribute.Key
Expand Down Expand Up @@ -78,7 +79,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
31 changes: 24 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,27 @@ 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{},
)
}

// 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{},
)
}
9 changes: 0 additions & 9 deletions sdk/resource/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,3 @@ func WithOSType() Option {
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{},
)
}
15 changes: 0 additions & 15 deletions sdk/resource/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,3 @@ func WithProcessRuntimeVersion() Option {
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{},
)
}
9 changes: 8 additions & 1 deletion sdk/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ var (
otel.Handle(err)
}
return r
}(Detect(context.Background(), defaultServiceNameDetector{}, fromEnv{}, telemetrySDK{}))
}(
Detect(
context.Background(),
defaultServiceNameDetector{},
fromEnv{},
telemetrySDK{},
),
)
)

var (
Expand Down
65 changes: 3 additions & 62 deletions sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,9 @@ func TestNew(t *testing.T) {
},
},
{
name: "Builtins",
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
envars: "key=value,other=attr",
options: []resource.Option{
resource.WithBuiltinDetectors(),
},
name: "Builtins",
envars: "key=value,other=attr",
options: []resource.Option{},
resourceValues: map[string]string{
"host.name": hostname(),
"telemetry.sdk.name": "opentelemetry",
Expand Down Expand Up @@ -457,63 +455,6 @@ func TestNew(t *testing.T) {
}
}

func TestNewWithBuiltinDetectors(t *testing.T) {
tc := []struct {
name string
envars string
detectors []resource.Detector
options []resource.Option

resourceValues map[string]string
}{
{
name: "No Options returns builtin",
envars: "key=value,other=attr",
options: nil,
resourceValues: map[string]string{
"host.name": hostname(),
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.language": "go",
"telemetry.sdk.version": otel.Version(),
"key": "value",
"other": "attr",
},
},
{
name: "WithAttributes",
envars: "key=value,other=attr",
options: []resource.Option{
resource.WithAttributes(attribute.String("A", "B")),
},
resourceValues: map[string]string{
"host.name": hostname(),
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.language": "go",
"telemetry.sdk.version": otel.Version(),
"key": "value",
"other": "attr",
"A": "B",
},
},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
store, err := ottest.SetEnvVariables(map[string]string{
envVar: tt.envars,
})
require.NoError(t, err)
defer func() { require.NoError(t, store.Restore()) }()

ctx := context.Background()
options := append([]resource.Option{resource.WithBuiltinDetectors()}, tt.options...)
res, err := resource.New(ctx, options...)

require.NoError(t, err)
require.EqualValues(t, tt.resourceValues, toMap(res))
})
}
}

func toMap(res *resource.Resource) map[string]string {
m := map[string]string{}
for _, attr := range res.Attributes() {
Expand Down