sentry-tool 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ # Sentry Tool Environment Configuration Template
2
+ # Copy to .envrc and fill in your values
3
+ # NEVER commit .envrc with real credentials
4
+ #
5
+ # NOTE: The recommended approach is to use TOML profiles in
6
+ # ~/.config/sentry-tool/config.toml (see README.md).
7
+ # Environment variables below override profile values when set.
8
+
9
+ # === PROFILE SELECTION ===
10
+
11
+ # Select a named profile (overrides default_profile in config.toml)
12
+ #SENTRY_PROFILE=my-profile
13
+
14
+ # === OVERRIDES (optional, override active profile values) ===
15
+
16
+ # Sentry API authentication token
17
+ # Get from: Sentry Settings > Account > API > Auth Tokens
18
+ # Required scopes: project:read, event:read
19
+ #SENTRY_AUTH_TOKEN=sntrys_...
20
+
21
+ # Sentry instance URL
22
+ #SENTRY_URL=https://sentry.io
23
+
24
+ # Organization slug
25
+ #SENTRY_ORG=my-org
26
+
27
+ # Default project slug
28
+ #SENTRY_PROJECT=my-project
@@ -0,0 +1,219 @@
1
+ # Contributing to Sentry Tool
2
+
3
+ Thank you for your interest in contributing to Sentry Tool!
4
+
5
+ ## Development Setup
6
+
7
+ ### Prerequisites
8
+
9
+ - Python >= 3.13
10
+ - uv package manager
11
+ - direnv (optional, for .envrc support)
12
+
13
+ ### Initial Setup
14
+
15
+ ```bash
16
+ # Navigate to project directory
17
+ cd sentry-tool
18
+
19
+ # Install dependencies (including dev dependencies)
20
+ uv sync --group dev
21
+
22
+ # Install pre-commit hooks (if configured at repository level)
23
+ pre-commit install
24
+
25
+ # Verify installation
26
+ uv run sentry-tool --help
27
+ ```
28
+
29
+ ### Environment Configuration
30
+
31
+ Create a `.envrc` file for local development (never commit this file):
32
+
33
+ ```bash
34
+ # .envrc (example)
35
+ export SENTRY_AUTH_TOKEN=your_auth_token_here
36
+ export SENTRY_URL=https://sentry.io
37
+ export SENTRY_ORG=your-org
38
+ export SENTRY_PROJECT=your-project
39
+ ```
40
+
41
+ **Security:** Never commit `.envrc` with real credentials. Use the provided `.env.template` as a guide.
42
+
43
+ ## Development Workflow
44
+
45
+ ### Running the CLI Locally
46
+
47
+ ```bash
48
+ # Run any command
49
+ uv run sentry-tool list
50
+ uv run sentry-tool show ISSUE-ID
51
+ ```
52
+
53
+ ### Running Tests
54
+
55
+ ```bash
56
+ # Run all tests
57
+ uv run pytest
58
+
59
+ # Run with coverage
60
+ uv run pytest --cov
61
+
62
+ # Run specific test file
63
+ uv run pytest tests/test_cli.py
64
+
65
+ # Run with verbose output
66
+ uv run pytest -v
67
+ ```
68
+
69
+ ### Code Quality
70
+
71
+ Before committing, ensure all quality checks pass:
72
+
73
+ ```bash
74
+ # Stage your changes first
75
+ git add <files>
76
+
77
+ # Run linting
78
+ uv run ruff check src tests
79
+
80
+ # Auto-fix issues
81
+ uv run ruff check --fix src tests
82
+
83
+ # Format code
84
+ uv run ruff format src tests
85
+
86
+ # Type checking (source only, not tests)
87
+ uv run mypy src
88
+
89
+ # Run pre-commit hooks on staged files
90
+ pre-commit run --files $(git diff --cached --name-only)
91
+ ```
92
+
93
+ **Quality Gate:** All of the following must pass before committing:
94
+ - pytest (all tests pass)
95
+ - ruff check (no linting errors)
96
+ - mypy (no type errors)
97
+ - pre-commit hooks (all hooks pass)
98
+
99
+ ### Adding Dependencies
100
+
101
+ ```bash
102
+ # Add runtime dependency
103
+ uv add package-name
104
+
105
+ # Add dev dependency
106
+ uv add --group dev package-name
107
+
108
+ # Remove dependency
109
+ uv remove package-name
110
+
111
+ # Update all dependencies
112
+ uv sync --upgrade
113
+ ```
114
+
115
+ **Always commit `uv.lock`** after changing dependencies to ensure reproducible builds.
116
+
117
+ ## Code Style Guidelines
118
+
119
+ ### General Principles
120
+
121
+ - Follow PEP 8 style guide
122
+ - Use type hints for all function signatures
123
+ - Write descriptive docstrings for public APIs
124
+ - Keep functions focused and small
125
+ - Prefer composition over inheritance
126
+
127
+ ### CLI Command Structure
128
+
129
+ When adding new commands:
130
+
131
+ ```python
132
+ @app.command()
133
+ def new_command(
134
+ arg: str = typer.Argument(..., help="Argument description"),
135
+ opt: str = typer.Option("default", "--option", "-o", help="Option description"),
136
+ ):
137
+ """
138
+ Brief command description.
139
+
140
+ Longer description with usage examples.
141
+
142
+ Examples:
143
+ sentry-tool new-command value
144
+ sentry-tool new-command value --option custom
145
+ """
146
+ ...
147
+ ```
148
+
149
+ ### Error Handling
150
+
151
+ - Use appropriate exit codes (see `ExitCode` enum in patterns)
152
+ - Write errors to stderr: `typer.echo("Error: ...", err=True)`
153
+ - Provide actionable error messages
154
+ - Never expose stack traces to users (unless --debug flag)
155
+
156
+ ### Testing
157
+
158
+ - Write tests for all new features
159
+ - Use `requests-mock` for mocking Sentry API calls
160
+ - Aim for >80% code coverage
161
+ - Test both success and error paths
162
+
163
+ ## Pull Request Process
164
+
165
+ 1. **Create a branch** for your feature or fix
166
+ 2. **Make your changes** following the style guide
167
+ 3. **Write tests** for new functionality
168
+ 4. **Run quality checks** (pytest, ruff, mypy, pre-commit)
169
+ 5. **Update documentation** if needed (README, docstrings)
170
+ 6. **Commit with clear message** describing the change
171
+ 7. **Push and create PR** with detailed description
172
+
173
+ ### Commit Message Format
174
+
175
+ ```
176
+ type: brief description (50 chars max)
177
+
178
+ Longer description if needed, explaining why the change
179
+ was made and any important context.
180
+
181
+ Examples:
182
+ - feat: add support for filtering issues by level
183
+ - fix: handle 404 errors gracefully in show command
184
+ - docs: update README with new configuration options
185
+ - test: add tests for tag analysis command
186
+ ```
187
+
188
+ ## Testing Guidelines
189
+
190
+ ### Unit Tests
191
+
192
+ - Test individual functions and methods
193
+ - Mock external dependencies (Sentry API)
194
+ - Focus on business logic
195
+
196
+ ### Integration Tests
197
+
198
+ - Test command-line interface end-to-end
199
+ - Use `typer.testing.CliRunner`
200
+ - Mock Sentry API responses
201
+
202
+ ### Test Organization
203
+
204
+ ```
205
+ tests/
206
+ ├── conftest.py # Shared fixtures
207
+ ├── test_cli.py # CLI command tests
208
+ ├── test_client.py # API client tests
209
+ └── test_config.py # Configuration tests
210
+ ```
211
+
212
+ ## Getting Help
213
+
214
+ - Check existing issues and PRs
215
+ - Ask questions in issues or discussions
216
+
217
+ ## License
218
+
219
+ By contributing, you agree that your contributions will be licensed under the MIT License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vlad Korolev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,404 @@
1
+ Metadata-Version: 2.4
2
+ Name: sentry-tool
3
+ Version: 0.1.0
4
+ Summary: CLI tool for querying and managing Sentry issues
5
+ Project-URL: Homepage, https://github.com/vladistan/sentry-tool
6
+ Project-URL: Repository, https://github.com/vladistan/sentry-tool
7
+ Project-URL: Issues, https://github.com/vladistan/sentry-tool/issues
8
+ Project-URL: Source, https://github.com/vladistan/sentry-tool
9
+ Project-URL: Documentation, https://github.com/vladistan/sentry-tool#readme
10
+ Author-email: Vlad Korolev <vlad@arsenale.bio>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Requires-Python: >=3.13
14
+ Requires-Dist: pydantic-settings>=2.0.0
15
+ Requires-Dist: requests>=2.31.0
16
+ Requires-Dist: rich>=13.0.0
17
+ Requires-Dist: sentry-sdk>=2.0.0
18
+ Requires-Dist: structlog>=24.0
19
+ Requires-Dist: tenacity>=8.0.0
20
+ Requires-Dist: typer>=0.12.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: mypy>=1.13; extra == 'dev'
23
+ Requires-Dist: pre-commit>=4.0; extra == 'dev'
24
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
25
+ Requires-Dist: pytest>=8.0; extra == 'dev'
26
+ Requires-Dist: requests-mock>=1.11.0; extra == 'dev'
27
+ Requires-Dist: ruff>=0.8; extra == 'dev'
28
+ Requires-Dist: types-requests>=2.31.0; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # Sentry Tool
32
+
33
+ CLI tool for querying and managing Sentry issues.
34
+
35
+ ## Overview
36
+
37
+ Sentry Tool provides a command-line interface for interacting with Sentry's API to query issues, view events, and analyze error patterns. It's designed for DevOps engineers, developers, and SREs who need quick CLI access to Sentry data.
38
+
39
+ ## Features
40
+
41
+ - **List issues**: View recent issues in a project or across all projects
42
+ - **Show issue details**: Get comprehensive information about specific issues
43
+ - **View events**: Examine event details and stacktraces
44
+ - **List events**: See recent events for an issue
45
+ - **Tag analysis**: Analyze tag distributions across issues
46
+ - **List projects**: View all projects in an organization
47
+ - **Open in browser**: Quick-launch Sentry web UI
48
+ - **Multi-instance support**: TOML-based profiles for multiple Sentry instances
49
+ - **Configuration management**: Validate connectivity, list projects across profiles
50
+
51
+ ## Installation
52
+
53
+ ### Requirements
54
+
55
+ - Python >= 3.13
56
+ - uv package manager
57
+
58
+ ### Setup
59
+
60
+ ```bash
61
+ # Clone or navigate to the sentry-tool directory
62
+ cd sentry-tool
63
+
64
+ # Install dependencies
65
+ uv sync
66
+
67
+ # Install dev dependencies (optional)
68
+ uv sync --group dev
69
+ ```
70
+
71
+ ## Configuration
72
+
73
+ Sentry Tool supports a TOML-based profile system for managing multiple Sentry instances, with environment variable overrides for flexibility.
74
+
75
+ ### Profile Configuration (Recommended)
76
+
77
+ Create a TOML configuration file at `~/.config/sentry-tool/config.toml`:
78
+
79
+ ```toml
80
+ default_profile = "my-sentry"
81
+
82
+ [profiles.my-sentry]
83
+ url = "https://sentry.example.com"
84
+ org = "my-org"
85
+ project = "my-project"
86
+ auth_token = "sntrys_..."
87
+
88
+ [profiles.cloud]
89
+ url = "https://sentry.io"
90
+ org = "my-cloud-org"
91
+ project = "web-app"
92
+ auth_token = "sntrys_..."
93
+ ```
94
+
95
+ Each profile defines:
96
+
97
+ | Field | Description | Default |
98
+ |-------|-------------|---------|
99
+ | `url` | Sentry instance URL | `https://sentry.io` |
100
+ | `org` | Organization slug | `sentry` |
101
+ | `project` | Default project slug | *(none)* |
102
+ | `auth_token` | API authentication token | *(required)* |
103
+
104
+ ### Environment Variable Overrides
105
+
106
+ Environment variables override profile values. This is useful for CI/CD or temporary overrides.
107
+
108
+ | Variable | Overrides | Description |
109
+ |----------|-----------|-------------|
110
+ | `SENTRY_AUTH_TOKEN` | `auth_token` | API authentication token |
111
+ | `SENTRY_URL` | `url` | Sentry instance URL |
112
+ | `SENTRY_ORG` | `org` | Organization slug |
113
+ | `SENTRY_PROJECT` | `project` | Default project slug |
114
+ | `SENTRY_PROFILE` | *(profile selection)* | Use this profile instead of default |
115
+
116
+ ### Getting a Sentry Auth Token
117
+
118
+ 1. Log into your Sentry instance
119
+ 2. Navigate to Settings > Account > API > Auth Tokens
120
+ 3. Create a new token with appropriate scopes (at minimum: `project:read`, `event:read`)
121
+ 4. Add the token to your profile configuration or set `SENTRY_AUTH_TOKEN`
122
+
123
+ ### Verifying Configuration
124
+
125
+ ```bash
126
+ # Show current configuration and all profiles
127
+ sentry-tool config show
128
+
129
+ # Verify connectivity to all profiles
130
+ sentry-tool config validate
131
+ ```
132
+
133
+ ## Global Flags
134
+
135
+ These flags are available on the root command and apply to all subcommands.
136
+
137
+ | Flag | Short | Description |
138
+ |------|-------|-------------|
139
+ | `--profile` | `-P` | Use a named profile from config |
140
+ | `--project` | `-p` | Override the project slug from the active profile |
141
+
142
+ Most commands also accept:
143
+
144
+ | Flag | Short | Values | Description |
145
+ |------|-------|--------|-------------|
146
+ | `--format` | `-f` | `table`, `json` | Output format (default: `table`) |
147
+
148
+ ## Usage
149
+
150
+ ### `list` - List Recent Issues
151
+
152
+ List recent issues in a project. Use `--all-projects/-A` to list across all projects.
153
+
154
+ ```bash
155
+ sentry-tool list
156
+ sentry-tool list -p my-project -n 5
157
+ sentry-tool list -s unresolved
158
+ sentry-tool list -A
159
+ sentry-tool list --format json
160
+ ```
161
+
162
+ | Flag | Short | Description | Default |
163
+ |------|-------|-------------|---------|
164
+ | `--project` | `-p` | Project slug | profile default |
165
+ | `--all-projects` | `-A` | List issues across all projects (mutually exclusive with `-p`) | |
166
+ | `--max` | `-n` | Maximum issues to show | `10` |
167
+ | `--status` | `-s` | Filter by status: `resolved`, `unresolved`, `muted` | |
168
+ | `--format` | `-f` | Output format: `table`, `json` | `table` |
169
+
170
+ ---
171
+
172
+ ### `show` - Show Issue Details
173
+
174
+ Show comprehensive details for a specific issue.
175
+
176
+ ```bash
177
+ sentry-tool show 24
178
+ sentry-tool show OTEL-COLLECTOR-Q
179
+ sentry-tool show 24 --format json
180
+ ```
181
+
182
+ | Argument | Description |
183
+ |----------|-------------|
184
+ | `ISSUE_ID` | Issue ID (numeric like `24` or short ID like `OTEL-COLLECTOR-Q`) |
185
+
186
+ | Flag | Short | Description | Default |
187
+ |------|-------|-------------|---------|
188
+ | `--format` | `-f` | Output format: `table`, `json` | `table` |
189
+
190
+ **Output includes:** Title, Status, Level, Priority, Event count, First/Last seen, Tags, Release info, Permalink
191
+
192
+ ---
193
+
194
+ ### `event` - Show Event Details
195
+
196
+ Show event details for an issue. By default shows the latest event.
197
+
198
+ ```bash
199
+ sentry-tool event 24
200
+ sentry-tool event OTEL-COLLECTOR-Q
201
+ sentry-tool event 24 -e abc123...
202
+ sentry-tool event 24 -c
203
+ sentry-tool event 24 --format json
204
+ ```
205
+
206
+ | Argument | Description |
207
+ |----------|-------------|
208
+ | `ISSUE_ID` | Issue ID (numeric or short ID) |
209
+
210
+ | Flag | Short | Description | Default |
211
+ |------|-------|-------------|---------|
212
+ | `--event` | `-e` | Specific event ID | latest |
213
+ | `--context` | `-c` | Show only context/stacktrace | |
214
+ | `--format` | `-f` | Output format: `table`, `json` | `table` |
215
+
216
+ **Output includes:** Event ID, Title, Message, Date, Server, SDK info, Release, Context, Exception with stacktrace
217
+
218
+ ---
219
+
220
+ ### `events` - List Recent Events
221
+
222
+ List recent events for an issue.
223
+
224
+ ```bash
225
+ sentry-tool events 24
226
+ sentry-tool events OTEL-COLLECTOR-Q -n 5
227
+ sentry-tool events 24 --format json
228
+ ```
229
+
230
+ | Argument | Description |
231
+ |----------|-------------|
232
+ | `ISSUE_ID` | Issue ID (numeric or short ID) |
233
+
234
+ | Flag | Short | Description | Default |
235
+ |------|-------|-------------|---------|
236
+ | `--max` | `-n` | Maximum events to show | `10` |
237
+ | `--format` | `-f` | Output format: `table`, `json` | `table` |
238
+
239
+ **Output:** Table with Event ID, Date, Server
240
+
241
+ ---
242
+
243
+ ### `tags` - Show Tag Values
244
+
245
+ Show tag values for an issue. Lists available tags when no tag key is provided.
246
+
247
+ ```bash
248
+ sentry-tool tags OTEL-COLLECTOR-14
249
+ sentry-tool tags OTEL-COLLECTOR-14 server_name
250
+ sentry-tool tags OTEL-COLLECTOR-14 release
251
+ sentry-tool tags 14 server_name --format json
252
+ ```
253
+
254
+ | Argument | Description |
255
+ |----------|-------------|
256
+ | `ISSUE_ID` | Issue ID (numeric or short ID) |
257
+ | `TAG_KEY` | *(optional)* Tag key to show values for (e.g., `server_name`, `release`) |
258
+
259
+ | Flag | Short | Description | Default |
260
+ |------|-------|-------------|---------|
261
+ | `--format` | `-f` | Output format: `table`, `json` | `table` |
262
+
263
+ **Output:**
264
+ - Without `TAG_KEY`: Table of available tags with unique value counts
265
+ - With `TAG_KEY`: Table showing tag values with count and percentage distribution
266
+
267
+ ---
268
+
269
+ ### `list-projects` - List Projects
270
+
271
+ List all projects in the configured organization.
272
+
273
+ ```bash
274
+ sentry-tool list-projects
275
+ sentry-tool list-projects --format json
276
+ ```
277
+
278
+ | Flag | Short | Description | Default |
279
+ |------|-------|-------------|---------|
280
+ | `--format` | `-f` | Output format: `table`, `json` | `table` |
281
+
282
+ ---
283
+
284
+ ### `open` - Open in Browser
285
+
286
+ Open Sentry web UI in the default browser. Without arguments, opens the organization dashboard. With an issue ID, opens that issue directly.
287
+
288
+ ```bash
289
+ sentry-tool open
290
+ sentry-tool open 24
291
+ ```
292
+
293
+ | Argument | Description |
294
+ |----------|-------------|
295
+ | `ISSUE_ID` | *(optional)* Issue ID to open directly |
296
+
297
+ ---
298
+
299
+ ### `config` - Configuration Management
300
+
301
+ Subcommands for managing and verifying configuration.
302
+
303
+ #### `config show`
304
+
305
+ Display current configuration including active profile and all configured profiles.
306
+
307
+ ```bash
308
+ sentry-tool config show
309
+ sentry-tool config show --format json
310
+ ```
311
+
312
+ #### `config profiles`
313
+
314
+ List configured profile names with default marked.
315
+
316
+ ```bash
317
+ sentry-tool config profiles
318
+ sentry-tool config profiles --format json
319
+ ```
320
+
321
+ #### `config list-projects`
322
+
323
+ Enumerate Sentry projects for each configured profile. Profiles with missing auth tokens are skipped.
324
+
325
+ ```bash
326
+ sentry-tool config list-projects
327
+ sentry-tool config list-projects --format json
328
+ ```
329
+
330
+ #### `config validate`
331
+
332
+ Verify connectivity to all configured profiles by querying projects. Useful after initial setup.
333
+
334
+ ```bash
335
+ sentry-tool config validate
336
+ sentry-tool config validate --format json
337
+ ```
338
+
339
+ All `config` subcommands accept `--format/-f` (`table` or `json`, default: `table`).
340
+
341
+ ---
342
+
343
+ ### Common Workflows
344
+
345
+ **Investigate a New Issue:**
346
+ ```bash
347
+ # 1. List recent unresolved issues
348
+ sentry-tool list -s unresolved
349
+
350
+ # 2. Show details for an issue
351
+ sentry-tool show OTEL-COLLECTOR-14
352
+
353
+ # 3. See the latest event with stack trace
354
+ sentry-tool event OTEL-COLLECTOR-14
355
+
356
+ # 4. Check which servers are affected
357
+ sentry-tool tags OTEL-COLLECTOR-14 server_name
358
+ ```
359
+
360
+ **Cross-Instance Investigation:**
361
+ ```bash
362
+ # List issues across all projects on a specific instance
363
+ sentry-tool -P production list -A
364
+
365
+ # Compare the same project on different instances
366
+ sentry-tool -P staging -p web-app list
367
+ sentry-tool -P production -p web-app list
368
+ ```
369
+
370
+ **Export Data for Analysis:**
371
+ ```bash
372
+ # Get issue details as JSON
373
+ sentry-tool show OTEL-COLLECTOR-14 --format json > issue.json
374
+
375
+ # Get event details as JSON
376
+ sentry-tool event OTEL-COLLECTOR-14 --format json > event.json
377
+ ```
378
+
379
+ ## Development
380
+
381
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development workflow, testing, and contribution guidelines.
382
+
383
+ ### Quick Start
384
+
385
+ ```bash
386
+ # Install with dev dependencies
387
+ uv sync --group dev
388
+
389
+ # Run tests
390
+ uv run pytest
391
+
392
+ # Type checking
393
+ uv run mypy src
394
+
395
+ # Linting
396
+ uv run ruff check src tests
397
+
398
+ # Format code
399
+ uv run ruff format src tests
400
+ ```
401
+
402
+ ## License
403
+
404
+ MIT License - see [LICENSE](LICENSE) file for details.