Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/server-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"@sentry/core": "11.9.0"
},
"devDependencies": {
"@apm-js-collab/code-transformer-bundler-plugins": "^0.7.4",
"@apm-js-collab/code-transformer-bundler-plugins": "^0.7.5",
"@neondatabase/serverless": "1.2.0",
"@sentry-internal/rollup-utils": "11.9.0",
"@types/node": "^20.19.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/server-utils/src/orchestrion/bundler/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import { externalEntryMatchesModule, externalizedModulesWarning, orchestrionTran

// Explicitly annotated with the vendored types so the emitted declaration doesn't reference
// `@apm-js-collab/code-transformer-bundler-plugins` — a bundled devDependency consumers don't have.
export const serializeInstrumentations: (configs: AnyInstrumentationConfig[]) => SerializableInstrumentationConfig[] =
serializeInstrumentationsImpl;
// Upstream also allows a function in `transform`. The vendored configs only allow a string there,
// and the serializer copies `transform` unchanged, so its output only contains strings too.
export const serializeInstrumentations = serializeInstrumentationsImpl as (
configs: AnyInstrumentationConfig[],
) => SerializableInstrumentationConfig[];
export type { SerializableInstrumentationConfig } from '../apmTypes';

export { getOrchestrionLoaderPath, resolveOrchestrionRuntimeRequest };
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/test/orchestrion/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InstrumentationConfig } from '@apm-js-collab/code-transformer-bundler-plugins/core';
import type { InstrumentationConfig } from '../../src/orchestrion/apmTypes';
import { describe, expect, it } from 'vitest';
import {
getInstrumentedModuleNames,
Expand Down
59 changes: 59 additions & 0 deletions packages/server-utils/test/orchestrion/sourcemap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { build, type Plugin, type Rollup } from 'vite';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import type { InstrumentationConfig } from '../../src/orchestrion/apmTypes';
import { sentryOrchestrionPlugin as sentryOrchestrionRollupPlugin } from '../../src/orchestrion/bundler/rollup';
import { sentryOrchestrionPlugin as sentryOrchestrionVitePlugin } from '../../src/orchestrion/bundler/vite';

const instrumentations: InstrumentationConfig[] = [
{
channelName: 'query',
module: { name: 'fake-db', versionRange: '>=1.0.0', filePath: 'index.js' },
functionQuery: { expressionName: 'query', kind: 'Sync' },
},
];

describe('orchestrion bundler plugins source maps', () => {
let root: string;

beforeAll(() => {
root = mkdtempSync(join(tmpdir(), 'orchestrion-sourcemap-'));
const packageDir = join(root, 'node_modules', 'fake-db');
mkdirSync(packageDir, { recursive: true });
writeFileSync(join(packageDir, 'package.json'), JSON.stringify({ name: 'fake-db', version: '1.0.0' }));
writeFileSync(join(packageDir, 'index.js'), 'exports.query = function query(sql) {\n return sql;\n};\n');
writeFileSync(
join(root, 'server.js'),
"import { query } from 'fake-db';\nexport const run = () => query('SELECT 1');\n",
);
});

afterAll(() => rmSync(root, { recursive: true, force: true }));

// https://github.com/getsentry/sentry-javascript/issues/25329
it.each([
['vite', () => sentryOrchestrionVitePlugin({ instrumentations })],
['rollup', () => sentryOrchestrionRollupPlugin({ instrumentations }) as Plugin],
])('maps the transformed module only to its file in node_modules (%s plugin)', async (_name, createPlugin) => {
const output = (await build({
root,
configFile: false,
logLevel: 'silent',
plugins: [createPlugin()],
ssr: { noExternal: ['fake-db'] },
build: {
ssr: 'server.js',
sourcemap: true,
write: false,
rollupOptions: { external: ['@sentry/server-utils'] },
},
})) as Rollup.RollupOutput;

const chunk = output.output[0];

expect(chunk.code).toContain('orchestrion:fake-db:query');
expect(chunk.map?.sources).toEqual(['../node_modules/fake-db/index.js', '../server.js']);
});
});
25 changes: 19 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading