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
3 changes: 3 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ targets:
- name: npm
id: '@sentry/node-core'
includeNames: /^sentry-node-core-\d.*\.tgz$/
- name: npm
id: '@sentry-internal/server-utils'
includeNames: /^sentry-internal-server-utils-\d.*\.tgz$/
## 1.3 Browser Utils package
- name: npm
id: '@sentry-internal/browser-utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ test('ioredis GET emits an http.server transaction containing a db.redis child s
expect(redisSpan).toBeDefined();
// ioredis publishes lowercase command names; node-redis publishes uppercase.
expect(redisSpan!.description).toBe('redis-get');
expect(redisSpan!.data?.['db.system']).toBe('redis');
expect(redisSpan!.data?.['db.statement']).toBe('get iocache:user:42');
expect(redisSpan!.data?.['db.system.name']).toBe('redis');
expect(redisSpan!.data?.['db.query.text']).toBe('get iocache:user:42');
});

test('ioredis SET then GET emit two db.redis child spans on the same transaction', async ({ baseURL }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ test('GET command emits an http.server transaction containing a db.redis child s
const redisSpan = transaction.spans!.find(span => span.op === 'db.redis');
expect(redisSpan).toBeDefined();
expect(redisSpan!.description).toBe('redis-GET');
expect(redisSpan!.data?.['db.system']).toBe('redis');
expect(redisSpan!.data?.['db.system.name']).toBe('redis');
// Statement omits the value; for GET the only allowed arg is the key.
expect(redisSpan!.data?.['db.statement']).toBe('GET cache:user:42');
expect(redisSpan!.data?.['net.peer.port']).toBe(6379);
expect(redisSpan!.data?.['db.query.text']).toBe('GET cache:user:42');
expect(redisSpan!.data?.['server.port']).toBe(6379);
});

test('SET then GET emit two db.redis child spans on the same transaction', async ({ baseURL }) => {
Expand Down Expand Up @@ -65,7 +65,7 @@ test('MULTI batch emits a PIPELINE/MULTI batch span', async ({ baseURL }) => {
const batchSpan = transaction.spans!.find(span => span.description === 'MULTI' || span.description === 'PIPELINE');
expect(batchSpan).toBeDefined();
expect(batchSpan!.op).toBe('db.redis');
expect(batchSpan!.data?.['db.system']).toBe('redis');
expect(batchSpan!.data?.['db.system.name']).toBe('redis');
});

test('shut down redis client', async ({ baseURL }) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"packages/replay-internal",
"packages/replay-canvas",
"packages/replay-worker",
"packages/server-utils",
"packages/solid",
"packages/solidstart",
"packages/svelte",
Expand Down
20 changes: 0 additions & 20 deletions packages/core/src/server-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ export type {
} from './integrations/express/types';
export { instrumentPostgresJsSql } from './integrations/postgresjs';

export {
IOREDIS_DC_CHANNEL_COMMAND,
IOREDIS_DC_CHANNEL_CONNECT,
REDIS_DC_CHANNEL_BATCH,
REDIS_DC_CHANNEL_COMMAND,
REDIS_DC_CHANNEL_CONNECT,
subscribeRedisDiagnosticChannels,
} from './integrations/redis/redis-dc-subscriber';
export type {
IORedisCommandData,
RedisBatchData,
RedisCommandData,
RedisConnectData,
RedisDiagnosticChannelResponseHook,
RedisTracingChannel,
RedisTracingChannelContextWithSpan,
RedisTracingChannelFactory,
RedisTracingChannelSubscribers,
} from './integrations/redis/redis-dc-subscriber';

export { patchHttpModuleClient } from './integrations/http/client-patch';
export { getHttpClientSubscriptions } from './integrations/http/client-subscriptions';
export { getHttpServerSubscriptions, isStaticAssetRequest } from './integrations/http/server-subscription';
Expand Down
1 change: 1 addition & 0 deletions packages/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"dependencies": {
"@opentelemetry/api": "^1.9.1",
"@sentry-internal/server-utils": "10.55.0",
"@sentry/core": "10.55.0"
},
"scripts": {
Expand Down
9 changes: 4 additions & 5 deletions packages/deno/src/integrations/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
// On older runtimes the integration becomes a no-op.
import * as dc from 'node:diagnostics_channel';
import type {
Integration,
IntegrationFn,
RedisDiagnosticChannelResponseHook,
RedisTracingChannel,
RedisTracingChannelFactory,
RedisTracingChannelSubscribers,
Span,
} from '@sentry/core';
import { defineIntegration, subscribeRedisDiagnosticChannels } from '@sentry/core';
} from '@sentry-internal/server-utils';
import { subscribeRedisDiagnosticChannels } from '@sentry-internal/server-utils';
import type { Integration, IntegrationFn, Span } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import { setAsyncLocalStorageAsyncContextStrategy } from '../async';

const INTEGRATION_NAME = 'DenoRedis';
Expand Down
16 changes: 8 additions & 8 deletions packages/deno/test/deno-redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ Deno.test('denoRedisIntegration: node-redis:command channel produces a db.redis
const redisSpan = parent.spans?.find(s => s.op === 'db.redis');
assertExists(redisSpan, `expected a db.redis child span, got ops: ${parent.spans?.map(s => s.op).join(', ')}`);
assertEquals(redisSpan!.description, 'redis-GET');
assertEquals(redisSpan!.data?.['db.system'], 'redis');
assertEquals(redisSpan!.data?.['db.statement'], 'GET cache:key');
assertEquals(redisSpan!.data?.['net.peer.name'], '127.0.0.1');
assertEquals(redisSpan!.data?.['net.peer.port'], 6379);
assertEquals(redisSpan!.data?.['db.system.name'], 'redis');
assertEquals(redisSpan!.data?.['db.query.text'], 'GET cache:key');
assertEquals(redisSpan!.data?.['server.address'], '127.0.0.1');
assertEquals(redisSpan!.data?.['server.port'], 6379);
});

Deno.test('denoRedisIntegration: errors on the command channel set span status', async () => {
Expand Down Expand Up @@ -165,8 +165,8 @@ Deno.test('denoRedisIntegration: ioredis:command channel produces a db.redis chi
const redisSpan = parent.spans?.find(s => s.op === 'db.redis');
assertExists(redisSpan, `expected a db.redis child span, got ops: ${parent.spans?.map(s => s.op).join(', ')}`);
assertEquals(redisSpan!.description, 'redis-get');
assertEquals(redisSpan!.data?.['db.system'], 'redis');
assertEquals(redisSpan!.data?.['db.statement'], 'get cache:key');
assertEquals(redisSpan!.data?.['net.peer.name'], '127.0.0.1');
assertEquals(redisSpan!.data?.['net.peer.port'], 6379);
assertEquals(redisSpan!.data?.['db.system.name'], 'redis');
assertEquals(redisSpan!.data?.['db.query.text'], 'get cache:key');
assertEquals(redisSpan!.data?.['server.address'], '127.0.0.1');
assertEquals(redisSpan!.data?.['server.port'], 6379);
});
1 change: 1 addition & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@opentelemetry/instrumentation": "^0.214.0",
"@opentelemetry/sdk-trace-base": "^2.6.1",
"@opentelemetry/semantic-conventions": "^1.40.0",
"@sentry-internal/server-utils": "10.55.0",
"@sentry/core": "10.55.0",
"@sentry/node-core": "10.55.0",
"@sentry/opentelemetry": "10.55.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/tracing/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
spanToJSON,
truncate,
} from '@sentry/core';
import { subscribeRedisDiagnosticChannels } from '@sentry/core/server';
import { subscribeRedisDiagnosticChannels } from '@sentry-internal/server-utils';
import { generateInstrumentOnce } from '@sentry/node-core';
import { tracingChannel as otelTracingChannel } from '@sentry/opentelemetry/tracing-channel';
import type { IORedisCommandArgs } from '../../../utils/redisCache';
Expand Down
30 changes: 30 additions & 0 deletions packages/server-utils/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "../../node_modules/oxlint/configuration_schema.json",
"extends": ["../../.oxlintrc.base.json"],
"jsPlugins": [
{
"name": "sdk",
"specifier": "@sentry-internal/eslint-plugin-sdk"
}
],
"env": {
"node": true
},
"rules": {
"sdk/no-unsafe-random-apis": "error"
},
"overrides": [
{
"files": ["**/src/**"],
"rules": {
"sdk/no-class-field-initializers": "off"
}
},
{
"files": ["test/**/*.ts", "test/**/*.tsx"],
"rules": {
"sdk/no-unsafe-random-apis": "off"
}
}
]
}
23 changes: 23 additions & 0 deletions packages/server-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Sentry JavaScript SDK Server Utilities

[![npm version](https://img.shields.io/npm/v/@sentry-internal/server-utils.svg)](https://www.npmjs.com/package/@sentry-internal/server-utils)
[![npm dm](https://img.shields.io/npm/dm/@sentry-internal/server-utils.svg)](https://www.npmjs.com/package/@sentry-internal/server-utils)
[![npm dt](https://img.shields.io/npm/dt/@sentry-internal/server-utils.svg)](https://www.npmjs.com/package/@sentry-internal/server-utils)

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)

## General

Common server-only utilities used by the Sentry JavaScript server SDKs (node, node-core, bun, deno, cloudflare,
aws-serverless, google-cloud-serverless, vercel-edge).

Note: This package is only meant to be used internally, and as such is not part of our public API contract and does not
follow semver.
68 changes: 68 additions & 0 deletions packages/server-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "@sentry-internal/server-utils",
"version": "10.55.0",
"description": "Server Utilities for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/server-utils",
"author": "Sentry",
"license": "MIT",
"engines": {
"node": ">=18"
},
"files": [
"/build"
],
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./build/types/index.d.ts",
"default": "./build/esm/index.js"
},
"require": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
}
}
},
"typesVersions": {
"<5.0": {
"build/types/index.d.ts": [
"build/types-ts3.8/index.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sentry/core": "10.55.0"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:types": "run-s build:types:core build:types:downlevel",
"build:types:core": "tsc -p tsconfig.types.json",
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
"build:watch": "run-p build:transpile:watch",
"build:dev:watch": "run-p build:transpile:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
"build:tarball": "npm pack",
"clean": "rimraf build coverage sentry-internal-server-utils-*.tgz",
"lint:fix": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --fix --type-aware",
"lint": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --type-aware",
"lint:es-compatibility": "es-check es2020 ./build/cjs/*.js && es-check es2020 ./build/esm/*.js --module",
"test:unit": "vitest run",
"test": "vitest run",
"test:watch": "vitest --watch",
"yalc:publish": "yalc publish --push --sig"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
}
17 changes: 17 additions & 0 deletions packages/server-utils/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to true because we don't want to bundle everything into one file.
preserveModules:
process.env.SENTRY_BUILD_PRESERVE_MODULES === undefined
? true
: Boolean(process.env.SENTRY_BUILD_PRESERVE_MODULES),
},
},
}),
);
8 changes: 8 additions & 0 deletions packages/server-utils/src/debug-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const __DEBUG_BUILD__: boolean;

/**
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
*
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
*/
export const DEBUG_BUILD = __DEBUG_BUILD__;
25 changes: 25 additions & 0 deletions packages/server-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Server-only utilities shared across Sentry server SDKs.
*
* @module
*/

export {
IOREDIS_DC_CHANNEL_COMMAND,
IOREDIS_DC_CHANNEL_CONNECT,
REDIS_DC_CHANNEL_BATCH,
REDIS_DC_CHANNEL_COMMAND,
REDIS_DC_CHANNEL_CONNECT,
subscribeRedisDiagnosticChannels,
} from './redis/redis-dc-subscriber';
export type {
IORedisCommandData,
RedisBatchData,
RedisCommandData,
RedisConnectData,
RedisDiagnosticChannelResponseHook,
RedisTracingChannel,
RedisTracingChannelContextWithSpan,
RedisTracingChannelFactory,
RedisTracingChannelSubscribers,
} from './redis/redis-dc-subscriber';
Loading
Loading