To capture metrics, traces, and logs from our application, we’ve instrumented it with OpenTelemetry.
This required adding the following package to the requirements.txt file (which ultimately gets
installed with pip install):
splunk-opentelemetry==2.8.0
We also added the following to the Dockerfile used to build the
container image for this application, to install additional OpenTelemetry
instrumentation packages:
Finally, to enhance the traces and metrics collected with OpenTelemetry from this
LangChain application, we added additional Splunk instrumentation packages:
To instrument the application with OpenTelemetry, we also included several
environment variables in the Kubernetes manifest file used to deploy the application:
env:- name:OTEL_SERVICE_NAMEvalue:"llm-app"- name:OTEL_EXPORTER_OTLP_ENDPOINTvalue:"http://splunk-otel-collector-agent:4317"- name:OTEL_EXPORTER_OTLP_PROTOCOLvalue:"grpc"# filter out health check requests to the root URL- name:OTEL_PYTHON_EXCLUDED_URLSvalue:"^(https?://)?[^/]+(/)?$"- name:OTEL_PYTHON_DISABLED_INSTRUMENTATIONSvalue:"httpx,requests"- name:OTEL_INSTRUMENTATION_LANGCHAIN_CAPTURE_MESSAGE_CONTENTvalue:"true"- name:OTEL_LOGS_EXPORTERvalue:"otlp"- name:OTEL_PYTHON_LOG_CORRELATIONvalue:"true"- name:OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCEvalue:"delta"- name:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLEDvalue:"true"- name:OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTvalue:"true"- name:OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT_MODEvalue:"SPAN_AND_EVENT"- name:OTEL_INSTRUMENTATION_GENAI_EMITTERSvalue:"span_metric_event,splunk"- name:OTEL_INSTRUMENTATION_GENAI_EMITTERS_EVALUATIONvalue:"replace-category:SplunkEvaluationResults"- name:SPLUNK_PROFILER_ENABLEDvalue:"true"
Note that the OTEL_INSTRUMENTATION_LANGCHAIN_CAPTURE_MESSAGE_CONTENT and
OTEL_INSTRUMENTATION_GENAI_* environment variables are specific to the
LangChain instrumentation we’ve used.