Skip to content

Commit

Permalink
Merge pull request #1349 from splunk/repo-sync
Browse files Browse the repository at this point in the history
Pulling refs/heads/main into main
  • Loading branch information
theletterf committed May 17, 2024
2 parents 496d9c3 + 6b1b6bd commit b138a65
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _splunk-otel-azure:
.. _splunk-otel-dotnet-azure:

***********************************************************************
Instrument .NET Azure functions for Splunk Observability Cloud
Expand All @@ -11,15 +11,15 @@ By instrumenting .NET Azure functions you can send spans to Splunk Observability

To instrument your .NET Azure function with OpenTelemetry to send telemetry to Splunk Observability Cloud, follow these high-level steps:

- :ref:`azure-functions-step-1`
- :ref:`azure-functions-step-2`
- :ref:`azure-functions-step-3`
- :ref:`azure-functions-step-4`
- :ref:`azure-functions-step-5`
- :ref:`azure-functions-dotnet-step-1`
- :ref:`azure-functions-dotnet-step-2`
- :ref:`azure-functions-dotnet-step-3`
- :ref:`azure-functions-dotnet-step-4`
- :ref:`azure-functions-dotnet-step-5`

.. note:: The SignalFx C# Azure Function wrapper is deprecated. Use the following method instrument your Azure functions.

.. _azure-functions-step-1:
.. _azure-functions-dotnet-step-1:

Define the environment variables
=================================================
Expand All @@ -46,7 +46,7 @@ Set the required environment variables in your function's settings:

#. Add any other settings you might need.

.. _azure-functions-step-2:
.. _azure-functions-dotnet-step-2:

Add the required libraries using NuGet
=================================================
Expand Down Expand Up @@ -78,7 +78,7 @@ In-process function

.. note:: Due to runtime dependencies, only the indicated versions are guaranteed to work when instrumenting in-process functions.

.. _azure-functions-step-3:
.. _azure-functions-dotnet-step-3:

Initialize OpenTelemetry in the code
=================================================
Expand Down Expand Up @@ -209,7 +209,7 @@ Define a startup function and decorate the assembly with it. The startup functio
}
}
.. _azure-functions-step-4:
.. _azure-functions-dotnet-step-4:
Instrument the code to send spans
=================================================
Expand Down Expand Up @@ -297,7 +297,7 @@ The following example shows how to retrieve ``faas`` attributes:
}
}
.. _azure-functions-step-5:
.. _azure-functions-dotnet-step-5:
Check that data is coming in
=========================================
Expand Down
120 changes: 120 additions & 0 deletions gdi/get-data-in/serverless/azure/instrument-azure-functions-nodejs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
.. _splunk-otel-js-azure:

***********************************************************************
Instrument NodeJS Azure functions for Splunk Observability Cloud
***********************************************************************

.. meta::
:description: Learn how to instrument your NodeJS Azure functions to export spans to Splunk Observability Cloud.

By instrumenting NodeJS Azure functions you can send spans to Splunk Observability Cloud every time your functions run.

To instrument your NodeJS Azure function with OpenTelemetry to send telemetry to Splunk Observability Cloud, follow these high-level steps:

- :ref:`azure-functions-js-step-1`
- :ref:`azure-functions-js-step-2`
- :ref:`azure-functions-js-step-3`
- :ref:`azure-functions-js-step-4`

.. _azure-functions-js-step-1:

Define the environment variables
=================================================

Set the required environment variables in your function's settings:

#. Select your function in Function App.

#. Go to :guilabel:`Settings`, then :guilabel:`Configuration`.

#. Select :strong:`New application setting` to add the following settings:

.. list-table::
:header-rows: 1
:width: 100%
:widths: 40 60

* - Name
- Value
* - ``SPLUNK_ACCESS_TOKEN``
- Your Splunk access token. To obtain an access token, see :ref:`admin-api-access-tokens`.
* - ``SPLUNK_REALM``
- Your Splunk Observability Cloud realm, for example ``us0``. To find your Splunk realm, see :ref:`Note about realms <about-realms>`.
* - ``NODE_OPTIONS``
- Specify NodeJS options to preload instrumentation module: ``-r @splunk/otel/instrument``

#. Add any other settings you might need.

.. _azure-functions-js-step-2:

Add the required libraries using NPM
=================================================

Install the latest version of ``@splunk/otel`` and match the ``@opentelemetry/api`` version used in the ``@splunk/otel`` (see ``package.json``).

- :new-page:`@splunk/otel <https://www.npmjs.com/package/@splunk/otel>`
- :new-page:`@opentelemetry/api <https://www.npmjs.com/package/@opentelemetry/api>`

.. _azure-functions-js-step-3:

Instrument the code to send spans
=================================================

Next, instrument your code using OpenTelemetry. Use the following examples as a starting point to instrument your code. See :new-page:`https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings <https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings>` in Microsoft Azure documentation for steps to add environment variables to an Azure function.

The following example shows how to instrument a function using the ``instrumentationWrapper`` helper:

.. code-block:: ts
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";
import { trace, Span } from "@opentelemetry/api";
const tracer = trace.getTracer('splunk-example-azure', '0.1.0');
export async function myhttptrigger(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
context.log(`Http function processed request for url "${request.url}"`);
const response = // run your function logic here.
return { body: `Hello, ${response}!` };
};
// Universal wrapper method that helps to generate root span for Azure Functions
export const instrumentationWrapper = <T extends (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>>(func: T) =>
async (...args: Parameters<T>): Promise<Awaited<ReturnType<T>>> => {
let result: Promise<Awaited<ReturnType<T>>>;
let functionName = func.name;
await tracer.startActiveSpan(functionName, async (span: Span) => {
// setup custom attributes for root span, specific to your Azure Functions.
span.setAttribute("foo", 1);
span.setAttribute("bar", "Hello World!");
span.setAttribute("baz", [1, 2, 3])
result = await func(...args)
span.end();
});
return result;
}
app.http('myhttptrigger', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: instrumentationWrapper(myhttptrigger)
});
.. _azure-functions-js-step-4:

Check that data is coming in
=========================================

Run your function and search for its spans in Splunk APM. See :ref:`span-search` for more information.

Troubleshooting
======================

.. include:: /_includes/troubleshooting-components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Instrument serverless functions for Splunk Observability Cloud
:hidden:

Instrument AWS Lambda functions <aws/splunk-otel-lambda-layer.rst>
Instrument .NET Azure functions <azure/instrument-azure-functions.rst>
Instrument Azure .NET functions <azure/instrument-azure-functions-dotnet.rst>
Instrument Azure Node.js functions <azure/instrument-azure-functions-nodejs.rst>

Instrument your serverless functions to send metrics and traces to Splunk Observability Cloud, so that you can explore your function data using dashboards, set up alerts, and more.

You can instrument functions on each of the following cloud platforms:

- :ref:`AWS <splunk-otel-lambda-layer>`
- :ref:`.NET Azure <splunk-otel-azure>`
- :ref:`Azure .NET <splunk-otel-dotnet-azure>`
- :ref:`Azure Node.js <splunk-otel-js-azure>`
3 changes: 3 additions & 0 deletions gdi/opentelemetry/discovery-mode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@ Automatic discovery supports the following host services and applications:
* - Redis
- Redis receiver. See :ref:`redis-receiver`.

* - MongoDB
- MongoDB receiver. See :ref:`mongodb-receiver`



0 comments on commit b138a65

Please sign in to comment.