|
| 1 | +.. _instrument-erlang: |
| 2 | + |
| 3 | +************************************************************************* |
| 4 | +Instrument your Erlang application for Splunk Observability Cloud |
| 5 | +************************************************************************* |
| 6 | + |
| 7 | +.. meta:: |
| 8 | + :description: Learn how to instrument your Erlang application using the OpenTelemetry instrumentation for Erlang and send your application traces to Splunk Observability Cloud. |
| 9 | + |
| 10 | +You can send traces from your Erlang applications using the OpenTelemetry instrumentation for Erlang. To get started, follow these instructions. |
| 11 | + |
| 12 | +.. _erlang-add-dependencies: |
| 13 | + |
| 14 | +1. Add the required dependencies or packages |
| 15 | +================================================== |
| 16 | + |
| 17 | +To instrument your application for Splunk Observability Cloud, you need to generate traces and spans that follow the OpenTelemetry format and semantic conventions. Add the required OpenTelemetry dependencies to your project, including gRPC communication libraries for communicating with the Splunk OpenTelemetry Collector. |
| 18 | + |
| 19 | +Add the OpenTelemetry packages to the list of dependencies in your rebar.config file: |
| 20 | + |
| 21 | +.. code-block:: Erlang |
| 22 | +
|
| 23 | + %% rebar.config file |
| 24 | +
|
| 25 | + {deps, [opentelemetry_api |
| 26 | + opentelemetry, |
| 27 | + opentelemetry_exporter]}. |
| 28 | +
|
| 29 | +You also must add them to the ``Applications`` section, together with gRPC libraries: |
| 30 | + |
| 31 | +.. code-block:: erlang |
| 32 | +
|
| 33 | + %% app.src file |
| 34 | +
|
| 35 | + {applications, |
| 36 | + [kernel, |
| 37 | + stdlib, |
| 38 | + opentelemetry_api, |
| 39 | + opentelemetry, |
| 40 | + opentelemetry_exporter |
| 41 | + ]}, |
| 42 | +
|
| 43 | +.. _erlang-init-tracer: |
| 44 | + |
| 45 | +2. Initialize the OpenTelemetry tracer |
| 46 | +================================================= |
| 47 | + |
| 48 | +In your application code, initialize the OpenTelemetry library and tracer like in the following example: |
| 49 | + |
| 50 | +.. code-block:: erlang |
| 51 | +
|
| 52 | + -module(otel_getting_started). |
| 53 | +
|
| 54 | + -export([hello/0]). |
| 55 | +
|
| 56 | + -include_lib("opentelemetry_api/include/otel_tracer.hrl"). |
| 57 | +
|
| 58 | +Erlang automatically initializes the tracer. |
| 59 | + |
| 60 | +.. _erlang-generate-spans: |
| 61 | + |
| 62 | +3. Generate spans for your application |
| 63 | +================================================== |
| 64 | + |
| 65 | +In your Erlang application code, create spans for the operations you want to track. |
| 66 | + |
| 67 | +The following example shows how to create spans that have attributes or tags: |
| 68 | + |
| 69 | +.. code-block:: erlang |
| 70 | +
|
| 71 | + hello() -> |
| 72 | + %% start an active span and run a local function |
| 73 | + ?with_span(<<"operation">>, #{}, fun nice_operation/1). |
| 74 | +
|
| 75 | + nice_operation(_SpanCtx) -> |
| 76 | + ?add_event(<<"Nice operation!">>, [{<<"bogons">>, 100}]), |
| 77 | + ?set_attributes([{another_key, <<"yes">>}]), |
| 78 | +
|
| 79 | + %% start an active span and run an anonymous function |
| 80 | + ?with_span(<<"Sub operation...">>, #{}, |
| 81 | + fun(_ChildSpanCtx) -> |
| 82 | + ?set_attributes([{lemons_key, <<"five">>}]), |
| 83 | + ?add_event(<<"Sub span event!">>, []) |
| 84 | + end). |
| 85 | +
|
| 86 | +.. _export-directly-to-olly-cloud-erlang: |
| 87 | +
|
| 88 | +Send data directly to Splunk Observability Cloud |
| 89 | +================================================== |
| 90 | +
|
| 91 | +By default, all telemetry goes to the local instance of the Splunk Distribution of OpenTelemetry Collector. |
| 92 | +
|
| 93 | +If you need to send data directly to Splunk Observability Cloud, set the following environment variables. When instrumenting Rust applications or services you might need to read the values of the environment variables first. |
| 94 | +
|
| 95 | +.. code-block:: shell |
| 96 | +
|
| 97 | + OTEL_EXPORTER_OTLP_PROTOCOL=grpc |
| 98 | + OTEL_EXPORTER_OTLP_TRACES_HEADERS=x-sf-token=<access_token> |
| 99 | + OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<realm>.signalfx.com |
| 100 | +
|
| 101 | +To obtain an access token, see :ref:`admin-api-access-tokens`. |
| 102 | +
|
| 103 | +To find your Splunk realm, see :ref:`Note about realms <about-realms>`. |
| 104 | +
|
| 105 | +.. note:: For more information on the ingest API endpoints, see :new-page:`Send APM traces <https://dev.splunk.com/observability/docs/apm/send_traces/>`. |
0 commit comments