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

Clumsy resource.New options #1690

Closed
MrAlias opened this issue Mar 10, 2021 · 6 comments
Closed

Clumsy resource.New options #1690

MrAlias opened this issue Mar 10, 2021 · 6 comments
Assignees
Labels
area:resources Part of OpenTelemetry resources pkg:SDK Related to an SDK package
Milestone

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Mar 10, 2021

The WithFromEnv, WithHost, and WithTelemetrySDK options that are passed to New all accept a Detector as an argument. This Detector is stated to be used as an alternate to the builtin Detector that finds the related resource attributes, or if nil will omit those resource attributes. This feels very clumsy.

For instance, there is not guarantee that a Detector is passed to WithTelemetrySDK that will detect telemetry.sdk.* attributes. It could detect whatever attributes it wants. The only meaningful effect including this option will have is that it will not include the builtin detector (nil or otherwise).

Based on this behavior, it seems like these options should be changed to Without* versions of themselves. If a user wants to provide a custom detector to override these attributes they can use the WithDetectors option.

Proposal

@MrAlias MrAlias added pkg:SDK Related to an SDK package release:required-for-ga area:resources Part of OpenTelemetry resources labels Mar 10, 2021
@MrAlias MrAlias added this to the RC1 milestone Mar 10, 2021
@seh
Copy link
Contributor

seh commented Mar 10, 2021

I think this approach won't age well, as we will have users relying on these functions that would later turn out to have no effect if we were to revise which things the default detectors handle automatically. In other words, say that we later decide that we shouldn't detect the host-related details automatically. We would have users calling WithoutHost, which would no longer have any effect, and we'd probably then need to introduce withHost again.

@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 10, 2021

@seh what is your proposal?

@seh
Copy link
Contributor

seh commented Mar 10, 2021

We have WithoutBuiltin, which takes care of clearing all of them. What if we recast the three above to not take a Detector parameter, and made them niladic instead? We could document the default behavior as being equivalent to having passed WithFromEnv(), WithHost(), and WithTelemetrySDK(). If you don't want all of them, pass WithoutBuiltin() followed by whichever of those three you'd like to add back in.

What I could possibly see someone griping about is not knowing all of things that are built in, but wanting to just knock one of them out—"all of them except this one that I know I don't want." It feels like a problem in want of a bitmask.

@MadVikingGod
Copy link
Contributor

What if we remove the three WithFromEnv, WithHost, and WithTelemetrySDK and use the default ones unless WithDetectors is used.

To make it convenient to add your own detector and have the builtins, we could have an exported slice of BuiltinDetectors. The New call would then look like this:

resource.New(
    WithDetectors(BuiltinDetectors...),
    WithDetectors(MyCustomDetector),
)

@MadVikingGod
Copy link
Contributor

@seh I put in a PR just toying around with this. Can you take a look and see if that format would be more approachable?

@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 29, 2021

Closed with #1810

@MrAlias MrAlias closed this as completed Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:resources Part of OpenTelemetry resources pkg:SDK Related to an SDK package
Projects
None yet
Development

No branches or pull requests

3 participants