Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid compile-time config for api_url #41

Merged
merged 2 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The library has a number of configuration options you can use to overwrite defau
- `config :segment, :retry_start` The time (in ms) to start the first retry. Default value is 100
- `config :segment, :send_to_http` If set to `false`, the library will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
- `config :segment, :tesla, :adapter` This config option allows for overriding the HTTP Adapter for Tesla (which the library defaults to Hackney).This can be useful if you prefer something else, or want to mock the adapter for testing.
- `config :segment, api_url: "https://self-hosted-segment-api.com/v1/"` The Segment-compatible API endpoint that will receive your events. Defaults to `https://api.segment.io/v1/`. This setting is only useful if you are using a Segment-compatible alternative API like [Rudderstack](https://rudderstack.com/).
- `config :segment, api_url: "https://self-hosted-segment-api.com/v1/"` The Segment-compatible API endpoint that will receive your events. Defaults to `https://api.segment.io/v1/`. This setting is only useful if you are using Segment's EU instance or a Segment-compatible alternative API like [Rudderstack](https://rudderstack.com/).

## Usage in Phoenix

Expand Down
4 changes: 1 addition & 3 deletions lib/segment/client/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ defmodule Segment.Http do
require Logger
use Retry

@segment_api_url Application.get_env(:segment, :api_url, "https://api.segment.io/v1/")

@doc """
Create a Tesla client with the Segment Source Write API Key
"""
Expand All @@ -66,7 +64,7 @@ defmodule Segment.Http do
@spec client(String.t(), adapter()) :: client()
def client(api_key, adapter) do
middleware = [
{Tesla.Middleware.BaseUrl, @segment_api_url},
{Tesla.Middleware.BaseUrl, Segment.Config.api_url()},
Tesla.Middleware.JSON,
{Tesla.Middleware.BasicAuth, %{username: api_key, password: ""}}
]
Expand Down
4 changes: 4 additions & 0 deletions lib/segment/config.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
defmodule Segment.Config do
@moduledoc false

def api_url do
Application.get_env(:segment, :api_url, "https://api.segment.io/v1/")
end

def service do
Application.get_env(:segment, :sender_impl, Segment.Analytics.Batcher)
end
Expand Down