Repository navigation
feat(api): replace Sentry with optional OpenTelemetry OTLP export - #4555
Conversation
Remove @sentry/node entirely (error capture, express handler, tracing wrapper) and rebuild lib/otel-tracer on the OpenTelemetry SDK: - Tracing is off unless OTEL_EXPORTER_OTLP_ENDPOINT (or the traces endpoint) is set; spans then go to the collector over http/protobuf with 100% sampling (parent-based for continued traces). - Zero-data-retention spans never leave the process: a sampler makes every span started under a ZDR context non-recording, and a span processor drops anything ending with a *.zero_data_retention=true attribute. Root spans (v2 scrape/parse/upload requests, scrape pipeline, worker job and its queue bookkeeping, NuQ enqueues, crawl/GCS persistence) pass the flag. - Queue trace propagation uses W3C traceparent/tracestate/baggage; legacy Sentry-shaped contexts on in-flight jobs start a fresh trace. - AI SDK telemetry keeps recordInputs/recordOutputs off, previously enforced by the Sentry integration. - Workers flush pending spans on graceful shutdown. - The SENTRY_ENVIRONMENT=dev local override (colored logs, uncached DNS under ENV=production) goes away with the variable. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
1 issue found across 78 files
Confidence score: 3/5
- In
apps/api/src/lib/gcs-jobs.ts, keyless job saves can send the client IP embedded inparams.team_idto the OTLP collector, creating a concrete privacy exposure in telemetry; apply the keyless-team pseudonymizer to this attribute while retaining the raw team ID.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/lib/gcs-jobs.ts">
<violation number="1" location="apps/api/src/lib/gcs-jobs.ts:100">
P1: When a keyless request saves a job, this span exports the client IP embedded in `params.team_id` to the OTLP collector. Apply the keyless-team pseudonymizer to this telemetry attribute while retaining the raw team ID for GCS metadata and storage logic.</violation>
</file>
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
Follow-ups from review: - The scrape worker applies the zero-data-retention context whether or not a trace context arrived with the job, so nothing between the worker entry and the pipeline records for ZDR jobs. - ZDR / anonymous searches flag the context before the controller body runs. - The parse upload root span and the crawl lookup span carry the ZDR flag. - scrape.pipeline records handled unexpected failures as ERROR spans instead of ending OK. - Every entry point flushes buffered spans on graceful shutdown. - OTLP endpoints are validated as URLs and empty OTEL_* values count as unset. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
1 issue found across 15 files (changes from recent commits).
Confidence score: 3/5
apps/api/src/lib/otel-tracer.tsrecords request-derived error messages and stack traces in OTLP-exported spans, which could expose sensitive request data to telemetry systems; sanitize or omit these fields before callingrecordException.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/lib/otel-tracer.ts">
<violation number="1" location="apps/api/src/lib/otel-tracer.ts:281">
P1: Sanitize or omit request-derived error messages and stack traces before calling `recordException`; this span event is exported with OTLP and may contain sensitive request data.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…d feedback - Flagging a live span with a *.zero_data_retention attribute now marks its trace: descendants started afterwards are not recorded and spans of that trace still in flight are dropped when they end (bounded registry), so the attribute path no longer depends on children starting after the end-time filter. Covered by tests. - v1 scrape requests and endpoint feedback recording run inside a span, and their handled failures are recorded as ERROR spans with the error id, so error visibility that used to come from Sentry capture has an OTel path. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Confidence score: 2/5
apps/api/src/lib/otel-tracer.tscan FIFO-evict an older trace ID while work is still running once more than 10,000 ZDR traces are marked, allowing later child or library spans to be recorded and exported incorrectly; fix the lifecycle-aware eviction handling before merging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/lib/otel-tracer.ts">
<violation number="1" location="apps/api/src/lib/otel-tracer.ts:75">
P1: When more than 10,000 ZDR traces are marked while an older trace still has work running, this FIFO evicts the older trace ID. A later child or library span from that trace can then be recorded and exported; use lifecycle-aware retention or propagate ZDR context instead of evicting active traces.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
… feedback ZDR - The ZDR trace registry only takes entries from recording spans (a non-recording span already suppresses its descendants through parent-based sampling), so it only sees the rare late-discovery case; cap raised to 100k as a pure memory guard. - Feedback recording derives its ZDR flag from the endpoint the feedback refers to (search forced-zdr/forced-anon or scrape/parse forced), and flags the span when the job itself turns out to be ZDR so it is dropped. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
Map feedback is not a ZDR endpoint, so its span stays recorded even for teams forced into scrape ZDR, matching shouldSkipPersistenceForForcedZdr. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
Re-trigger cubic
The variable is a deployment-environment marker with its own consumers (colorized logs and uncached DNS when set to "dev"); it stays exactly as it was. Only SENTRY_DSN and SENTRY_TRACE_SAMPLE_RATE go with Sentry. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Drop the recordInputs/recordOutputs=false carried over from the Sentry integration; AI SDK telemetry keeps its defaults. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 12 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
…-drop-sentry # Conflicts: # apps/api/src/controllers/v2/parse-upload.ts # apps/api/src/lib/crawl-redis.ts # apps/api/src/services/logging/log_job.test.ts # apps/api/src/services/logging/log_job.ts
Those two calls feed the model the page screenshot and raw page chunks; recording them as span attributes would bloat OTLP batches. Outputs stay recorded; every other AI call keeps the SDK defaults. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@cubic-dev-ai review All previous threads are addressed or resolved; please re-review the whole PR at the current head. |
@mogery I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 70 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Search requests now get an api.search.request SERVER span (inside the ZDR context for zdr/anon searches), matching scrape and parse. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Upstream removed Sentry entirely in favor of OpenTelemetry (firecrawl#4555), which is why this hunk conflicted even though upstream never touched this function: the base state on both sides had no Sentry usage. Resolving in favor of this branch's closedDuringAuth/isSocketOpen guard would have kept an unimported `Sentry.captureException(err)` call — a leftover from before this repo dropped the Sentry dependency, and something that would throw ReferenceError on the exact disconnect-during-auth path this PR hardens. Dropped it; the existing logger.error() call below already reports the full error. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Summary
Removes Sentry from the API entirely and replaces the span wrapper with a real OpenTelemetry setup that optionally exports to an OTLP collector.
@sentry/node,@sentry/core,@sentry/cli,Sentry.init, the Express error handler, everycaptureExceptionsite,services/sentry.ts, and theSENTRY_DSN/SENTRY_TRACE_SAMPLE_RATE/SENTRY_ERROR_SAMPLE_RATEconfig. Error paths keep their existinglogger.errorcalls, and the paths that only had Sentry capture (v1 scrape, endpoint feedback, the scrape pipeline's handled failures) now record the error on a span instead.SENTRY_ENVIRONMENTis untouched: it is an environment marker with its own consumers (colorized logs and uncached DNS underdev), unrelated to the Sentry SDK.lib/otel-tracer.tsnow sits on@opentelemetry/sdk-trace-node.withSpan/setSpanAttributes/SpanKindkeep their signatures; spans are always ended, errors are recorded as span events withERRORstatus.src/otel.tsis imported first by every entry point and registers a provider only whenOTEL_EXPORTER_OTLP_ENDPOINT(orOTEL_EXPORTER_OTLP_TRACES_ENDPOINT) is set. Export is http/protobuf via@opentelemetry/exporter-trace-otlp-proto, which honors the standardOTEL_EXPORTER_OTLP_*variables;OTEL_SERVICE_NAME/OTEL_RESOURCE_ATTRIBUTESset the resource. Without an endpoint,withSpanis a no-op wrapper. Every entry point flushes pending spans on graceful shutdown.ParentBased(AlwaysOn), so everything is exported and continued traces keep the parent's decision.withSpan(..., { zeroDataRetention })/withZeroDataRetention()flag the OTel context; a sampler makes every span started under it non-recording, including library spans (AI SDK).zero_data_retention/*.zero_data_retentionattribute equal totrue. Setting that attribute on a live recording span also flags its trace, so descendants started afterwards are not recorded and in-flight spans of the trace are dropped.The flag is passed at every root where ZDR is known: v1 and v2 scrape, v2 parse and parse-upload requests (resolved before the root span from the team flags and raw body), v2 search (ZDR / anon), endpoint feedback (per endpoint),
scrape.pipeline,worker.scrape.processand the queue bookkeeping that follows it, NuQ enqueues, crawl Redis persistence, GCS job persistence.traceparent/tracestate/baggageonjob.data.traceContext. Legacy Sentry-shaped contexts on in-flight jobs are ignored (fresh trace), so the deploy is safe.experimental_telemetryblocks are unchanged, so model, usage, inputs and outputs are recorded on the AI spans (the Sentry integration used to force inputs/outputs off).Deploy notes
OTEL_EXPORTER_OTLP_ENDPOINTat a hostname that no longer resolves and set the Sentry DSN. The companion infra change repoints it at the ClickStack OTel collector gateway over http/protobuf and drops the Sentry DSN and sample rate; merge that first so the API never tries the dead endpoint.OTEL_SERVICE_NAMEshould be set per deployment (production already does:app,nuq-worker, ...); without it every process reports asfirecrawl-api.Test plan
pnpm exec tsc --noEmit,pnpm exec knip,audit-cicleansrc/lib/otel-tracer.test.ts: export of attributes/kind/status/resource, exception recording, nesting of library spans, ZDR context suppression (own and library spans), attribute-based drop, late-flagged trace suppression (descendants and in-flight spans), W3C round trip with inherited sampling, ZDR parent stays unrecorded, legacy/missing contexts, empty context outside a spanlog_job,batch_billing,llm-failure-fallback,search-developer-ledger,services/index)🤖 Generated with Claude Code