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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ All options are passed to `init()` as an `ObservabilityConfig` object.
| `ignoredRoutes` | `string[]` | `[]` | Routes never sampled by Sentry (e.g. `['/health', '/metrics']`). Trailing slashes and query strings are handled automatically. |
| `ignoredBreadcrumbCategories` | `string[]` | `['http', 'fetch', 'xhr']` | Breadcrumb categories to apply URL-pattern filtering to. |
| `ignoredBreadcrumbPatterns` | `RegExp[]` | Pyroscope + PostHog patterns | URL patterns for breadcrumbs that should be dropped entirely. |
| `ignoredSpanOps` | `string[]` | `[]` | Span ops dropped before sending to Sentry (e.g. `['middleware.express', 'router.express']`). Children are re-parented; OTLP export is unaffected. |

## API

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.6/schema.json",
"$schema": "https://biomejs.dev/schemas/2.5.15/schema.json",
"files": {
"ignoreUnknown": true,
"includes": ["**", "!dist", "!node_modules", "!coverage"]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scope3/observability-js",
"version": "2.3.0",
"version": "2.4.0",
"description": "Unified observability (Sentry, OpenTelemetry, Pyroscope) for Node.js services",
"keywords": [
"observability",
Expand Down
23 changes: 23 additions & 0 deletions src/__tests__/otel-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,26 @@ describe('trace provider registration on the Sentry client', () => {
}
}, 2000)
})

describe('Sentry span filtering', () => {
it('passes ignoredSpanOps to Sentry as ignoreSpans', () => {
init({
serviceName: 'otel-setup-test',
environment: 'development',
enableOtel: true,
sentry: { dsn: SENTRY_DSN, enabled: false },
filters: { ignoredSpanOps: ['middleware.express', 'router.express'] },
})

expect(Sentry.getClient()?.getOptions().ignoreSpans).toEqual([
{ op: 'middleware.express' },
{ op: 'router.express' },
])
})

it('ignores no spans by default', () => {
initWithOtel()

expect(Sentry.getClient()?.getOptions().ignoreSpans).toEqual([])
})
})
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function resolveConfig(config: ObservabilityConfig): ResolvedConfig {
/posthog\.com/i,
/i\.posthog\.com/i,
],
ignoredSpanOps: config.filters?.ignoredSpanOps ?? [],
},

shouldDropError: config.shouldDropError,
Expand Down
1 change: 1 addition & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function initializeSentry(config: ResolvedConfig): void {
],
enabled: config.sentry.enabled,
tracesSampler: buildTracesSampler(config),
ignoreSpans: config.filters.ignoredSpanOps.map((op) => ({ op })),
beforeSend(event, hint) {
const error = hint?.originalException

Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export interface FilterConfig {
* Defaults to patterns matching Pyroscope and PostHog URLs.
*/
ignoredBreadcrumbPatterns?: RegExp[]
/**
* Sentry span ops dropped before spans are sent to Sentry. Children of a
* dropped span are re-parented, and OTLP export is unaffected.
* Example: `['middleware.express', 'router.express']`. Defaults to `[]`.
*/
ignoredSpanOps?: string[]
}

/** Top-level configuration passed to {@link init}. */
Expand Down Expand Up @@ -177,6 +183,7 @@ export interface ResolvedConfig {
ignoredRoutes: string[]
ignoredBreadcrumbCategories: string[]
ignoredBreadcrumbPatterns: RegExp[]
ignoredSpanOps: string[]
}

shouldDropError?: (error: unknown) => boolean
Expand Down
Loading