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

feat: Add WithResourceOption for additional resource configuration #48

Merged
merged 8 commits into from
Jul 27, 2023

Conversation

robbkidd
Copy link
Member

@robbkidd robbkidd commented Jun 1, 2023

Which problem is this PR solving?

We are unable to add resource detectors when configuring the launcher.

Short description of the changes

Implementation starts with what was written for #47 with smoke tests added to verify the order of precedence for resources attributes from environment over code.

[vera] upon further inspection, the original behavior of CODE attributes winning over ENV attributes was valid:

The SDK MUST extract information from the OTEL_RESOURCE_ATTRIBUTES environment variable and merge this, as the secondary resource, with any resource information provided by the user, i.e. the user provided resource information has higher priority.
OTel Resource SDK spec

“user provided resource information” -- the user could mean the application code writer OR the operator setting environment variables. It’s ambiguous! And not settled in the spec: open-telemetry/opentelemetry-specification#1620

See note in that issue:

others in the Go SIG have interpreted this passage to require that resource attributes from the environment must be subordinated to any resource attributes provided by the developer-user

This is how the underlying Go SDK works, as designed.

The CODE>ENV decision was also made in the Ruby SDK: https://github.com/robertlaurin/opentelemetry-ruby/blob/0c03e4aee09093ce0d80142e13a35326aad9f877/sdk/test/opentelemetry/sdk/configurator_test.rb#L35

Description from original PR:

Rather than adding a specific WithDetectors func to mirror the functionality in the resource package this adds a more generic version so that any resource option configuration can be provided.

This has been done in a backwards compatible manner but I could see a future where the WithResourceAttributes function is removed as it is duplicate functionality now.

How to verify that this has the expected result

  • Unit tests - logic's probably sound
  • Smoke tests - interaction with config from environment behaves according to spec

@robbkidd robbkidd requested a review from a team June 1, 2023 21:09
@robbkidd robbkidd force-pushed the robb.smoke-resources branch from 23ece81 to 7856679 Compare June 1, 2023 21:14
@robbkidd robbkidd added the type: bug Something isn't working label Jun 1, 2023
@robbkidd robbkidd force-pushed the robb.smoke-resources branch from 7856679 to a3c9917 Compare June 1, 2023 21:18
examples/main.go Outdated

if err != nil {
log.Fatalf("error setting up OTel SDK - %e", err)
}

defer otelShutdown()
tracer := otel.Tracer("my-app")
ctx := context.Background()
ctx, span := tracer.Start(ctx, "doing-things")
_, span := tracer.Start(context.Background(), "doing-things")
Copy link
Member Author

Choose a reason for hiding this comment

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

I … don't know why I included this. It has nothing to do with the resource attributes issue. 😐

@robbkidd robbkidd added the status: oncall Flagged for awareness from Honeycomb Telemetry Oncall label Jun 1, 2023
martin308 and others added 2 commits June 2, 2023 12:28
## Which problem is this PR solving?

We are unable to add resource detectors when configuring the launcher.

- Closes #12

## Short description of the changes

