Skip to content

Instantly share code, notes, and snippets.

@gosseti
Created November 18, 2025 07:01
Show Gist options
  • Select an option

  • Save gosseti/3d2fcc2157559bd79ada91ca1f8c5e28 to your computer and use it in GitHub Desktop.

Select an option

Save gosseti/3d2fcc2157559bd79ada91ca1f8c5e28 to your computer and use it in GitHub Desktop.
BetterStack Sentry Integration - 401 Unauthorized Issue

BetterStack Sentry Integration - 401 Unauthorized Issue

Issue Summary

We're getting HTTP 401 Unauthorized when the Elixir Sentry SDK attempts to send events to BetterStack's Sentry-compatible endpoint. The SDK successfully sends the events, but BetterStack rejects them with authentication errors.

Environment

  • Elixir: 1.17+
  • Sentry SDK: {:sentry, "~> 11.0.4"}
  • Client: Sentry.HackneyClient
  • Environment: Development (same issue expected in production)

DSN Format Confusion

BetterStack provides two different DSN formats in different locations, and both fail with 401 Unauthorized:

DSN Format #1 - From Documentation Page

Source: https://betterstack.com/docs/errors/collecting-errors/sentry-sdk/?application=1592187

Format:

https://SC36ZjS3KTUCypm***********@s1592187.eu-nbg-2.betterstackdata.com/1

Structure:

  • Host includes application ID as subdomain: s[app-id].eu-nbg-2.betterstackdata.com
  • Project ID at end: /1

DSN Format #2 - From Data Ingestion Page

Source: https://errors.betterstack.com/team/t*****/applications/1592187/data-ingestion

Format:

https://SC36ZjS3KTUCypm***********@eu-nbg-2.betterstackdata.com/1592187

Structure:

  • Generic host: eu-nbg-2.betterstackdata.com
  • Application ID as project: /1592187

Both formats produce identical 401 errors.

Configuration

Following the official Sentry Elixir documentation, we have a minimal vanilla config:

config/runtime.exs

# Vanilla Sentry setup - minimal configuration per Sentry docs
config :sentry,
  dsn: System.get_env("SENTRY_DSN"),
  environment_name: config_env(),
  enable_source_code_context: true,
  root_source_code_paths: [File.cwd!()],
  client: Sentry.HackneyClient,
  send_result: :sync  # For debugging

.env

# We tested BOTH DSN formats - both fail with 401
SENTRY_DSN=https://[key]@[host]/[project]

Test Code

Following the Sentry Elixir documentation example:

# Test 1: Simple message (from Sentry docs)
Sentry.capture_message("Hello Better Stack, this is a test message from Elixir!")

# Test 2: Exception with stacktrace (from Sentry docs)
try do
  raise "This is a test exception from Elixir!"
rescue
  exception ->
    Sentry.capture_exception(exception, stacktrace: __STACKTRACE__)
end

Error Output

Both DSN formats produce identical 401 errors for both test cases:

[warning] Failed to send Sentry event. Sentry failed to report event:
the Sentry server responded with an error, the details are below.

HTTP Status: 401
Response Headers: [
  {"content-type", "application/json"},
  {"access-control-allow-origin", "*"},
  {"access-control-allow-methods", "GET, POST, OPTIONS, HEAD"},
  {"access-control-allow-headers", "*"},
  {"content-length", "25"},
  {"date", "Tue, 18 Nov 2025 06:55:13 GMT"}
]
Response Body: "{\"error\": \"Unauthorized\"}"

Status: :error
Event ID: %Sentry.ClientError{
  reason: :server_error,
  http_response: {401, [...headers...], "{\"error\": \"Unauthorized\"}"}
}

What We've Tried

  1. Tested BOTH DSN formats from BetterStack:

    • Documentation page format: https://[key]@s1592187.eu-nbg-2.betterstackdata.com/1
    • Data ingestion page format: https://[key]@eu-nbg-2.betterstackdata.com/1592187
    • Both fail with identical 401 errors
  2. Confirmed SDK is working correctly:

    • Events are being constructed properly
    • HTTP requests are being sent successfully
    • Using official Sentry.HackneyClient
    • Sentry SDK v11.0.4
  3. Followed official Sentry Elixir docs exactly:

    • Minimal vanilla configuration
    • Using documented capture methods
    • No custom filters or before_send hooks active
    • Standard error/message capture patterns
  4. Verified config loading:

    • DSN is correctly loaded from environment
    • All config values are present and correct
    • Using :sync send mode to see immediate errors

Questions for BetterStack

  1. Why are there two different DSN formats in different parts of the UI?

    • Which format is correct for the Elixir Sentry SDK?
    • Should we expect both formats to work?
  2. Is there a setup step required in BetterStack UI before the Sentry endpoint accepts events?

    • Do we need to enable the integration somewhere?
    • Are there API keys or tokens needed beyond the DSN?
  3. Are there known compatibility issues with:

    • Sentry Elixir SDK v11.0.4?
    • The Sentry.HackneyClient?
  4. Does the BetterStack Sentry endpoint require any additional authentication headers beyond what's embedded in the DSN?

Additional Context

  • The Sentry SDK is successfully constructing and sending events
  • The BetterStack server is responding (not a network/firewall issue)
  • The 401 suggests authentication/authorization problem specifically
  • Both message capture and exception capture fail identically
  • Both DSN formats fail identically
  • We're following the official Sentry Elixir documentation exactly

Expected: Events appear in BetterStack Errors dashboard Actual: HTTP 401 Unauthorized from BetterStack endpoint Tested: Both DSN formats from different BetterStack pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment