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
6 changes: 0 additions & 6 deletions dev-packages/bun-integration-tests/node-suites/excludes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ const NOT_TRIAGED = [
'suites/tracing/tracer-start-active-span-error/test.ts',
];

// Bun garbage-collects a diagnostics channel that no code references, and its subscribers with it.
// `graphql` 17 publishes its own tracing channels, so the integration only subscribes to them, and
// no spans arrive. See https://github.com/oven-sh/bun/issues/43086
const CHANNEL_GARBAGE_COLLECTED = ['suites/tracing/graphql-tracing-channel/**'];

// The scenario configures `nativeNodeFetchIntegration`, which `@sentry/bun` does not export.
const NO_NATIVE_NODE_FETCH_INTEGRATION = [
'suites/tracing/http-client-spans/fetch-forward-request-hook/test.ts',
Expand Down Expand Up @@ -209,7 +204,6 @@ export const NODE_SUITES_EXCLUDE = [
...NO_OUTGOING_HTTP_INSTRUMENTATION,
...NO_AUTO_INSTRUMENTATION,
...NOT_TRIAGED,
...CHANNEL_GARBAGE_COLLECTED,
];

// Excluded only in the `node-suites` project, which runs the suites with `@sentry/node`.
Expand Down
19 changes: 18 additions & 1 deletion packages/bun/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@
{
"files": ["**/src/**"],
"rules": {
"sdk/no-class-field-initializers": "off"
"sdk/no-class-field-initializers": "off",
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "node:diagnostics_channel",
"allowTypeImports": true,
"message": "Bun garbage-collects a channel that no code references, together with its subscribers. Use `subscribeDiagnosticsChannel` or `diagnosticsTracingChannel` from `@sentry/server-utils` instead. See https://github.com/oven-sh/bun/issues/43086"
},
{
"name": "diagnostics_channel",
"allowTypeImports": true,
"message": "Bun garbage-collects a channel that no code references, together with its subscribers. Use `subscribeDiagnosticsChannel` or `diagnosticsTracingChannel` from `@sentry/server-utils` instead. See https://github.com/oven-sh/bun/issues/43086"
}
]
}
]
}
}
]
Expand Down
26 changes: 26 additions & 0 deletions packages/bun/test/integrations/diagnosticsChannelGc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { channel } from 'node:diagnostics_channel';
import { describe, expect, test } from 'bun:test';
import { init } from '../../src';

const EXPRESS_HANDLE_START = 'tracing:orchestrion:express:handle:start';

function nextTask(): Promise<void> {
return new Promise(resolve => setTimeout(resolve, 0));
}

describe('channel-based integrations', () => {
// Bun garbage-collects a diagnostics channel that no code references, together with its
// subscribers. A GC in the same task does not collect it, so the check runs in a later task.
// See https://github.com/oven-sh/bun/issues/43086
test('stay subscribed after a garbage collection', async () => {
init({ dsn: 'https://username@domain/123', tracesSampleRate: 1 });
await nextTask();

expect(channel(EXPRESS_HANDLE_START).hasSubscribers).toBe(true);

Bun.gc(true);
await nextTask();

expect(channel(EXPRESS_HANDLE_START).hasSubscribers).toBe(true);
});
});
19 changes: 18 additions & 1 deletion packages/node/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,24 @@
{
"files": ["**/src/**"],
"rules": {
"sdk/no-class-field-initializers": "off"
"sdk/no-class-field-initializers": "off",
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "node:diagnostics_channel",
"allowTypeImports": true,
"message": "Bun garbage-collects a channel that no code references, together with its subscribers. Use `subscribeDiagnosticsChannel` or `diagnosticsTracingChannel` from `@sentry/server-utils` instead. See https://github.com/oven-sh/bun/issues/43086"
},
{
"name": "diagnostics_channel",
"allowTypeImports": true,
"message": "Bun garbage-collects a channel that no code references, together with its subscribers. Use `subscribeDiagnosticsChannel` or `diagnosticsTracingChannel` from `@sentry/server-utils` instead. See https://github.com/oven-sh/bun/issues/43086"
}
]
}
]
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/childProcess.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ChildProcess } from 'node:child_process';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import { addBreadcrumb, defineIntegration, isObjectLike } from '@sentry/core';
import { subscribeDiagnosticsChannel } from '@sentry/server-utils';

