### start_link(opts \\ []) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.ApiServer.html Starts the ApiServer with given options. ```APIDOC ## start_link(opts \\ []) ### Description Starts the ApiServer with given options. ### Function start_link(opts \\ []) ### Parameters - **opts** (Keyword.t()) - Optional - Options for starting the server. ### Options - **:http** (module()) - Optional - The HTTP module to use for sending spans to the agent. Defaults to `HTTPoison`. - **:host** (string()) - Optional - The host the agent can be reached at. Defaults to `"localhost"`. - **:port** (integer()) - Optional - The port to use when sending traces to the agent. Defaults to `8126`. - **:verbose?** (boolean()) - Optional - Only to be used for debugging: All finished traces will be logged. Defaults to `false`. - **:batch_size** (integer()) - Optional - The number of traces that should be sent in a single batch. Defaults to `10`. - **:sync_threshold** (integer()) - Optional - The maximum number of processes that may be sending traces at any one time. This adds backpressure. Defaults to `20`. - **:name** (atom()) - Optional - The name the GenServer should have. Currently only used for testing. Defaults to `SpandexDatadog.ApiServer`. - **:trap_exits?** (boolean()) - Optional - Whether or not to trap exits and attempt to flush traces on shutdown, defaults to `false`. Useful if you do frequent deploys and you don't want to lose traces each deploy. ### Returns - **on_start** (GenServer.on_start()) - The result of starting the GenServer. ``` -------------------------------- ### Start SpandexDatadog.ApiServer in supervisor Source: https://hexdocs.pm/spandex_datadog/readme.html Configure and start the SpandexDatadog.ApiServer as a worker in your application's supervisor. Place ApiServer before other children that might send traces, such as Ecto.Repo and Phoenix.Endpoint. ```elixir # Example configuration # Note: You should put ApiServer before any other children in the list that # might try to send traces before the ApiServer has started up, for example # Ecto.Repo and Phoenix.Endpoint spandex_opts = [ host: System.get_env("DATADOG_HOST") || "localhost", port: System.get_env("DATADOG_PORT") || 8126, batch_size: System.get_env("SPANDEX_BATCH_SIZE") || 10, sync_threshold: System.get_env("SPANDEX_SYNC_THRESHOLD") || 100, http: HTTPoison ] children = [ # ... {SpandexDatadog.ApiServer, spandex_opts}, MyApp.Repo, MyAppWeb.Endpoint, # ... ] opts = [strategy: :one_for_one, name: MyApp.Supervisor] Supvervisor.start_link(children, opts) ``` -------------------------------- ### child_spec(init_arg) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.ApiServer.html Returns a specification to start this module under a supervisor. See Supervisor. ```APIDOC ## child_spec(init_arg) ### Description Returns a specification to start this module under a supervisor. See `Supervisor`. ### Function child_spec(init_arg) ### Parameters - **init_arg** (term) - Required - Argument passed to the child specification. ### Returns - **spec** (Supervisor.child_spec()) - The child specification. ``` -------------------------------- ### Add spandex_datadog dependency in mix.exs Source: https://hexdocs.pm/spandex_datadog/readme.html Add the :spandex_datadog dependency to your mix.exs file to install the package. ```elixir def deps do [ {:spandex_datadog, "~> 1.4"} ] end ``` -------------------------------- ### send_and_log(traces, state) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.ApiServer.html Sends traces and logs the result. ```APIDOC ## send_and_log(traces, state) ### Description Sends traces and logs the result. ### Function send_and_log(traces, state) ### Parameters - **traces** ([Spandex.Trace.t()]) - Required - The list of traces to send. - **state** (SpandexDatadog.ApiServer.State.t()) - Required - The current state. ### Returns - **:ok** (atom()) - Always returns :ok. ``` -------------------------------- ### send_trace(trace, opts \\ []) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.ApiServer.html Send spans asynchronously to DataDog. ```APIDOC ## send_trace(trace, opts \\ []) ### Description Send spans asynchronously to DataDog. ### Function send_trace(trace, opts \\ []) ### Parameters - **trace** (Spandex.Trace.t()) - Required - The trace to send. - **opts** (Keyword.t()) - Optional - Options for sending the trace. ### Returns - **:ok** (atom()) - Always returns :ok. ``` -------------------------------- ### inject_context(headers, span_context, opts) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.Adapter.html Injects Datadog-specific HTTP headers to represent the specified SpanContext. Returns the updated headers list. ```APIDOC ## inject_context(headers, span_context, opts) ### Description Injects Datadog-specific HTTP headers to represent the specified SpanContext. ### Function Signature ```elixir @spec inject_context( [{term(), term()}], Spandex.SpanContext.t(), Spandex.Tracer.opts() ) :: [{term(), term()}] ``` ### Parameters - **headers** ([{term(), term()}]) - Required - The headers list to inject into. - **span_context** (Spandex.SpanContext.t()) - Required - The span context to represent. - **opts** (Spandex.Tracer.opts()) - Required - Tracer options. ### Returns - [{term(), term()}] - The updated headers list with Datadog-specific headers injected. ``` -------------------------------- ### format(span, priority, baggage) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.ApiServer.html Formats a span with priority and baggage into a map. ```APIDOC ## format(span, priority, baggage) ### Description Formats a span with priority and baggage into a map. ### Function format(span, priority, baggage) ### Parameters - **span** (Spandex.Span.t()) - Required - The span to format. - **priority** (integer()) - Required - The priority value. - **baggage** (Keyword.t()) - Required - The baggage keywords. ### Returns - **map** (map()) - The formatted map. ``` -------------------------------- ### distributed_context(conn, opts) Source: https://hexdocs.pm/spandex_datadog/SpandexDatadog.Adapter.html Fetches the Datadog-specific conn request headers if they are present. Returns a SpanContext or an error if no distributed trace is found. ```APIDOC ## distributed_context(conn, opts) ### Description Fetches the Datadog-specific conn request headers if they are present. ### Function Signature ```elixir @spec distributed_context(conn :: Plug.Conn.t(), Spandex.Tracer.opts()) :: {:ok, Spandex.SpanContext.t()} | {:error, :no_distributed_trace} ``` ### Parameters - **conn** (Plug.Conn.t()) - Required - The connection to fetch headers from. - **opts** (Spandex.Tracer.opts()) - Required - Tracer options. ### Returns - `{:ok, Spandex.SpanContext.t()}` - Success with the span context. - `{:error, :no_distributed_trace}` - Error when no distributed trace headers are present. ### Alternative Signature ```elixir @spec distributed_context(headers :: Spandex.headers(), Spandex.Tracer.opts()) :: {:ok, Spandex.SpanContext.t()} | {:error, :no_distributed_trace} ``` ### Parameters (Alternative) - **headers** (Spandex.headers()) - Required - The headers list to fetch from. - **opts** (Spandex.Tracer.opts()) - Required - Tracer options. ### Returns (Alternative) - `{:ok, Spandex.SpanContext.t()}` - Success with the span context. - `{:error, :no_distributed_trace}` - Error when no distributed trace headers are present. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.