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

Import OpenTelemetry types rather than duplicate #659

Merged
merged 1 commit into from
May 16, 2022

Conversation

tombruijn
Copy link
Member

@tombruijn tombruijn commented May 11, 2022

Use Typescript's import type and export type to include the
OpenTelemetry types into our package without having to copy the code
into our project directly.

This was suggested by @unflxw in PR #651 (comment)

I'm not sure if this is more or less fragile. If the OpenTelemetry
package changes the interface we'd be shipping an older version that
doesn't work with older versions anymore.

The package from which we import is a dev dependency only, and used
during the compile step, and won't ship as a dependency in the final
release.

I got an issue when using the OpenTelemetry SpanProcessor type for the
onEnd function. It doesn't have a second argument.

The onStart also needed another type, from SpanContext to Context.

Use Typescript's `import type` and `export type` to include the
OpenTelemetry types into our package without having to copy the code
into our project directly.

This was suggested by @unflxw in PR
#651 (comment)

I'm not sure if this is more or less fragile. If the OpenTelemetry
package changes the interface we'd be shipping an older version that
doesn't work with older versions anymore.

The package from which we import is a dev dependency only, and used
during the compile step, and won't ship as a dependency in the final
release.

I got an issue when using the OpenTelemetry SpanProcessor type for the
`onEnd` function. It doesn't have a second argument.

The `onStart` also needed another type, from `SpanContext` to `Context`.
@tombruijn tombruijn requested review from luismiramirez and unflxw May 11, 2022 13:21
@tombruijn tombruijn self-assigned this May 11, 2022
@tombruijn
Copy link
Member Author

@unflxw is this what you had in mind?

@unflxw
Copy link
Contributor

unflxw commented May 11, 2022

@tombruijn Yes, this is what I had in mind :) I hoped we could remove the file in interfaces/ entirely, but if we want to re-export those types, that's okay.

If possible, I'd wait for @jeffkreeftmeijer's input on this as well? There may be something I'm missing that makes the previous approach preferable.

@tombruijn
Copy link
Member Author

Ok, asking for a review from Jeff as well.

Copy link
Member

@jeffkreeftmeijer jeffkreeftmeijer left a comment

Choose a reason for hiding this comment

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

I added that interface to save us a dependency on @opentelemetry/sdk-trace-base, to allow us to only depend on the types package, but this seems to make more sense indeed.

@tombruijn tombruijn merged commit ee1ea8b into main May 16, 2022
tombruijn added a commit that referenced this pull request Jun 8, 2022
In PR #659 we tried to import the OpenTelemetry types at compile time
and include them in our own package, but that's not how TypeScript's
`import type` turns out to work.

This breaks the app for non-OpenTelemetry users as reported in #684. The
easiest fix we can ship right now is to add the package as a runtime
dependency rather than only a development dependency.

Ideally though, we do not ship additional dependencies for thing not all
our users use, but we can figure that out after this immediate fix.

I had missed this in PR #659, but we've also already included the
`@opentelemetry/api` as a dependency since PR #651. Already doing the
same this change does for the `@opentelemetry/sdk-trace-base` package.
tombruijn added a commit that referenced this pull request Jun 8, 2022
In PR #659 we tried to import the OpenTelemetry types at compile time
and include them in our own package, but that's not how TypeScript's
`import type` turns out to work.

This breaks the app for non-OpenTelemetry users as reported in #684. The
easiest fix we can ship right now is to add the package as a runtime
dependency rather than only a development dependency.

Ideally though, we do not ship additional dependencies for thing not all
our users use, but we can figure that out after this immediate fix.

I had missed this in PR #659, but we've also already included the
`@opentelemetry/api` as a dependency since PR #651. Already doing the
same this change does for the `@opentelemetry/sdk-trace-base` package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants