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

chore(instrumentation-pg): Inline incubating constants from @opentelemetry/semantic-conventions #2599

Conversation

nwalters512
Copy link
Contributor

@nwalters512 nwalters512 commented Dec 10, 2024

Which problem is this PR solving?

No other instrumentation packages pin @opentelemetry/semantic-conventions, and from what I can tell, there's no good reason that @opentelemetry/instumentation-pg should be pinning it. When the dependency is pinned, npm can't dedupe it to a higher version, which results in multiple versions of this package being installed.

As decided in open-telemetry/opentelemetry-js#5182 (comment), incubating constants from @opentelemetry/semantic-conventions should be inlined instead of pinning @opentelemetry/semantic-conventions to a particular version.

Short description of the changes

In @opentelemetry/instrumentation-pg, @opentelemetry/semantic-conventions now uses a ^ semver range to allow newer minor versions to be installed.

This PR updates @opentelemetry/instrumentation-pg to include inlined copies of the experimental constants it needs. This, in turn, allows us to unpin @opentelemetry/semantic-conventions.

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.80%. Comparing base (e57f3e4) to head (b8aa803).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2599      +/-   ##
==========================================
+ Coverage   90.79%   90.80%   +0.01%     
==========================================
  Files         169      170       +1     
  Lines        8061     8070       +9     
  Branches     1646     1646              
==========================================
+ Hits         7319     7328       +9     
  Misses        742      742              
Files with missing lines Coverage Δ
...elemetry-instrumentation-pg/src/instrumentation.ts 90.21% <ø> (ø)
...try-instrumentation-pg/src/semantic-conventions.ts 100.00% <100.00%> (ø)
...node/opentelemetry-instrumentation-pg/src/utils.ts 97.65% <ø> (ø)

@maryliag
Copy link
Contributor

The reason for this versioning being pinned, it's because this package is using the incubating entrypoint, which may break on minor bumps.
This was added on purpose here: #2473
Once it's no longer using the incubating, it can be unpinned.

I see other packages that use the incubating entrypoint are not pinning the value, like this one. @pichlermarc do you know if this was just a mistake or we can now unpin for these cases?

@nwalters512
Copy link
Contributor Author

Ah! Apologies, I didn't go digging deep enough. In that case, can I just change this PR to pin to 1.28.0 so that it will be deduped by package managers (at least until 1.29.0 comes out)?

@pichlermarc
Copy link
Member

pichlermarc commented Dec 11, 2024

I see other packages that use the incubating entrypoint are not pinning the value, like this one. @pichlermarc do you know if this was just a mistake or we can now unpin for these cases?

Hi 🙂 I'd say it's a mistake. When using the incubating entrypoint, we should always pin for now until we have a decision on open-telemetry/opentelemetry-js#5182. Sorry for the inconvenience.

@maryliag
Copy link
Contributor

Hi @nwalters512 , looks like we will go with a different approach of copying those specific values from the incubation, see more here: open-telemetry/opentelemetry-js#5182 (comment)

I would be happy to review if that is something you want to work on.

@nwalters512
Copy link
Contributor Author

@maryliag I'd be happy to open some PRs for this! I'll work on instrumentation-pg to start, and I can follow up with other packages that are using the incubating entrypoint.

@maryliag
Copy link
Contributor

thank you @nwalters512!

@nwalters512 nwalters512 changed the title chore(instrumentation-pg): Unpin @opentelemetry/semantic-conventions chore(instrumentation-pg): Inline incubating constants from @opentelemetry/semantic-conventions Dec 11, 2024
Copy link
Contributor Author

@nwalters512 nwalters512 left a comment

Choose a reason for hiding this comment

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

@maryliag I repurposed this PR to include the inlining of the relevant constants.

@@ -65,7 +65,7 @@ import {
METRIC_DB_CLIENT_OPERATION_DURATION,
ATTR_DB_NAMESPACE,
ATTR_DB_OPERATION_NAME,
} from '@opentelemetry/semantic-conventions/incubating';
} from './semantic-conventions';
Copy link
Contributor Author

@nwalters512 nwalters512 Dec 11, 2024

Choose a reason for hiding this comment

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

open-telemetry/opentelemetry-js#5182 (comment) suggested using semconv.ts; I went with semantic-conventions.ts since it directly matches the package name. Happy to use the other suggestion if that's preferred.

Comment on lines +1 to +4
/**
* These constants are considered experimental exports of `@opentelemetry/semantic-conventions`.
* They're being inlined until they're officially exported by `@opentelemetry/semantic-conventions`.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This little comment will appear at the top of this file in other packages; let's workshop it if needed before it proliferates.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, in a third-party instrumentation I have at work that is doing this, I have this block comment:
https://github.com/elastic/elastic-otel-node/blob/690896cb2995a349313b37ae6e609a741676946c/packages/instrumentation-openai/src/semconv.ts#L20-L27

That's perhaps a little wordier than necessary, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed that it's perhaps a bit wordy. I'd be happy to apply any recommendations to the message I have here!

/**
* The number of connections that are currently in state described by the `state` attribute
*
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied these all in full, including the "experimental" warning. Happy to edit this to remove it desired.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think either way is fine.

(Ideally eventually there is some handy tooling for this to help with generation and maintenance of these. I'd played with a start at something, but it is far from ready for others to use:
https://github.com/elastic/elastic-otel-node/blob/main/packages/instrumentation-openai/scripts/semconv-gen.js)

@nwalters512
Copy link
Contributor Author

Sorry about the failing tests, I'll get those fixed up.

@maryliag
Copy link
Contributor

Thank you for working on this!

@trentm would you mind confirming if that is what you had in mind?

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.

@trentm would you mind confirming if that is what you had in mind?

Yes, this is what I had in mind. Thanks!

I added a couple comments and a nit. Good to go as is, however.

Comment on lines +1 to +4
/**
* These constants are considered experimental exports of `@opentelemetry/semantic-conventions`.
* They're being inlined until they're officially exported by `@opentelemetry/semantic-conventions`.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, in a third-party instrumentation I have at work that is doing this, I have this block comment:
https://github.com/elastic/elastic-otel-node/blob/690896cb2995a349313b37ae6e609a741676946c/packages/instrumentation-openai/src/semconv.ts#L20-L27

That's perhaps a little wordier than necessary, though.

/**
* The number of connections that are currently in state described by the `state` attribute
*
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think either way is fine.

(Ideally eventually there is some handy tooling for this to help with generation and maintenance of these. I'd played with a start at something, but it is far from ready for others to use:
https://github.com/elastic/elastic-otel-node/blob/main/packages/instrumentation-openai/scripts/semconv-gen.js)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I have a small preference for "semconv.ts" if others think that is reasonable as the filename. (It is the name I mentioned as an example at https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv)

I'm happy to be overridden by others' opinions on this. The current naming of .ts files in this repo does tend to use this-style.ts rather than using abbreviations in filenames.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I commented on this here too: #2599 (comment)

I'll defer to whatever you or the other maintainers think is best 🙂

trentm pushed a commit that referenced this pull request Jan 17, 2025
… package dependency with caret (`^`) version to sync with other instrumentation packages (#2664)

Refs: #2599 (similar work)
@trentm
Copy link
Contributor

trentm commented Jan 17, 2025

@nwalters512 #2664 is doing the same thing. There was discussion on Slack to refine that one. I'm merging that one and closing this one. Thanks for the changes!

@trentm trentm closed this Jan 17, 2025
@nwalters512 nwalters512 deleted the pg-unpin-semantic-conventions branch January 17, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants