Skip to content

Commit b122b71

Browse files
committed
Merge branch 'master' into ivana/python/migration-guide-rename-param
2 parents e02c281 + 9a2f1a6 commit b122b71

File tree

116 files changed

+2647
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2647
-517
lines changed

develop-docs/integrations/index.mdx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,70 @@ description: How to setup Sentry integrations. Integrations connect the Sentry s
44
sidebar_order: 80
55
---
66

7-
<PageGrid />
7+
<PageGrid/>
8+
9+
10+
11+
## Integration Backup and Restore Scripts
12+
13+
### Overview
14+
15+
When working on integration development locally, your database contains important configuration that makes integrations work properly. If you run `make reset-db` or need to delete your local environment, you lose all this setup and have to configure integrations from scratch.
16+
There are two scripts that help you backup and restore your local Sentry integration configuration and setup data.
17+
18+
These scripts allow you to:
19+
- **Backup**: Save your current integration state to a JSON file
20+
- **Restore**: Load the integration state back into a clean database
21+
22+
### What Data is Backed Up
23+
24+
The scripts handle the following Sentry models in the correct dependency order:
25+
- `IdentityProvider` - Authentication provider configurations
26+
- `Integration` - Integration instances and settings
27+
- `Identity` - User identity mappings
28+
- `OrganizationIntegration` - Organization-specific integration configurations
29+
30+
### Prerequisites
31+
32+
- Sentry development environment set up locally
33+
- Python environment with Sentry dependencies installed
34+
- Access to your local Sentry database
35+
36+
### Script Files
37+
38+
There are two scripts (exist in `sentry` and `getsentry`):
39+
40+
- `save_integration_data` - Backs up integration data
41+
- `load_integration_data` - Restores integration data
42+
43+
### Usage Instructions
44+
45+
#### Step 1: Save Your Integration Data
46+
47+
Before running `make reset-db` or making any destructive changes, backup your current integration state:
48+
49+
```bash
50+
# Navigate to your Sentry project directory
51+
cd /path/to/sentry # or /path/to/getsentry
52+
53+
# Run the save script
54+
bin/save_integration_data --output-file integration_backup.json
55+
```
56+
57+
#### Step 2: Restore Your Integration Data
58+
59+
After your database is reset and ready, restore your integration configuration:
60+
61+
```bash
62+
# Basic restore (preserves original organization IDs)
63+
bin/load_integration_data --input-file integration_backup.json
64+
```
65+
66+
**Or, if you need to change the organization ID:**
67+
68+
```bash
69+
# Restore and update organization ID for OrganizationIntegration objects
70+
bin/load_integration_data --input-file integration_backup.json --org-id 123
71+
```
72+
73+
After restoring, all the previous integration data will be restored and you can start using the integration for local development again.

develop-docs/sdk/data-model/envelope-items.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ _None_
400400

401401
Item type `"log"` contains an array of log payloads encoded as JSON. This allows for multiple log payloads to be sent in a single envelope item.
402402

403-
Only a single log item is allowed per envelope. The `item_count` field in the envelope item header must match the amount of logs sent, it's not optional. A `content_type` field in the envelope item header must be set to `application/vnd.sentry.items.log+json`.
403+
Only a single log container is allowed per envelope. The `item_count` field in the envelope item header must match the amount of logs sent, it's not optional. A `content_type` field in the envelope item header must be set to `application/vnd.sentry.items.log+json`.
404404

405405
It's okay to mix logs from different traces into the same log envelope item, but if you do, you MUST not attach a DSC (dynamic sampling context) to the envelope header.
406406

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: MCP Server Errors
3+
sidebar_title: Errors
4+
---
5+
6+
MCP Server error instrumentation ensures that all errors occurring within the Model Context Protocol (MCP) server are captured and reported to Sentry, **without ever interfering with the operation of the MCP service itself**.
7+
8+
## Goals and Philosophy
9+
10+
- **Comprehensive context:** Errors are always associated with the active Sentry span, so you get full context (method, tool, arguments, etc.) in Sentry.
11+
- **Categorized errors:** Errors are tagged by type (e.g., `validation`, `timeout`, `tool_execution`, `resource_operation`, `prompt_execution`, `transport`, etc.) for easy filtering and analysis in Sentry.
12+
- **Handler wrapping:** All MCP server handlers (`tool`, `resource`, `prompt`) are wrapped to ensure errors are captured and correlated with the correct request span.
13+
- **Span status tracking:** When errors occur, the active span status is automatically set to error for better trace correlation.
14+
15+
## Safe Error Capture
16+
17+
The core utility is an error capture function:
18+
19+
```ts
20+
import { getClient } from '../../currentScopes';
21+
import { captureException } from '../../exports';
22+
import { SPAN_STATUS_ERROR } from '../../tracing';
23+
import { getActiveSpan } from '../../utils/spanUtils';
24+
import type { McpErrorType } from './types';
25+
26+
export function captureError(error: Error, errorType?: McpErrorType, extraData?: Record<string, unknown>): void {
27+
try {
28+
const client = getClient();
29+
if (!client) return;
30+
31+
const activeSpan = getActiveSpan();
32+
if (activeSpan?.isRecording()) {
33+
activeSpan.setStatus({
34+
code: SPAN_STATUS_ERROR,
35+
message: 'internal_error',
36+
});
37+
}
38+
39+
captureException(error, {
40+
mechanism: {
41+
type: 'mcp_server',
42+
handled: false,
43+
data: {
44+
error_type: errorType || 'handler_execution',
45+
...extraData,
46+
},
47+
},
48+
});
49+
} catch {
50+
// Silently ignore capture errors so it never affects MCP operation
51+
}
52+
}
53+
```
54+
55+
- **Never throws an exception:** All error capture is wrapped in a try/catch and will never throw an exception.
56+
- **Mechanism-based categorization:** Error metadata is attached using the `mechanism` object.
57+
- **Flexible context:** Additional context can be passed via `extraData` and will be included in the mechanism data.
58+
59+
## Handler Wrapping for Error Capture
60+
61+
All MCP server method handlers (`tool`, `resource`, `prompt`) are wrapped to:
62+
- Correlate handler execution with the correct Sentry span (using request/session data)
63+
- Capture both synchronous and asynchronous errors
64+
- Categorize errors by handler type and error nature
65+
- Set span status to error for failed operations
66+
67+
### Error Categorization
68+
69+
Errors are categorized using the mechanism's data field according to the handler and type of error:
70+
71+
- **Tool handler errors:**
72+
- `validation` (e.g., protocol/validation errors)
73+
- `timeout` (e.g., server timeouts)
74+
- `tool_execution` (all other tool errors)
75+
- **Resource handler errors:**
76+
- `resource_operation`
77+
- **Prompt handler errors:**
78+
- `prompt_execution`
79+
- **Transport errors:**
80+
- `transport`
81+
- **Protocol errors:**
82+
- `protocol`
83+
84+
The mechanism approach ensures that error classification information is available in the Sentry UI for debugging and analysis.
85+
86+
**Note**: this mechanism data is not indexed so it is not searchable.
87+
88+
## Span Correlation
89+
90+
All errors are captured within the context of the active Sentry span, so you can:
91+
- See which MCP method, tool, or resource caused the error
92+
- View all arguments and context for the failed request
93+
- Correlate errors with traces and performance data
94+
95+
## Transport Layer Error Instrumentation
96+
97+
The MCP transport layer is also instrumented to:
98+
- Create spans for incoming/outgoing messages
99+
- Capture errors in transport event handlers (e.g., `onerror`)
100+
- Correlate protocol errors with the correct request/response
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: MCP Instrumentation
3+
---
4+
5+
The MCP Server module instruments Anthropic's Model Context Protocol (MCP) SDKs. At the moment it only supports the [MCP Typescript SDK](https://github.com/modelcontextprotocol/typescript-sdk/).
6+
7+
## Features
8+
9+
- [Tracing](./tracing)
10+
- [Errors](./errors)

0 commit comments

Comments
 (0)