|
| 1 | +# feat(core): Add `@sentry/core/light` sub-path export to reduce import time for lightweight consumers |
| 2 | + |
| 3 | +**Repo**: https://github.com/getsentry/sentry-javascript |
| 4 | + |
| 5 | +## Problem |
| 6 | + |
| 7 | +`@sentry/core` has a single barrel entry point (`index.js`) that eagerly loads **179 ESM modules** (~776 KB). This includes: |
| 8 | + |
| 9 | +- AI tracing integrations: OpenAI, Anthropic, Google GenAI, LangChain, LangGraph, Vercel AI SDK (21 files, ~170 KB) |
| 10 | +- MCP server integration (14 files, ~160 KB) |
| 11 | +- Supabase integration (1 file, ~14 KB) |
| 12 | +- Feature flags integrations (3 files, ~8 KB) |
| 13 | +- Other unused server-framework-specific code: tRPC, fetch instrumentation, idle spans, etc. |
| 14 | + |
| 15 | +Even `@sentry/node-core/light`, which was designed to be lightweight, re-exports from the full `@sentry/core` barrel, forcing consumers to pay the entire import cost. |
| 16 | + |
| 17 | +## Measured Impact |
| 18 | + |
| 19 | +On our Bun CLI project ([getsentry/cli](https://github.com/getsentry/cli)): |
| 20 | + |
| 21 | +| Configuration | `@sentry/core` Import Time | |
| 22 | +|---|---| |
| 23 | +| Full barrel (current) | **~40ms** | |
| 24 | +| Barrel with 29 unused export lines removed (59 transitive modules, 310 KB) | **~27ms** | |
| 25 | + |
| 26 | +That's a **33% improvement** just by removing modules that lightweight consumers never use. |
| 27 | + |
| 28 | +## Proposal |
| 29 | + |
| 30 | +Add a `@sentry/core/light` sub-path export (similar to `@sentry/node-core/light`) that excludes: |
| 31 | + |
| 32 | +- AI tracing integrations (OpenAI, Anthropic, Google GenAI, LangChain, LangGraph, Vercel AI SDK) |
| 33 | +- MCP server integration |
| 34 | +- Supabase integration |
| 35 | +- Feature flags integrations (featureFlagsIntegration, growthbookIntegration) |
| 36 | +- Server-framework-specific code (tRPC middleware, fetch instrumentation, idle spans) |
| 37 | +- Other heavy modules not needed for basic error/tracing/session/logs usage |
| 38 | + |
| 39 | +Then `@sentry/node-core/light` could import from `@sentry/core/light` instead of `@sentry/core`, further reducing the startup cost of lightweight mode. |
| 40 | + |
| 41 | +## Our Patch (for reference) |
| 42 | + |
| 43 | +We're currently removing these 32 export lines from the barrel via `bun patch`: |
| 44 | + |
| 45 | +``` |
| 46 | +export { TRACING_DEFAULTS, startIdleSpan } from './tracing/idleSpan.js'; |
| 47 | +export { _INTERNAL_clearAiProviderSkips, ... } from './utils/ai/providerSkip.js'; |
| 48 | +export { moduleMetadataIntegration } from './integrations/moduleMetadata.js'; |
| 49 | +export { captureConsoleIntegration } from './integrations/captureconsole.js'; |
| 50 | +export { dedupeIntegration } from './integrations/dedupe.js'; |
| 51 | +export { extraErrorDataIntegration } from './integrations/extraerrordata.js'; |
| 52 | +export { rewriteFramesIntegration } from './integrations/rewriteframes.js'; |
| 53 | +export { instrumentSupabaseClient, supabaseIntegration } from './integrations/supabase.js'; |
| 54 | +export { instrumentPostgresJsSql } from './integrations/postgresjs.js'; |
| 55 | +export { zodErrorsIntegration } from './integrations/zoderrors.js'; |
| 56 | +export { thirdPartyErrorFilterIntegration } from './integrations/third-party-errors-filter.js'; |
| 57 | +export { featureFlagsIntegration } from './integrations/featureFlags/featureFlagsIntegration.js'; |
| 58 | +export { growthbookIntegration } from './integrations/featureFlags/growthbook.js'; |
| 59 | +export { conversationIdIntegration } from './integrations/conversationId.js'; |
| 60 | +export { profiler } from './profiling.js'; |
| 61 | +export { instrumentFetchRequest } from './fetch.js'; |
| 62 | +export { trpcMiddleware } from './trpc.js'; |
| 63 | +export { wrapMcpServerWithSentry } from './integrations/mcp-server/index.js'; |
| 64 | +export { addVercelAiProcessors } from './tracing/vercel-ai/index.js'; |
| 65 | +export { _INTERNAL_cleanupToolCallSpanContext, ... } from './tracing/vercel-ai/utils.js'; |
| 66 | +export { toolCallSpanContextMap as ... } from './tracing/vercel-ai/constants.js'; |
| 67 | +export { instrumentOpenAiClient } from './tracing/openai/index.js'; |
| 68 | +export { OPENAI_INTEGRATION_NAME } from './tracing/openai/constants.js'; |
| 69 | +export { instrumentAnthropicAiClient } from './tracing/anthropic-ai/index.js'; |
| 70 | +export { ANTHROPIC_AI_INTEGRATION_NAME } from './tracing/anthropic-ai/constants.js'; |
| 71 | +export { instrumentGoogleGenAIClient } from './tracing/google-genai/index.js'; |
| 72 | +export { GOOGLE_GENAI_INTEGRATION_NAME } from './tracing/google-genai/constants.js'; |
| 73 | +export { createLangChainCallbackHandler } from './tracing/langchain/index.js'; |
| 74 | +export { LANGCHAIN_INTEGRATION_NAME } from './tracing/langchain/constants.js'; |
| 75 | +export { instrumentLangGraph, instrumentStateGraphCompile } from './tracing/langgraph/index.js'; |
| 76 | +export { LANGGRAPH_INTEGRATION_NAME } from './tracing/langgraph/constants.js'; |
| 77 | +export { _INTERNAL_FLAG_BUFFER_SIZE, ... } from './utils/featureFlags.js'; |
| 78 | +``` |
| 79 | + |
| 80 | +We also remove the corresponding re-exports from `@sentry/node-core/light/index.js`. |
| 81 | + |
| 82 | +Happy to contribute a PR if the approach is accepted. |
0 commit comments