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

Fix missing Aggregate re-exports #14886

Merged
merged 1 commit into from
Sep 12, 2024
Merged

Conversation

wongsean
Copy link
Contributor

@wongsean wongsean commented Sep 12, 2024

Summary

While using Sentry (with OpenTelemetry as the underlying system) to instrument Mongoose in my project, I encountered the following error:

2024-09-12 11:26:31.183 TypeError: Cannot read properties of undefined (reading ‘prototype’)
2024-09-12 11:26:31.183     at MongooseInstrumentation.patch (/usr/src/app/node_modules/.pnpm/@opentelemetry+instrumentation-mongoose@0.42.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation-mongoose/build/src/mongoose.js:94:44)
2024-09-12 11:26:31.183     at MongooseInstrumentation._onRequire (/usr/src/app/node_modules/.pnpm/@opentelemetry+instrumentation@0.53.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:164:39)
2024-09-12 11:26:31.183     at hookFn (/usr/src/app/node_modules/.pnpm/@opentelemetry+instrumentation@0.53.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:222:29)
2024-09-12 11:26:31.183     at callHookFn (/usr/src/app/node_modules/.pnpm/import-in-the-middle@1.11.0/node_modules/import-in-the-middle/index.js:29:22)
2024-09-12 11:26:31.183     at Hook._iitmHook (/usr/src/app/node_modules/.pnpm/import-in-the-middle@1.11.0/node_modules/import-in-the-middle/index.js:150:11)
2024-09-12 11:26:31.183     at /usr/src/app/node_modules/.pnpm/import-in-the-middle@1.11.0/node_modules/import-in-the-middle/lib/register.js:28:31
2024-09-12 11:26:31.183     at Array.forEach (<anonymous>)
2024-09-12 11:26:31.183     at register (/usr/src/app/node_modules/.pnpm/import-in-the-middle@1.11.0/node_modules/import-in-the-middle/lib/register.js:28:15)
2024-09-12 11:26:31.183     at file:///usr/src/app/node_modules/.pnpm/mongoose@8.3.4_@aws-sdk+credential-providers@3.649.0_socks@2.8.3/node_modules/mongoose/index.js?iitm=true:381:1
2024-09-12 11:26:31.183     at ModuleJob.run (node:internal/modules/esm/module_job:222:25)

Upon investigation, I found that the issue is caused by a missing re-export of Aggregate in Mongoose’s ESM exports.

Examples

I was able to temporarily resolve the issue by adding the following command to my project’s Dockerfile:

# Hack to fix otel mongoose instruementation issue
RUN echo "module.exports.Aggregate = mongoose.Aggregate;" >> /usr/src/app/node_modules/.pnpm/mongoose@8.3.4_@aws-sdk+credential-providers@3.650.0_socks@2.8.3/node_modules/mongoose/index.js

@vkarpov15 vkarpov15 merged commit 1b18d5b into Automattic:master Sep 12, 2024
22 checks passed
@vkarpov15 vkarpov15 added this to the 8.6.3 milestone Sep 12, 2024
@wongsean wongsean deleted the patch-1 branch September 13, 2024 07:10
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.

2 participants