ReportError reports the given error to Sentry. The caller is responsible for checking whether telemetry is enabled, and calling the sentry.Flush() function to wait for the report to be uploaded. (By default, Sentry submits reports asynchronously.) Note: an empty 'eventID' can be returned which sign
(err error)
| 363 | // configured or Sentry client decided to not report the error (due to |
| 364 | // configured sampling rate, callbacks, Sentry's event processors, etc). |
| 365 | func ReportError(err error) (eventID string) { |
| 366 | event, extraDetails := BuildSentryReport(err) |
| 367 | |
| 368 | if event.Contexts == nil { |
| 369 | event.Contexts = make(map[string]sentry.Context) |
| 370 | } |
| 371 | for extraKey, extraValue := range extraDetails { |
| 372 | event.Contexts[extraKey] = sentry.Context{"value": extraValue} |
| 373 | } |
| 374 | |
| 375 | // Avoid leaking the machine's hostname by injecting the literal "<redacted>". |
| 376 | // Otherwise, sentry.Client.Capture will see an empty ServerName field and |
| 377 | // automatically fill in the machine's hostname. |
| 378 | event.ServerName = "<redacted>" |
| 379 | |
| 380 | tags := map[string]string{ |
| 381 | "report_type": "error", |
| 382 | } |
| 383 | for key, value := range tags { |
| 384 | event.Tags[key] = value |
| 385 | } |
| 386 | |
| 387 | res := sentry.CaptureEvent(event) |
| 388 | if res != nil { |
| 389 | eventID = string(*res) |
| 390 | } |
| 391 | return |
| 392 | } |
| 393 | |
| 394 | func lastPathComponent(tn string) string { |
| 395 | // Strip the path prefix. |
searching dependent graphs…