Rather than adding a specific `WithDetectors` func to mirror the
functionality in the [resource
package](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/resource#WithDetectors)
this adds a more generic version so that any resource option
configuration can be provided.

This has been done in a backwards compatible manner but I could see a
future where the `WithResourceAttributes` function is removed as it is
duplicate functionality now.

## How to verify that this has the expected result

Unit tests have been added
Per the OTel spec, resource attributes set via environment variable must
supercede resource attributes set in code.[1]

[1] https://opentelemetry.io/docs/specs/otel/resource/sdk/#specifying-resource-information-via-an-environment-variable
@robbkidd robbkidd force-pushed the robb.smoke-resources branch from a3c9917 to d23bbf7 Compare June 2, 2023 16:28
@robbkidd robbkidd changed the title fix: WithResource clobbers resource attrs set via env var feat: Add WithResource for setting resource attributes in code Jun 2, 2023
@robbkidd
Copy link
Member Author

robbkidd commented Jun 2, 2023

What's up with the revert/readd of this feature?

Resource attributes set via environment variable must supercede resource attributes set in code.

The SDK MUST extract information from the OTEL_RESOURCE_ATTRIBUTES environment variable and merge this, as the secondary resource, with any resource information provided by the user, i.e. the user provided resource information has higher priority.
OTel Resource SDK spec

#47 introduced WithResource() but the current order of merging resource attributes has code-provided attributes (from this function) clobbering user-provided attributes from the environment. It's important to remember that the "user" mentioned by the spec is not the developer writing application code, it's the person using the application later at runtime.

@robbkidd robbkidd added type: enhancement New feature or request and removed type: bug Something isn't working status: oncall Flagged for awareness from Honeycomb Telemetry Oncall labels Jun 2, 2023
otelconfig/otelconfig.go Outdated Show resolved Hide resolved
“user provided resource information” the user could mean the application code writer OR the operator setting environment variables. It’s ambiguous! And not settled in the spec: open-telemetry/opentelemetry-specification#1620

See note in that issue: others in the Go SIG have interpreted this passage to require that resource attributes from the environment must be subordinated to any resource attributes provided by the developer-user

This is how the underlying Go SDK works, as designed.

The CODE>ENV decision was also made in the Ruby SDK: https://github.com/robertlaurin/opentelemetry-ruby/blob/0c03e4aee09093ce0d80142e13a35326aad9f877/sdk/test/opentelemetry/sdk/configurator_test.rb#L35
@vreynolds
Copy link
Contributor

Updated the description with my reasoning for walking back on the premise of the revert. I believe code config wins over env config, at least in the Go SDK land.

@vreynolds vreynolds assigned vreynolds and unassigned robbkidd Jul 27, 2023
@vreynolds vreynolds added the version: bump minor A PR that adds behavior, but is backwards-compatible. label Jul 27, 2023
@vreynolds vreynolds changed the title feat: Add WithResource for setting resource attributes in code feat: Add WithResourceOption for additional resource configuration Jul 27, 2023
Copy link
Contributor

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

It seems like we're still doing some extra work here that could be simplified by using the available resource options now available upstream, but that can be addressed separately. This at least allows the end user more flexibility in setting additional resource options. Appreciate the PR details and the test cleanup as well 👍

@vreynolds vreynolds merged commit f4716a6 into main Jul 27, 2023
@vreynolds vreynolds deleted the robb.smoke-resources branch July 27, 2023 21:33
JamieDanielson pushed a commit that referenced this pull request Aug 14, 2023
## Which problem is this PR solving?

When using detectors with mis-matched Schema URLs, resource.New will
return an error. Previously, this was dropped and consequently it looked
like configuration worked but many resource attributes would be missing
in the resulting telemetry.

With the recent addition of
#48, this error is
much easier to hit. For example, the detectors built into
opentelemetry-go
[import](https://github.com/open-telemetry/opentelemetry-go/blob/main/sdk/resource/builtin.go#L25)
semconv `v1.17.0` but this project [pulls
in](https://github.com/honeycombio/otel-config-go/blob/main/otelconfig/otelconfig.go#L21)
`v1.18.0`. This means that adding something like
`otelconfig.WithResourceOption(resource.WithHost())` results in a
mis-configured OTel and no error to warn you what happened.

This is all … very bad. This PR is really the bare minimum that needs to
be done here. That is, it at least causes a runtime error so that you
can tell what's going on — but it doesn't solve the problem that you
fundamentally cannot use this library with _any_ other library that
doesn't happen to use semconv `v1.18.0`. There are [a
number](open-telemetry/opentelemetry-go#2341)
of
[open](open-telemetry/opentelemetry-go#3769)
[issues](open-telemetry/opentelemetry-go-contrib#3657)
in OTel and adjacent repositories regarding this problem, which probably
warrant further investigation into a long-term sustainable solution.

## Short description of the changes

Return the `err` from `resource.New` up through the stack. Update tests
to expect this.

⚠️ I guess technically this could be considered a backwards incompatible
change, in that folks may have configurations that are "working" today
but will throw an error after this change. I put that in scare quotes
though because it's not _really_ working — it's just not throwing an
error. I feel like actually returning an appropriate error here and
letting folks know their configuration is likely not working as expected
is the right choice.

## How to verify that this has the expected result

There's a new test that specifically uses a detector with a different
schema URL.

Co-authored-by: Vera Reynolds <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request version: bump minor A PR that adds behavior, but is backwards-compatible.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support adding custom resource.Detectors / resource.Options
5 participants