|
| 1 | +--- |
| 2 | +title: Troubleshooting |
| 3 | +description: "Learn how to troubleshoot your tracing setup." |
| 4 | +sidebar_order: 60 |
| 5 | +--- |
| 6 | + |
| 7 | +If you need help managing transactions, you can read more here. If you need additional help, you can ask on GitHub. Customers on a paid plan may also contact support. |
| 8 | + |
| 9 | +## Group Transactions |
| 10 | + |
| 11 | +When Sentry captures transactions, they are assigned a transaction name. This name is generally auto-generated by the Sentry SDK based on the framework integrations you are using. If you can't leverage the automatic transaction generation (or want to customize how transaction names are generated) you can use the scope API to set transaction names or use a custom event processor. |
| 12 | + |
| 13 | +For example, to set a transaction name: |
| 14 | + |
| 15 | +```python |
| 16 | +import sentry_sdk |
| 17 | + |
| 18 | +# Setting the transaction name directly on the current scope |
| 19 | +scope = sentry_sdk.get_current_scope() |
| 20 | +scope.set_transaction_name("UserListView") |
| 21 | +``` |
| 22 | + |
| 23 | +You can define a custom `before_send_transaction` callback to modify transaction names: |
| 24 | + |
| 25 | +```python |
| 26 | +import sentry_sdk |
| 27 | +from sentry_sdk.integrations.django import DjangoIntegration |
| 28 | +from sentry_sdk.types import Event, Hint |
| 29 | + |
| 30 | +def transaction_processor(event: Event, hint: Hint) -> Event | None: |
| 31 | + if event.get("type") == "transaction": |
| 32 | + # Extract path from transaction name |
| 33 | + transaction_name = event.get("transaction", "") |
| 34 | + |
| 35 | + # Remove variable IDs from URLs to reduce cardinality |
| 36 | + if "/user/" in transaction_name: |
| 37 | + # Convert /user/123/ to /user/:id/ |
| 38 | + import re |
| 39 | + event["transaction"] = re.sub(r'/user/\d+/', '/user/:id/', transaction_name) |
| 40 | + |
| 41 | + return event |
| 42 | + |
| 43 | +sentry_sdk.init( |
| 44 | + dsn="your-dsn", |
| 45 | + integrations=[DjangoIntegration()], |
| 46 | + traces_sample_rate=1.0, |
| 47 | + # Add your event processor during SDK initialization |
| 48 | + before_send_transaction=transaction_processor, |
| 49 | +) |
| 50 | +``` |
| 51 | + |
| 52 | +## Control Data Truncation |
| 53 | + |
| 54 | +Currently, every tag has a maximum character limit of 200 characters. Tags over the 200 character limit will become truncated, losing potentially important information. To retain this data, you can split data over several tags instead. |
| 55 | + |
| 56 | +For example, a 200+ character tag like this: |
| 57 | + |
| 58 | +`https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=161803398874989484820458683436563811772030917980576` |
| 59 | + |
| 60 | +...will become truncated to: |
| 61 | + |
| 62 | +`https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=1618033988749894848` |
| 63 | + |
| 64 | +Using `span.set_tag` for shorter values, in combination with `span.set_attribute` maintains the details. |
| 65 | + |
| 66 | +```python |
| 67 | +import sentry_sdk |
| 68 | + |
| 69 | +# ... |
| 70 | + |
| 71 | +base_url = "https://empowerplant.io" |
| 72 | +endpoint = "/api/0/projects/ep/setup_form" |
| 73 | +parameters = { |
| 74 | + "user_id": 314159265358979323846264338327, |
| 75 | + "tracking_id": "EasyAsABC123OrSimpleAsDoReMi", |
| 76 | + "product_name": "PlantToHumanTranslator", |
| 77 | + "product_id": 161803398874989484820458683436563811772030917980576, |
| 78 | +} |
| 79 | + |
| 80 | +with sentry_sdk.start_span(op="request", name="setup form") as span: |
| 81 | + span.set_tag("base_url", base_url) |
| 82 | + span.set_tag("endpoint", endpoint) |
| 83 | + for param, value in parameters.items(): |
| 84 | + span.set_attribute(f"parameters.{param}", value) |
| 85 | + |
| 86 | + make_request( |
| 87 | + "{base_url}/{endpoint}/".format( |
| 88 | + base_url=base_url, |
| 89 | + endpoint=endpoint, |
| 90 | + ), |
| 91 | + data=parameters, |
| 92 | + ) |
| 93 | + |
| 94 | + # ... |
| 95 | +``` |
0 commit comments