Skip to content
Merged
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ jobs:
node-version-file: 'dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/package.json'
- name: Set up Bun
if:
contains(fromJSON('["node-exports-test-app","nextjs-16-bun", "elysia-bun", "hono-4"]'),
contains(fromJSON('["node-exports-test-app","nextjs-16-bun", "elysia-bun", "hono-4", "bun-bytecode"]'),
matrix.test-application)
uses: oven-sh/setup-bun@v2
with:
Expand Down
19 changes: 19 additions & 0 deletions dev-packages/e2e-tests/test-applications/bun-bytecode/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "bun-bytecode-test",
"version": "1.0.0",
"private": true,
"scripts": {
"clean": "npx rimraf node_modules pnpm-lock.yaml dist",
"test:build": "pnpm install && bun build src/main.ts --compile --bytecode --format=esm --outfile dist/main",
"test:assert": "dist/main"
},
"dependencies": {
"@sentry/bun": "file:../../packed/sentry-bun-packed.tgz"
},
"devDependencies": {
"bun-types": "^1.2.9"
},
"volta": {
"extends": "../../package.json"
}
}
11 changes: 11 additions & 0 deletions dev-packages/e2e-tests/test-applications/bun-bytecode/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Verifies that @sentry/bun can be compiled with `bun build --compile --bytecode` without crashing at runtime.
*/
import * as Sentry from '@sentry/bun';

Sentry.init({
dsn: 'https://username@domain/123',
tracesSampleRate: 0,
});

console.log('Bun bytecode compilation: OK');
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"types": ["bun-types"],
"strict": true,
"module": "ESNext",
"moduleResolution": "bundler",
"target": "ESNext"
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NOTICE from the Sentry authors:
* - Vendored locally from @opentelemetry/instrumentation to work around a Bun
* --bytecode bug (https://github.com/getsentry/sentry-javascript/issues/21256).
* - The upstream class imports `normalize` via an indirect platform/index
* re-export chain, which Bun's bytecode bundler renames and loses scope for.
* - This copy imports `normalize` directly from 'path' to break that chain.
*/
/* oxlint-disable */

import { normalize } from 'path';
import type { InstrumentationModuleFile } from '@opentelemetry/instrumentation';

export class InstrumentationNodeModuleFile implements InstrumentationModuleFile {
public name: string;
public supportedVersions: string[];
public patch: (moduleExports: any, moduleVersion?: string) => any;
public unpatch: (moduleExports?: any, moduleVersion?: string) => void;

constructor(
name: string,
supportedVersions: string[],
patch: (moduleExports: any, moduleVersion?: string) => any,
unpatch: (moduleExports?: any, moduleVersion?: string) => void,
) {
this.name = normalize(name);
this.supportedVersions = supportedVersions;
this.patch = patch;
this.unpatch = unpatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import { timestampInSeconds } from '@sentry/core';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
safeExecuteInTheMiddle,
SemconvStability,
semconvStabilityFromStr,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import { ATTR_MESSAGING_OPERATION } from './semconv';
import {
ATTR_MESSAGING_DESTINATION,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as net from 'node:net';
import type { Span, Tracer } from '@opentelemetry/api';
import { context, diag, SpanKind, trace } from '@opentelemetry/api';
import {
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleDefinition, isWrapped, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';
import {
ATTR_DB_COLLECTION_NAME,
ATTR_DB_NAMESPACE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import type { Span, Tracer } from '@opentelemetry/api';
import { context, diag, SpanKind, trace } from '@opentelemetry/api';
import type { InstrumentationBase } from '@opentelemetry/instrumentation';
import {
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleDefinition, isWrapped, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';
import type { SpanAttributes } from '@sentry/core';
import type { FirebaseInstrumentation } from '../firebaseInstrumentation';
import type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../InstrumentationNodeModuleFile';
import type { GoogleGenAIClient, GoogleGenAIOptions } from '@sentry/core';
import {
_INTERNAL_shouldSkipAiProviderWrapping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
isWrapped,
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import type {
DefinitionNode,
DocumentNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import * as constants from './constants';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
SemconvStability,
semconvStabilityFromStr,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import * as utils from './utils';
import { KnexInstrumentationConfig } from './types';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
type InstrumentationConfig,
type InstrumentationModuleDefinition,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../InstrumentationNodeModuleFile';
import type { LangChainOptions } from '@sentry/core';
import {
_INTERNAL_mergeLangChainCallbackHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
type InstrumentationConfig,
type InstrumentationModuleDefinition,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../InstrumentationNodeModuleFile';
import type { CompiledGraph, LangGraphOptions } from '@sentry/core';
import { getClient, instrumentCreateReactAgent, instrumentLangGraph, SDK_VERSION } from '@sentry/core';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { context, trace, Span, SpanKind, SpanStatusCode, UpDownCounter, type Att
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
safeExecuteInTheMiddle,
SemconvStability,
semconvStabilityFromStr,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import {
ATTR_DB_COLLECTION_NAME,
ATTR_DB_NAMESPACE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { SDK_VERSION } from '@sentry/core';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
safeExecuteInTheMiddle,
SemconvStability,
semconvStabilityFromStr,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import { DB_SYSTEM_VALUE_MYSQL, ATTR_DB_STATEMENT, ATTR_DB_SYSTEM } from './semconv';
import { addSqlCommenterComment } from '../../utils/sql-common';
import type { Connection, Query, QueryOptions, QueryError, FieldPacket, FormatFunction } from './mysql2-types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
safeExecuteInTheMiddle,
InstrumentationNodeModuleFile,
SemconvStability,
semconvStabilityFromStr,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import {
context,
trace,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/tracing/postgresjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from './InstrumentationNodeModuleFile';
import {
ATTR_DB_OPERATION_NAME,
ATTR_DB_QUERY_TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
safeExecuteInTheMiddle,
SemconvStability,
semconvStabilityFromStr,
} from '@opentelemetry/instrumentation';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import {
ATTR_DB_OPERATION_NAME,
ATTR_DB_QUERY_TEXT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as fs from 'fs';
import * as path from 'path';
import { describe, expect, it } from 'vitest';

const TRACING_DIR = path.resolve(__dirname, '../../../src/integrations/tracing');

/**
* Importing InstrumentationNodeModuleFile from @opentelemetry/instrumentation causes
* Bun's --bytecode compiler to inline a re-export chain that loses scope bindings.
* All instrumentations must use the local vendored copy instead.
*/
describe('InstrumentationNodeModuleFile import guard', () => {
it('no file should import InstrumentationNodeModuleFile from @opentelemetry/instrumentation', () => {
const offendingFiles: string[] = [];
Comment thread
sentry[bot] marked this conversation as resolved.

function walkDir(dir: string): void {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
walkDir(fullPath);
} else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.test.ts')) {
const content = fs.readFileSync(fullPath, 'utf-8');
// Match multi-line imports: look for an import block from @opentelemetry/instrumentation
// that includes InstrumentationNodeModuleFile as a named import
const importBlockRegex =
/import\s*\{[^}]*InstrumentationNodeModuleFile[^}]*\}\s*from\s*['"]@opentelemetry\/instrumentation['"]/s;
if (importBlockRegex.test(content)) {
offendingFiles.push(path.relative(TRACING_DIR, fullPath));
}
}
}
}

walkDir(TRACING_DIR);

expect(offendingFiles).toEqual([]);
});
});
Loading