Instrument the Application

Add the Splunk Agent Observability SDK and Configuration

3 minutes

First, add the Splunk Agent Observability SDK to the Python application. Then, add configuration so that the SDK knows where to send traces.

Exercise Add the SDK and configuration
1

Add the Splunk Agent Observability package

If you open the ~/workshop/healthcare-assistant/2-app-with-instrumentation/requirements.txt file, you’ll see that this package has already been added:

text
splunk-ao
2

Create a Kubernetes Secret

If you’re using the standalone version of Splunk Agent Observability for the workshop, run the following command to create a Kubernetes secret, which stores the Splunk Agent Observability API key:

bash
kubectl create secret generic splunk-ao-secret \
  --from-literal=SPLUNK_AO_API_KEY="$GALILEO_API_KEY"

Alternatively, if you’re using Splunk Agent Observability within Splunk Observability Cloud for this workshop, please use the following command instead:

bash
kubectl create secret generic splunk-ao-secret \
--from-literal=SPLUNK_AO_O11Y_TOKEN="$ACCESS_TOKEN"
3

Create a Config Map

If you’re using the standalone version of Splunk Agent Observability for the workshop, run the following command to create a Kubernetes config map, which the application will use to determine how to send traces to Splunk Agent Observability:

bash
kubectl create configmap splunk-ao-config \
  --from-literal=SPLUNK_AO_CONSOLE_URL="$GALILEO_CONSOLE_URL" \
  --from-literal=SPLUNK_AO_PROJECT="Splunk Agent Observability Workshop" \
  --from-literal=SPLUNK_AO_AGENT_STREAM="$INSTANCE"

Alternatively, if you’re using Splunk Agent Observability within Splunk Observability Cloud for this workshop, please use the following command instead:

bash
kubectl create configmap splunk-ao-config \
--from-literal=SPLUNK_AO_REALM="$REALM" \
--from-literal=SPLUNK_AO_PROJECT="Splunk Agent Observability Workshop" \
--from-literal=SPLUNK_AO_AGENT_STREAM="$INSTANCE"

Project and agent stream

SPLUNK_AO_PROJECT and SPLUNK_AO_AGENT_STREAM decide where your traces appear in the Splunk Agent Observability console. If you leave them blank, the SDK falls back to a project and agent stream both named default.

If you remove SPLUNK_AO_PROJECT and SPLUNK_AO_AGENT_STREAM from the splunk-ao-config config map, where will your traces show up?

Click here to see the answer
In a project named default and an agent stream named default. With those keys empty, setup_env.py exports empty SPLUNK_AO_PROJECT / SPLUNK_AO_AGENT_STREAM values, and the Splunk AO SDK falls back to its built-in default project and default agent stream.