interface Options {
/**
Expand All @@ -21,7 +21,7 @@ export const childProcessIntegration = defineIntegration((options: Options = {})
return {
name: INTEGRATION_NAME,
setup() {
diagnosticsChannel.channel('child_process').subscribe((event: unknown) => {
subscribeDiagnosticsChannel('child_process', (event: unknown) => {
if (isObjectLike(event) && 'process' in event) {
captureChildProcessEvents(event.process as ChildProcess, options);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { subscribe } from 'node:diagnostics_channel';
import { context, trace } from '@opentelemetry/api';
import type { ClientRequest, IncomingMessage } from 'node:http';
import type { Span } from '@sentry/core';
Expand All @@ -10,6 +9,7 @@ import {
HTTP_ON_CLIENT_REQUEST,
patchHttpModuleClient,
} from '@sentry/core/server';
import { subscribeDiagnosticsChannel } from '@sentry/server-utils';
import { NODE_VERSION } from '../../nodeVersion';
import { errorMonitor } from 'node:events';
import * as http from 'node:http';
Expand Down Expand Up @@ -125,7 +125,7 @@ export function instrumentHttpOutgoingRequests(

function instrumentHttpOutgoingRequestsViaChannel(options: HttpInstrumentationOptions): void {
const { [HTTP_ON_CLIENT_REQUEST]: onHttpClientRequestCreated } = getHttpClientSubscriptions(options);
subscribe(HTTP_ON_CLIENT_REQUEST, onHttpClientRequestCreated);
subscribeDiagnosticsChannel(HTTP_ON_CLIENT_REQUEST, onHttpClientRequestCreated);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { subscribe } from 'node:diagnostics_channel';
import type { RequestOptions } from 'node:http';
import { context, createContextKey, propagation } from '@opentelemetry/api';
import type { Integration, IntegrationFn } from '@sentry/core';
import { addNonEnumerableProperty, debug, getClient } from '@sentry/core';
import type { HttpIncomingMessage, HttpServerResponse } from '@sentry/core/server';
import { getHttpServerSubscriptions, HTTP_ON_SERVER_REQUEST, recordRequestSession } from '@sentry/core/server';
import { subscribeDiagnosticsChannel } from '@sentry/server-utils';
import type { RequestEventData } from '@sentry/core';
import { DEBUG_BUILD } from '../../debug-build';

Expand Down Expand Up @@ -143,7 +143,7 @@ const _httpServerIntegration = ((options: HttpServerIntegrationOptions = {}) =>
name: INTEGRATION_NAME,
setupOnce() {
const { [HTTP_ON_SERVER_REQUEST]: onHttpServerRequestStart } = getHttpServerSubscriptions(_options);
subscribe(HTTP_ON_SERVER_REQUEST, onHttpServerRequestStart);
subscribeDiagnosticsChannel(HTTP_ON_SERVER_REQUEST, onHttpServerRequestStart);
},
afterAllSetup(client) {
if (DEBUG_BUILD && client.getIntegrationByName('Http')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

/* eslint-disable max-lines */

import * as diagch from 'diagnostics_channel';
import { URL } from 'url';

import type { Span, SpanAttributes } from '@sentry/core';
Expand All @@ -42,6 +41,7 @@ import {
filterCollectedUrlQuery,
httpHeadersToSpanAttributes,
} from '@sentry/core';
import { subscribeDiagnosticsChannel } from '@sentry/server-utils';
import { addFetchRequestBreadcrumb, addTracePropagationHeadersToFetchRequest } from '../../utils/outgoingFetchRequest';
import {
HTTP_REQUEST_METHOD,
Expand Down Expand Up @@ -118,7 +118,7 @@ function subscribeToChannel(
diagnosticChannel: string,
onMessage: (message: unknown, name: string | symbol) => void,
): void {
diagch.subscribe?.(diagnosticChannel, onMessage);
subscribeDiagnosticsChannel(diagnosticChannel, onMessage);
}

function parseRequestHeaders(request: UndiciRequest): Map<string, string | string[]> {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/pino.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import type { IntegrationFn, LogSeverityLevel } from '@sentry/core';
import {
_INTERNAL_captureLog,
Expand All @@ -10,6 +9,7 @@ import {
severityLevelFromString,
withScope,
} from '@sentry/core';
import { diagnosticsTracingChannel } from '@sentry/server-utils';

const SENTRY_TRACK_SYMBOL = Symbol('sentry-track-pino-logger');

Expand Down Expand Up @@ -125,7 +125,7 @@ const _pinoIntegration = defineIntegration((userOptions: DeepPartial<PinoOptions
return {
name: 'Pino',
setup: () => {
const integratedChannel = diagnosticsChannel.tracingChannel('pino_asJson');
const integratedChannel = diagnosticsTracingChannel('pino_asJson');

function onPinoStart(self: Pino, args: PinoHookArgs, result: PinoResult): void {
if (!shouldTrackLogger(self)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/workerThreads.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Worker } from 'node:worker_threads';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import { captureException, defineIntegration, isObjectLike } from '@sentry/core';
import { subscribeDiagnosticsChannel } from '@sentry/server-utils';

const INTEGRATION_NAME = 'WorkerThreads' as const;

Expand All @@ -12,7 +12,7 @@ export const workerThreadsIntegration = defineIntegration(() => {
return {
name: INTEGRATION_NAME,
setup() {
diagnosticsChannel.channel('worker_threads').subscribe((event: unknown) => {
subscribeDiagnosticsChannel('worker_threads', (event: unknown) => {
if (isObjectLike(event) && 'worker' in event) {
captureWorkerThreadEvents(event.worker as Worker);
}
Expand Down
19 changes: 18 additions & 1 deletion packages/server-utils/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,24 @@
{
"files": ["**/src/**"],
"rules": {
"sdk/no-class-field-initializers": "off"
"sdk/no-class-field-initializers": "off",
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "node:diagnostics_channel",
"allowTypeImports": true,
"message": "Bun garbage-collects a channel that no code references, together with its subscribers. Import the wrappers from `src/utils/diagnosticsChannel.ts` instead. See https://github.com/oven-sh/bun/issues/43086"
},
{
"name": "diagnostics_channel",
"allowTypeImports": true,
"message": "Bun garbage-collects a channel that no code references, together with its subscribers. Import the wrappers from `src/utils/diagnosticsChannel.ts` instead. See https://github.com/oven-sh/bun/issues/43086"
}
]
}
]
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions packages/server-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export type { InstrumentationConfig } from './orchestrion/apmTypes';
// `orchestrion/bundler/moduleInjectedTransform.ts`); it is a plain runtime
// helper with no orchestrion build-time dependency.
export { orchestrionModuleInjected } from './utils/moduleInjected';
export {
subscribe as subscribeDiagnosticsChannel,
tracingChannel as diagnosticsTracingChannel,
} from './utils/diagnosticsChannel';
export { eveConversationHook, eveIntegration } from './eve';
export { getInstrumentedModuleNames } from './orchestrion/config';
export {
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/amqplib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines */
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn, Span, SpanAttributes } from '@sentry/core';
import {
continueTrace,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/anthropic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GEN_AI_REQUEST_MODEL } from '@sentry/conventions/attributes';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn, Span, SpanAttributeValue } from '@sentry/core';
import {
_INTERNAL_shouldSkipAiProviderWrapping,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/aws-sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { IntegrationFn, Span } from '@sentry/core';
import { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startInactiveSpan } from '@sentry/core';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/dataloader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import {
CACHE_KEY,
CACHE_OPERATION,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/express/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import { expressModuleNames } from '../../orchestrion/config/express';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/fastify/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyIntegration, FastifyReply, FastifyRequest } from './types';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import { addNonEnumerableProperty, captureException, getClient } from '@sentry/core';
import { defaultShouldHandleError, INTEGRATION_NAME } from './utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* eslint-disable @typescript-eslint/no-this-alias */
/* eslint-disable max-lines */

import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import {
HTTP_REQUEST_METHOD,
HTTP_RESPONSE_STATUS_CODE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import { CHANNELS } from '../../orchestrion/channels';
import { bindTracingChannelToSpan, safeChannelCallback } from '../../tracing-channel';
import type { FirestoreReference } from './firestore-types';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/generic-pool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import { SENTRY_OP } from '@sentry/conventions/attributes';
import { DB } from '@sentry/conventions/op';
import type { IntegrationFn } from '@sentry/core';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/google-genai.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GEN_AI_REQUEST_MODEL, SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn, Span } from '@sentry/core';
import {
_INTERNAL_shouldSkipAiProviderWrapping,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration, waitForTracingChannelBinding } from '@sentry/core';
import { subscribeGraphqlDiagnosticChannels, type GraphQLOptions } from './graphql-dc-subscriber';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/hapi/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import { CHANNELS } from '../../orchestrion/channels';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/kafkajs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { TracingChannelSubscribers } from 'node:diagnostics_channel';
import type { IntegrationFn, Span } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/knex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// emit them deliberately to preserve parity with what `@opentelemetry/instrumentation-knex` produced.
/* oxlint-disable typescript/no-deprecated */

import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn, Span, SpanAttributes } from '@sentry/core';
import {
debug,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/koa/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import {
addNonEnumerableProperty,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/langchain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn, Span } from '@sentry/core';
import { _INTERNAL_skipAiProviderWrapping, defineIntegration, startInactiveSpan } from '@sentry/core';
import { ANTHROPIC_AI_INTEGRATION_NAME } from '../ai/anthropic-ai/constants';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/langgraph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import { debug, defineIntegration } from '@sentry/core';
import { resolveAIRecordingOptions } from '../ai/core/utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/lru-memoizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import { CHANNELS } from '../orchestrion/channels';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/mastra.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import { createRequire } from 'node:module';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/mistral.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import type { IntegrationFn, Span, SpanAttributeValue } from '@sentry/core';
import {
_INTERNAL_shouldSkipAiProviderWrapping,
Expand Down
2 changes: 1 addition & 1 deletion packages/server-utils/src/integrations/mongodb/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import * as diagnosticsChannel from '../../utils/diagnosticsChannel';
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import type { MongodbNamespace, MongoV3Topology } from './mongodb-span';
Expand Down
Loading
Loading