### Setup OpentelemetryOban in Application Start Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_oban/README.md Call OpentelemetryOban.setup() in your application's start function to initialize the instrumentation. ```elixir def start(_type, _args) do OpentelemetryOban.setup() # ... end ``` -------------------------------- ### Setup OpentelemetryFinch in Application Start Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_finch/README.md Call OpentelemetryFinch.setup() in your application's start function to enable instrumentation. ```elixir def start(_type, _args) do OpentelemetryFinch.setup() # ... end ``` -------------------------------- ### Install Dependencies and Setup Ecto Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/basic_phoenix_ecto/README.md Run these commands to fetch project dependencies and set up the Ecto database schema. ```bash mix deps.get, ecto.setup ``` -------------------------------- ### Setup OpentelemetryPhoenix Handler Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/README.md Configure the OpentelemetryPhoenix handler in your application's behavior before the top-level supervisor starts. The `:bandit` adapter is shown as an example. ```elixir OpentelemetryPhoenix.setup(adapter: :bandit) ``` -------------------------------- ### Setup OpentelemetryCommanded in Application Behavior Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_commanded/README.md Call OpentelemetryCommanded.setup() in your application's behavior before the supervisor starts to initialize the telemetry handler. ```elixir # lib/my_app/application.ex OpentelemetryCommanded.setup() ``` -------------------------------- ### Setup OpentelemetryDataloader Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_dataloader/README.md Call this function to set up the handler in your application behavior before your top-level supervisor starts. ```elixir OpentelemetryDataloader.setup() ``` -------------------------------- ### Setup OpentelemetryEcto Handler Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_ecto/README.md Configure the OpentelemetryEcto handler in your application's start callback before the top-level supervisor. Pass the Telemetry prefix of the Ecto repo you wish to instrument. ```elixir OpentelemetryEcto.setup([:blog, :repo]) ``` -------------------------------- ### Basic Broadway Setup Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_broadway/README.md Set up the basic OpenTelemetry handler for Broadway pipelines in your application's start callback. ```elixir def start(_type, _args) do OpentelemetryBroadway.setup() Supervisor.start_link(...) end ``` -------------------------------- ### Setup OpentelemetryBandit Handler Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_bandit/README.md Call this function to set up the OpentelemetryBandit telemetry handler. It should be called before your top-level supervisor starts. ```elixir OpentelemetryBandit.setup() ``` -------------------------------- ### Start Phoenix Server with OpenTelemetry Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/basic_phoenix_ecto/README.md Start the Phoenix server with the OTEL_SERVICE_NAME environment variable set. This command initiates the application and enables OpenTelemetry tracing. ```bash OTEL_SERVICE_NAME=demo iex -S mix phx.server ``` -------------------------------- ### Basic OpenTelemetry gRPC Setup Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Set up both client and server instrumentation for OpenTelemetry gRPC in your application's startup. ```elixir # In your application startup (e.g., Application.start/2) OpentelemetryGrpc.setup() ``` -------------------------------- ### Setup OpentelemetryBandit with Phoenix Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_bandit/README.md When using Phoenix, set up both OpentelemetryBandit and OpentelemetryPhoenix. Specify the :bandit adapter for OpentelemetryPhoenix. ```elixir OpentelemetryBandit.setup() OpentelemetryPhoenix.setup(adapter: :bandit) ``` -------------------------------- ### Original Job Insertion Method Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_oban/README.md Example of the standard Oban job insertion method before using OpentelemetryOban. ```elixir %{id: 1, in_the: "business", of_doing: "business"} |> MyApp.Business.new() |> Oban.insert() ``` -------------------------------- ### Start OpenTelemetry Collector and Jaeger Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Use Docker Compose to start the OpenTelemetry collector and Jaeger for trace visualization. ```bash docker compose up ``` -------------------------------- ### Create New Phoenix Project Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice/README.md Generates a new Phoenix project without Ecto or HTML for a simplified setup. ```shell mix phx.new --no-ecto --no-html roll_dice ``` -------------------------------- ### Advanced Server Options in Main Setup Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Pass server-specific options, such as span relationship, through the main OpentelemetryGrpc.setup function. ```elixir OpentelemetryGrpc.setup(server: [span_relationship: :link]) ``` -------------------------------- ### Replace HTTPoison with OpentelemetryHTTPoison Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_httpoison/README.md Before and after example showing how to replace direct HTTPoison calls with OpentelemetryHTTPoison calls for instrumented requests. ```elixir # Before HTTPoison.get!(url, headers, opts) # After OpentelemetryHTTPoison.get!(url, headers, opts) ``` -------------------------------- ### Erlang Dependency Installation Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/otel_http/README.md Add otel_http to your Erlang project's dependencies. ```erlang {deps, [ {otel_http, "> 0.2"} ]} ``` -------------------------------- ### Client-Only OpenTelemetry gRPC Setup Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Configure OpenTelemetry gRPC to instrument only gRPC client calls. ```elixir OpentelemetryGrpc.Client.setup() ``` -------------------------------- ### Server-Only OpenTelemetry gRPC Setup Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Configure OpenTelemetry gRPC to instrument only gRPC server requests. ```elixir OpentelemetryGrpc.Server.setup() ``` -------------------------------- ### Create Counter Instrument on Application Boot Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Initializes the roll counter instrument using the `?create_counter` macro when the application starts. ```erlang start(_StartType, _StartArgs) -> create_instruments(), roll_dice_sup:start_link(). create_instruments() -> ?create_counter(?ROLL_COUNTER, #{description => <<"The number of rolls by roll value.">>, unit => '1'}). ``` -------------------------------- ### Broadway Setup with Trace Propagation Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_broadway/README.md Configure Broadway instrumentation to establish trace links by extracting context from message headers. Use `:link` for general distributed tracing or `:child` for single-message processors when a parent context should be continued. ```elixir def start(_type, _args) do OpentelemetryBroadway.setup(span_relationship: :link) Supervisor.start_link(...) end ``` -------------------------------- ### Infer Route for GET Request Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_httpoison/README.md Demonstrates inferring the HTTP route for a GET request without explicit service name configuration. ```elixir OpentelemetryHTTPoison.get!( "https://www.example.com/user/list", [], ot_span_name: "list example users", ot_attributes: [{"example.language", "en"}], ot_resource_route: :infer ) ``` -------------------------------- ### Configure Service Name and Infer Route Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_httpoison/README.md Configures the service name and demonstrates inferring the HTTP route for a GET request. ```elixir config :opentelemetry_httpoison, ot_attributes: [{"service.name", "users"}] OpentelemetryHTTPoison.get!( "https://www.example.com/user/list", [], ot_span_name: "list example users", ot_attributes: [{"example.language", "en"}], ot_resource_route: :infer ) ``` -------------------------------- ### Elixir Dependency Installation Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/otel_http/README.md Add otel_http to your Elixir project's dependencies. ```elixir def deps do [ {:otel_http, "> 0.2"} ] end ``` -------------------------------- ### Setup Cowboy Telemetry Handler Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_cowboy/README.md Call this function in your application behavior before the top-level supervisor starts to enable OpenTelemetry span generation from Cowboy events. ```erlang opentelemetry_cowboy:setup() ``` -------------------------------- ### Starting a Span with ?with_span Macro Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Use the `?with_span` macro to start a new span named 'dice_roll' and execute code within its context. ```erlang -spec do_roll() -> integer(). do_roll() -> ?with_span(dice_roll, #{}, fun(_) -> Roll = rand:uniform(6), ?set_attribute('roll.value', Roll), Roll end). ``` -------------------------------- ### Add OpentelemetryRedix to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_redix/README.md Install the opentelemetry_redix package by adding it to your project's dependencies in mix.exs. ```elixir def deps do [ {:opentelemetry_redix, "~> 0.2"} ] end ``` -------------------------------- ### Install opentelemetry_req Dependency Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_req/README.md Add the opentelemetry_req package as a project dependency in your Erlang application's `deps` function. ```elixir def deps do [ {:opentelemetry_req, ">~ 1.0.0-beta.1"} ] end ``` -------------------------------- ### Update Span Name with ?update_name Macro Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Use the ?update_name macro from opentelemetry_api to set a descriptive Span name after it has started. This is useful when Elli's lack of a router prevents automatic descriptive naming. ```erlang handle(Req, Args) -> handle(Req#req.path, Req, Args). handle([<<"hello">>, Who], Req, _Args) -> ?update_name(<<"/hello/{who}">>), {ok, [], <<"Hello ", Who/binary>>}. ``` -------------------------------- ### Define API Route for Dice Roll Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice/README.md Adds a GET route to the '/api/rolldice' endpoint within the '/api' scope, mapping it to the 'roll' action in the DiceController. ```elixir scope "/api", DiceGameWeb do pipe_through :api get "/rolldice", DiceController, :roll end ``` -------------------------------- ### Run the Erlang Project Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Execute the Erlang project using rebar3, setting environment variables for the OTLP exporter. ```bash OTEL_EXPORTER_OTLP_PROTOCOL=grpc OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 rebar3 shell ``` -------------------------------- ### Run Common Test Suite Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Execute the Common Test suite to verify the Elli server and exported Spans. This requires rebar3. ```bash $ rebar3 ct ``` -------------------------------- ### Erlang Project Dependencies and Boot Order Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Configure rebar.config to include OpenTelemetry dependencies and define the application boot order for the shell and release. ```erlang {shell, [{apps, [opentelemetry_exporter, opentelemetry_experimental, opentelemetry, recon, roll_dice]}, {config, "config/sys.config"}]}. {relx, [{release, {roll_dice, "0.1.0"}, [opentelemetry_exporter, opentelemetry_experimental, opentelemetry, recon, roll_dice, sasl] }]}. ``` -------------------------------- ### Configure Metrics Reader in sys.config Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md This snippet shows how to configure the OpenTelemetry experimental SDK in `sys.config` to export metrics every second to the console. ```erlang { opentelemetry_experimental, [{"readers", [#{module => otel_metric_reader, config => #{export_interval_ms => 1000, exporter => {otel_metric_exporter_console, #{}}}}]}]} ``` -------------------------------- ### Insert Job with Trace Linking Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_oban/README.md Replace Oban.insert/2 with OpentelemetryOban.insert/2 to create a span when a job is created and link traces together. ```elixir %{id: 1, in_the: "business", of_doing: "business"} |> MyApp.Business.new() |> OpentelemetryOban.insert() ``` -------------------------------- ### OpenTelemetry SDK Configuration in sys.config Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Configure the OpenTelemetry SDK in sys.config to use the batch span processor and OTLP exporter. ```erlang {opentelemetry, [{span_processor, batch}, {traces_exporter, otlp} ]}, ``` -------------------------------- ### Use Custom Mylib Attributes at Runtime Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/reference/custom-span-attributes.md Demonstrates how to use the custom attribute functions when building an attributes map or setting attributes on a span. This ensures consistent attribute usage. ```elixir alias OpentelemetryMylib.MylibAttributes attributes = %{ MylibAttributes.mylib_queue_name() => queue_name, MylibAttributes.mylib_retry_count() => retries } ``` -------------------------------- ### Add OpentelemetryPhoenix Dependency Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/README.md Add the opentelemetry_phoenix library to your project's dependencies in `mix.exs`. Ensure you use a compatible version. ```elixir def deps do [ {:opentelemetry_phoenix, "~> 2.0.0-rc.2"} ] end ``` -------------------------------- ### Configure Tesla Client with OpenTelemetry Middleware Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_tesla/README.md Configure your Tesla client to use the `Tesla.Middleware.OpenTelemetry` middleware. Ensure it is placed before `Tesla.Middleware.PathParams` to correctly capture parameterized paths in span names. ```elixir client = Tesla.client([ {Tesla.Middleware.OpenTelemetry, opt_in_attrs: [URLAttributes.url_template()]}, Tesla.Middleware.PathParams ]) Tesla.get(client, "/users/:id", opts: [path_params: [id: "123"]]) ``` -------------------------------- ### Add OpentelemetryXandra to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_xandra/README.md Include `opentelemetry_xandra` in your project's dependencies within the `mix.exs` file to enable integration. ```elixir defp deps do [ # Other opentelemetry_* deps…, {:opentelemetry_xandra, "~> 0.1"} ] end ``` -------------------------------- ### Configure Elli Middleware Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Place oc_elli_middleware as the first handler module when using elli_middleware. ```erlang [{callback, elli_middleware}, {callback_args, [{mods, [{otel_elli_middleware, []}, {, []}]}]}] ``` -------------------------------- ### Manual Finch Instrumentation with Context Propagation Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_finch/README.md Use this manual instrumentation pattern when context propagation in HTTP headers is required, as automatic instrumentation does not support it. Ensure OpenTelemetry.Tracer is required and aliased. ```elixir require OpenTelemetry.Tracer, as: Tracer Tracer.with_span "HTTP #{url}" do headers = :otel_propagator_text_map.inject([]) with request <- Finch.build(:get, url, headers), {:ok, response} <- Finch.request(request, HttpFinch) do Tracer.set_attributes([ {"http.url", url}, {"http.method", request.method}, {"http.status_code", response.status}]) {:ok, response} else {:error, %{__exception__: true} = error} -> Tracer.set_status(:error, Exception.message(error)) {:error, error} end end ``` -------------------------------- ### Add opentelemetry_grpc to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Add the opentelemetry_grpc library to your project's dependencies in the mix.exs file. ```elixir def deps do [ {:opentelemetry_grpc, "~> 1.0"} ] end ``` -------------------------------- ### Configure Extra Applications for Hammer Backend Redis Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_redix/README.md When using libraries like hammer_backend_redis that manage Redix connections internally, ensure opentelemetry_redix is listed in extra_applications to guarantee proper startup order. ```elixir def application do [ extra_applications: [:opentelemetry_redix, :hammer_backend_redis] ] end ``` -------------------------------- ### Add OpentelemetryCommanded to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_commanded/README.md Add the opentelemetry_commanded package to your project's dependencies in mix.exs. ```elixir def deps do [ {:opentelemetry_commanded, "~> 0.1.0"} ] end ``` -------------------------------- ### Add OpentelemetryFinch to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_finch/README.md Add the opentelemetry_finch package to your project's dependencies in mix.exs. ```elixir def deps do [ {:opentelemetry_finch, "~> 0.3"} ] end ``` -------------------------------- ### Add OpentelemetryEcto to Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_ecto/README.md Add the opentelemetry_ecto package to your project's dependencies in the `mix.exs` file. ```elixir def deps do [ {:opentelemetry_ecto, "~> 1.0"} ] end ``` -------------------------------- ### Exclude Paths from Tracing via OS Environment Variable Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Set the OTEL_ELLI_EXCLUDED_URLS OS environment variable as a comma-separated list of paths to exclude from tracing. Note that commas within URLs must be percent encoded. ```bash export OTEL_ELLI_EXCLUDED_URLS="/health,/metrics,/api/v1/status" ``` -------------------------------- ### Record Exception and Set Status (Erlang) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Demonstrates recording an exception and setting the span status to error in Erlang using `otel_span:record_exception/5` and `opentelemetry:status/2`. ```erlang otel_span:record_exception(ctx, kind, reason, stacktrace, []), opentelemetry:status(?OTEL_STATUS_ERROR, Message) ``` -------------------------------- ### Add OpentelemetryOban to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_oban/README.md Add the opentelemetry_oban package to your project's dependencies in mix.exs. ```elixir def deps do [ {:opentelemetry_oban, "~> 1.0"} ] end ``` -------------------------------- ### Set Fixed HTTP Route Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_httpoison/README.md Demonstrates setting a fixed string value for the HTTP route attribute. ```elixir OpentelemetryHTTPoison.get!( "https://www.example.com/user/list", [], ot_resource_route: "my secret path" ) ``` -------------------------------- ### Add opentelemetry_xray to mix.exs Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/opentelemetry_aws_xray/README.md Add the opentelemetry_xray dependency to your Elixir project's mix.exs file. ```elixir def deps do [ {:opentelemetry_xray, "~> 0.1"} ] end ``` -------------------------------- ### Elli Middleware Configuration for OpenTelemetry Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Configure Elli middleware in Erlang to integrate `otel_elli_middleware` for request tracing. ```erlang ElliOpts = [{callback, elli_middleware}, {callback_args, [{mods, [{otel_elli_middleware, []}, {roll_dice_handler, []}]}]}, {port, Port}], ChildSpecs = [#{id => roll_dice_http, start => {elli, start_link, [ ElliOpts]}, restart => permanent, shutdown => 5000, type => worker, modules => [roll_dice_handler]}], ``` -------------------------------- ### Add Opentelemetry_tesla Dependency Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_tesla/README.md Add the opentelemetry_tesla package to your project's dependencies in `deps.ex`. ```elixir def deps do [ {:opentelemetry_tesla, "~> 3.0"} ] end ``` -------------------------------- ### Handle :telemetry Exception Event (Empty Status Description) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md An alternative for handling `:telemetry` exception events where an empty status description is acceptable, as used in `opentelemetry_phoenix` when the event already carries sufficient detail. ```elixir OpenTelemetry.Span.set_status(ctx, OpenTelemetry.status(:error, "")) ``` -------------------------------- ### Client Channel Configuration Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpcbox/README.md Set up a gRPC client channel with the OpenTelemetry interceptor for outgoing unary calls. This configuration is typically placed in `sys.config`. ```erlang {client, #{channels => [{default_channel, [{http, "localhost", 8080, []}], #{unary_interceptor => fun otel_grpcbox_interceptor:unary_client/7}}]}} ``` -------------------------------- ### Add OpentelemetryNebulex Dependency Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_nebulex/README.md Add the `opentelemetry_nebulex` package to your project's dependencies in `mix.exs`. ```elixir def deps do [ {:opentelemetry_nebulex, "~> 0.1.0"} ] end ``` -------------------------------- ### Add opentelemetry_elli to Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Include opentelemetry_elli in your project's dependencies. ```erlang {deps, [opentelemetry_elli]}. ``` -------------------------------- ### Add opentelemetry_broadway Dependency Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_broadway/README.md Add the opentelemetry_broadway library to your project's dependencies in `deps.ex`. ```elixir defp deps do [ {:opentelemetry_broadway, "~> 0.3"} ] end ``` -------------------------------- ### Add OpentelemetryDataloader to Mix Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_dataloader/README.md Add the opentelemetry_dataloader package to your project's dependencies in mix.exs. ```elixir def deps do [ {:opentelemetry_dataloader, "~> 0.1"} ] end ``` -------------------------------- ### Configure Plug.Telemetry in Phoenix Endpoint Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/README.md Ensure your Phoenix endpoint uses `Plug.Telemetry` with the correct `event_prefix` to enable tracing. This is required for `OpentelemetryPhoenix` to capture endpoint calls. ```elixir defmodule MyApp.Endpoint do use Phoenix.Endpoint, otp_app: :my_app ... plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] ... end ``` -------------------------------- ### Add OpentelemetryBandit Dependency Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_bandit/README.md Add the opentelemetry_bandit package to your project's dependencies in your `deps` function. ```elixir def deps do [ {:opentelemetry_bandit, ">~ 0.1.4"} ] end ``` -------------------------------- ### Configure Server Name for HTTP Attributes Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Set the server_name attribute in sys.config for OpenTelemetry HTTP semantic conventions. ```erlang {opentelemetry_elli, [{server_name, <<"my-http-server">>}]}. ``` -------------------------------- ### Add opentelemetry_xray to rebar.config Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/opentelemetry_aws_xray/README.md Add the opentelemetry_xray dependency to your Erlang project's rebar.config file. ```erlang {deps, [opentelemetry_xray]}. ``` -------------------------------- ### Configure Custom Route Inference Function Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_httpoison/README.md Configures a custom function for inferring the HTTP route and demonstrates its usage. ```elixir config :opentelemetry_httpoison, infer_route: fn %HTTPoison.Request{} = request -> URI.parse(request.url).path end OpentelemetryHTTPoison.get!( "https://www.example.com/user/list", [], ot_resource_route: :infer ) ``` -------------------------------- ### Configure Server Span Relationship Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Control span relationships for server instrumentation. Use :child for default parent-child spans, :link for span links in detached processing, or :none to disable context propagation. ```elixir # Create child spans (default) - spans should be part of the same trace OpentelemetryGrpc.Server.setup(span_relationship: :child) # Create span links instead of parent-child relationships - use for fire-and-forget or detached async processing OpentelemetryGrpc.Server.setup(span_relationship: :link) # Disable context propagation entirely - useful for isolated traces OpentelemetryGrpc.Server.setup(span_relationship: :none) ``` -------------------------------- ### Ignore HTTP Route Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_httpoison/README.md Demonstrates ignoring the HTTP route attribute by setting it to :ignore. ```elixir OpentelemetryHTTPoison.get!( "https://www.example.com/user/list", [], ot_resource_route: :ignore ) ``` -------------------------------- ### Add opentelemetry_cowboy Dependency (Erlang) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_cowboy/README.md Add the opentelemetry_cowboy package to your Erlang project's dependencies. ```erlang {deps, [ {opentelemetry_cowboy, "~> 1.0"} ]} ``` -------------------------------- ### Server Interceptor Configuration Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpcbox/README.md Configure the gRPCbox interceptor for server-side unary calls. This should be used when defining your service's interceptors. ```erlang { service_protos => [route_guide_pb], unary_interceptor => {otel_grpcbox_interceptor, unary} } ``` -------------------------------- ### Add OpentelemetryCommanded Middleware to Commanded Router Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_commanded/README.md Include OpentelemetryCommanded.Middleware in your Commanded router configuration to enable span creation for commands and events. ```elixir middleware OpentelemetryCommanded.Middleware ``` -------------------------------- ### Server Chain Interceptor Configuration Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpcbox/README.md Integrate the OpenTelemetry interceptor into an existing gRPCbox chain for server-side unary calls. This allows combining multiple interceptors. ```erlang { service_protos => [route_guide_pb], unary_interceptor => grpcbox_chain_interceptor:unary([..., fun otel_grpcbox_interceptor:unary/4, ...]) } ``` -------------------------------- ### Add opentelemetry_telemetry to Elixir Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/opentelemetry_telemetry/README.md Add the opentelemetry_telemetry package to your Elixir project's dependencies. ```elixir def deps do [ {:opentelemetry_telemetry, "~> 1.0"} ] end ``` -------------------------------- ### Add opentelemetry_telemetry to Erlang Dependencies Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/opentelemetry_telemetry/README.md Add the opentelemetry_telemetry package to your Erlang project's dependencies. ```erlang {deps, [ {opentelemetry_telemetry, "~> 1.0"} ]}. ``` -------------------------------- ### Add opentelemetry_cowboy Dependency (Elixir) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_cowboy/README.md Add the opentelemetry_cowboy package to your Elixir project's dependencies. ```elixir def deps do [ {:opentelemetry_cowboy, "~> 1.0"} ] end ``` -------------------------------- ### Configure OpenTelemetry with X-Ray Id Generator in Erlang Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/opentelemetry_aws_xray/README.md Configure OpenTelemetry to use the X-Ray Id Generator in your Erlang application. ```erlang [ {opentelemetry, [{id_generator, otel_aws_xray_id_generator}]} ]. ``` -------------------------------- ### Define Custom Mylib Attributes Module Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/reference/custom-span-attributes.md Defines custom span attributes for the Mylib instrumentation package. Use this module to list all non-SemConv attributes the package can produce, ensuring discoverability and compile-time safety. ```elixir defmodule OpentelemetryMylib.MylibAttributes do @moduledoc """ OpenTelemetry span attributes specific to the Mylib instrumentation. These attributes are not part of the OpenTelemetry Semantic Conventions. """ @doc """ The name of the Mylib queue being processed. """ @spec mylib_queue_name() :: :"mylib.queue_name" def mylib_queue_name, do: :"mylib.queue_name" @doc """ Number of times the operation was retried. """ @spec mylib_retry_count() :: :"mylib.retry_count" def mylib_retry_count, do: :"mylib.retry_count" end ``` -------------------------------- ### Roll a Die via HTTP Request Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Send an HTTP request to the application's endpoint to roll a die and receive the result. ```bash curl localhost:3000/rolldice ``` -------------------------------- ### Erlang: Record Exception Function Signatures Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/reference/recording-exceptions.md The Erlang API for recording exceptions provides two function signatures: `:otel_span.record_exception/5` and `:otel_span.record_exception/6`. These functions accept a context, OTP exception class, reason, stacktrace, and optional message and attributes. They produce an exception event with structured type and stacktrace information. ```erlang :otel_span.record_exception(Ctx, Class, Reason, Stacktrace, Attributes) ``` ```erlang :otel_span.record_exception(Ctx, Class, Reason, Stacktrace, Message, Attributes) ``` -------------------------------- ### Handle :telemetry Exception Event (Any Term Reason) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Use this when the `reason` from a `:telemetry` event may be any term, not necessarily an Elixir exception struct. It records the exception using `:otel_span` and sets the span status to error. ```elixir ctx = OpentelemetryTelemetry.set_current_telemetry_span(@tracer_id, meta) :otel_span.record_exception(ctx, kind, reason, stacktrace, []) OpenTelemetry.Span.set_status(ctx, OpenTelemetry.status(:error, Exception.format_banner(kind, reason, stacktrace))) ``` -------------------------------- ### Configure OpenTelemetry with X-Ray Id Generator in Elixir Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/utilities/opentelemetry_aws_xray/README.md Configure OpenTelemetry to use the X-Ray Id Generator in your Elixir application. ```elixir config :opentelemetry, id_generator: :otel_aws_xray_id_generator ``` -------------------------------- ### Dice Controller with OpenTelemetry Span Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice/README.md Implements the DiceController with a 'roll' function that generates a random number, emits an OpenTelemetry span named 'roll_dice', sets the roll value as a span attribute, and returns the roll as a string. ```elixir defmodule DiceGameWeb.DiceController do use DiceGameWeb, :controller require OpenTelemetry.Tracer, as: Tracer def roll(conn, _params) do send_resp(conn, 200, roll_dice()) end defp roll_dice do Tracer.with_span("roll_dice") do roll = Enum.random(1..6) Tracer.set_attribute("roll.value", roll) to_string(roll) end end end ``` -------------------------------- ### Add Context Propagator Interceptor to gRPC Channel Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_grpc/README.md Add the OpentelemetryGrpc.ContextPropagatorInterceptor to your gRPC channel configuration to ensure proper trace context propagation in client requests. This interceptor should typically be the first in the list. ```elixir {:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [OpentelemetryGrpc.ContextPropagatorInterceptor]) # Use the channel for your gRPC calls MyService.Stub.my_method(channel, request) ``` -------------------------------- ### Exclude Paths from Tracing via sys.config Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_elli/README.md Configure excluded paths in sys.config to prevent tracing specific URLs like health checks or metrics endpoints. ```erlang {opentelemetry_elli, [{excluded_paths, ["/health", "/metrics"]}]} ``` -------------------------------- ### Record and Set Status for Non-Telemetry Failure Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Records an exception event and sets the span status to error for errors directly obtained from `{:error, reason}` returns or `rescue`/`catch` blocks, using a helper to format the reason. ```elixir OpenTelemetry.Span.record_exception(ctx, exception, stacktrace, []) OpenTelemetry.Span.set_status(span, OpenTelemetry.status(:error, format_error(reason))) ``` -------------------------------- ### Helper to Format Non-Telemetry Errors Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md A helper function to format errors from `{:error, reason}` returns or `rescue`/`catch` blocks for use in OpenTelemetry span status descriptions. ```elixir defp format_error(%{__exception__: true} = exception), do: Exception.message(exception) defp format_error(reason), do: inspect(reason) ``` -------------------------------- ### Record Erlang Exception Kind Attribute Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Adds the `"erlang.exception.kind"` attribute to the span, recording the OTP exception class. This is optional and useful when consumers need the class as a structured field separate from the exception event. ```elixir OpenTelemetry.Span.set_attribute(ctx, : ``` -------------------------------- ### Handle :telemetry Exception Event (Elixir Exception Struct) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Use this when the `reason` from a `:telemetry` event is likely an Elixir exception struct. It normalizes the exception and records it with structured fields, then sets the span status to error. ```elixir ctx = OpentelemetryTelemetry.set_current_telemetry_span(@tracer_id, meta) exception = Exception.normalize(kind, reason, stacktrace) OpenTelemetry.Span.record_exception(ctx, exception, stacktrace, []) OpenTelemetry.Span.set_status(ctx, OpenTelemetry.status(:error, Exception.format_banner(kind, reason, stacktrace))) OpentelemetryTelemetry.end_telemetry_span(@tracer_id, meta) ``` -------------------------------- ### Elixir: Record Exception Function Signature Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/reference/recording-exceptions.md The `OpenTelemetry.Span.record_exception/4` function in Elixir is used to record an exception event on a span. It requires a span context, an exception struct, and optionally a stacktrace and attributes. The exception struct must have `__exception__: true`. ```elixir OpenTelemetry.Span.record_exception(span_ctx, exception, stacktrace \ nil, attributes \ []) ``` -------------------------------- ### Erlang: Exception Normalization Function Signature Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/reference/recording-exceptions.md The `Exception.normalize/3` function in Erlang maps OTP `kind`/`reason` pairs to an Elixir exception struct. The resulting struct can be used with `Exception.message/1` and `OpenTelemetry.Span.record_exception/4`. ```elixir Exception.normalize(kind, reason, stacktrace) :: Exception.t() | term() ``` -------------------------------- ### Define Roll Counter Instrument Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Defines a constant for the roll counter instrument name, used for referencing it throughout the code. ```erlang -define(ROLL_COUNTER, roll_counter). ``` -------------------------------- ### Setting Span Attributes with ?set_attribute Macro Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Use the `?set_attribute` macro to add attributes, such as the dice roll value, to the currently active span. ```erlang ?set_attribute('roll.value', Roll) ``` -------------------------------- ### Set error.type Attribute (HTTP Status) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Sets the `error.type` attribute on the span with an HTTP status code. This attribute summarizes the failure class for dashboards and should be low-cardinality. ```elixir # HTTP status OpenTelemetry.Span.set_attribute(ctx, ErrorAttributes.error_type(), to_string(status_code)) ``` -------------------------------- ### Elixir: Error Type Attribute Key Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/reference/recording-exceptions.md The `OpenTelemetry.SemConv.ErrorAttributes.error_type/0` function returns the key for the `error.type` span attribute. This attribute is used for stable SemConv classification of errors. ```elixir OpenTelemetry.SemConv.ErrorAttributes.error_type/0 ``` -------------------------------- ### Set error.type Attribute (Unknown/Opaque) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Sets the `error.type` attribute on the span to a generic 'other' value when the failure is unknown or opaque. This attribute summarizes the failure class for dashboards and should be low-cardinality. ```elixir # Unknown / opaque OpenTelemetry.Span.set_attribute(ctx, ErrorAttributes.error_type(), ErrorAttributes.error_type_values().other) ``` -------------------------------- ### Updating Span Name in roll_dice_handler Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Use the `?update_name` macro within `roll_dice_handler` to set a more descriptive name for the current span. ```erlang handle('GET', [<<"rolldice">>], _Req) -> ?update_name(<<"GET /rolldice">>), ... handle('GET', [], _Req) -> ?update_name(<<"GET /">>), ``` -------------------------------- ### Set error.type Attribute (Named Exception) Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/docs/how-to/record-exceptions.md Sets the `error.type` attribute on the span with the name of the exception struct. This attribute summarizes the failure class for dashboards and should be low-cardinality. ```elixir # Named exception OpenTelemetry.Span.set_attribute(ctx, ErrorAttributes.error_type(), inspect(exception.__struct__)) ``` -------------------------------- ### Increment Counter and Set Attribute in Handler Source: https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/examples/roll_dice_elli/README.md Increments the roll counter and sets the 'roll.value' attribute within a span when a dice roll occurs. ```erlang -spec do_roll() -> integer(). do_roll() -> ?with_span(dice_roll, #{}, fun(_) -> Roll = rand:uniform(6), ?set_attribute('roll.value', Roll), ?counter_add(?ROLL_COUNTER, 1, #{'roll.value' => Roll}), Roll end). ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.