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(otlp-transformer): Do not limit @opentelemetry/api upper range peerDependency #4816

Merged
merged 5 commits into from
Jul 30, 2024

Conversation

mydea
Copy link
Contributor

@mydea mydea commented Jun 21, 2024

Today, some packages define a peer dependency on @opentelemetry/api that explicitly excludes future versions in the 1.x range. IMHO this is not helpful because 1.x release have to be backwards compatible anyhow, but this can lead to version conflicts when using different packages. I believe that it should be safe enough to simply have ^1.3.0 as peer dependency?

Fixes #4815

@mydea mydea requested a review from a team June 21, 2024 10:02
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

packages/sdk-metrics/package.json Outdated Show resolved Hide resolved
@@ -59,7 +59,7 @@
"README.md"
],
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.10.0"
"@opentelemetry/api": "^1.3.0"
Copy link
Member

Choose a reason for hiding this comment

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

This here is fine to unpin as it does not implement the API. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I think I kind of get it now. Took me some time and iterations to really wrap my head around this. I think what confused me additionally is that this package here had this (which, as you stated, does not need it), which is also how we stumbled over this problem in the first place. So I'll just fix this one place instead! 👍

experimental/packages/opentelemetry-sdk-node/package.json Outdated Show resolved Hide resolved
@lforst
Copy link
Contributor

lforst commented Jun 24, 2024

@pichlermarc I am also following this thread.

I struggle to understand the reasoning for clamping the version range like this. Especially considering the spec you linked:

When new functionality is added to the OpenTelemetry API, a new minor version of
the API is released. These API changes are always additive and backwards compatible
from the perspective of existing Instrumentation packages which import and call
prior versions. Instrumentation written against all prior minor versions of the
API continues to work, and may be composed together into the same application without
creating a dependency conflict.

To me, this would very much indicate that it is absolutely safe to allow for a specific version and above within a major (^). I might totally be missing something.

Do you happen to have an example for how this is necessary?

I understand that extending an interface will be fine for consumers, but break for implementors, however, that seems to be forbidden by the spec and instead replacement interfaces should be provided:

Instead of breaking a Plugin Interface, a new interface is created and the existing interface
is marked as deprecated. Plugins which target the deprecated interface continue
to work, and the SDK provides default implementations of any missing functionality.
After one year, the deprecated Plugin Interface may be removed in a major version
release of the SDK.

@pichlermarc
Copy link
Member

Do you happen to have an example for how this is necessary?

Example: Adding a new instrument to the Meter interface in the API.

I understand that extending an interface will be fine for consumers, but break for implementors, however, that seems to be forbidden by the spec and instead replacement interfaces should be provided:

Instead of breaking a Plugin Interface, a new interface is created and the existing interface
is marked as deprecated. Plugins which target the deprecated interface continue
to work, and the SDK provides default implementations of any missing functionality.
After one year, the deprecated Plugin Interface may be removed in a major version
release of the SDK.

There's a difference between the API and the SDK.
This Section relates to the SDK (and Plugin interfaces - like Instrumentation, SpanExporter, SpanProcessor, etc.). Compared to the API the SDK may actually receive major version bumps where these deprecated types can be removed. The API spec is much more restrictive on that.

@mydea mydea changed the title feat: Do not limit @opentelemetry/api upper range peerDependency feat(otlp-transformer): Do not limit @opentelemetry/api upper range peerDependency Jun 26, 2024
@mydea
Copy link
Contributor Author

mydea commented Jun 26, 2024

I updated this to only unclamp this for otlp-transformer! @pichlermarc thanks for the explanations!

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Thanks 👍
Please also add a changelog entry, then we can merge this. 🙂

A side note about this situation: I agree that ideally we'd have an API setup that allows for just depending on the caret range, no matter if you're implementor or consumer. We may be able to do such a thing but we'd need to do a lot of prototyping before we can consider changing the API in such a way. There are a lot of edge-cases that come with providing a "partial" no-op (which would be the natural result of that) that can cause issues.

The spec kind of intends it to be this way and I can see the original reasoning behind that choice. However, combined with some TypeScript/NPM limitations it ends up being quite clunky and not very user-friendly.

I think we should have at least documentation about API limitations and best-practices (it was also hard to wrap my head around the topic when I joined the SIG).

@lforst
Copy link
Contributor

lforst commented Jun 28, 2024

Me and @mydea thought a lot about this offline and I settled my mental model on the fact that SemVer is sometimes actually really hard to properly get right when you have implementors. It becomes a trade-off between wanting to be super correct, and being user-friendly but risking breakage. In theory, even simple stuff that you may think will never break anybody, like for example turning the return type of a simple exported function from void to string may break somebody's implementation.

In our packages in the Sentry JS SDKs we probably don't adhere to SemVer in the strictest of ways (still we never had anybody complain). The only API where we are careful is our Client (which is the only realistic API surface that people actually may implement themselves): https://github.com/getsentry/sentry-javascript/blob/5eafa401c076796fba7663dad9ca254ab6f1972f/packages/types/src/client.ts#L30

Here, whenever we want to add surface, we first add it as optional field, and then in a major we may make it non-optional. This comes with a bit of internal implementation complexity but it is probably worth it. I am not familiar enough with the OTEL implementations and whether OTEL already has this pattern but I still wanted to bring it up for posterity.

@mydea
Copy link
Contributor Author

mydea commented Jul 1, 2024

I added a changelog entry, I figure this is an enhancement 🤔

Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Leaving to Marc to merge. He's the "otlp-transformer" and "exporter"-king.

@pichlermarc pichlermarc added this pull request to the merge queue Jul 30, 2024
Merged via the queue into open-telemetry:main with commit 1cf1939 Jul 30, 2024
19 checks passed
@dyladan dyladan mentioned this pull request Aug 2, 2024
Zirak pushed a commit to Zirak/opentelemetry-js that referenced this pull request Sep 14, 2024
… peerDependency (open-telemetry#4816)

* feat: Do not limit `@opentelemetry/api` upper range peerDependency

* Revert "feat: Do not limit `@opentelemetry/api` upper range peerDependency"

This reverts commit d0dd3d5.

* only unclamp otlp-transformer

* Add changelog entry

---------

Co-authored-by: Marc Pichler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Widen peerDependency range for @opentelemetry/api
4 participants