diff --git a/.github/workflows/ansible.yml b/.github/workflows/ansible.yml index 79f7fe3ae7..3579220082 100644 --- a/.github/workflows/ansible.yml +++ b/.github/workflows/ansible.yml @@ -12,6 +12,7 @@ on: - 'deployments/ansible/galaxy.yml' branches: - main + - ansible-node-zc pull_request: paths: - '.github/workflows/ansible.yml' diff --git a/deployments/ansible/molecule/with_instrumentation_preload_custom/converge.yml b/deployments/ansible/molecule/with_instrumentation_preload_custom/converge.yml index 67e462e962..4c6a5f5ff1 100644 --- a/deployments/ansible/molecule/with_instrumentation_preload_custom/converge.yml +++ b/deployments/ansible/molecule/with_instrumentation_preload_custom/converge.yml @@ -14,6 +14,34 @@ splunk_otel_auto_instrumentation_enable_metrics: true splunk_otel_auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317 tasks: + - name: "Install nodejs" + block: + - name: "install tar with apt" + ansible.builtin.apt: + name: tar + update_cache: yes + when: ansible_os_family == "Debian" + - name: "install tar with yum" + ansible.builtin.yum: + name: tar + update_cache: yes + when: ansible_os_family == "RedHat" + - name: "install tar with zypper" + community.general.zypper: + name: tar + update_cache: yes + when: ansible_os_family == "Suse" + - name: "download and extract" + unarchive: + src: https://nodejs.org/download/release/v16.20.2/node-v16.20.2-linux-x64.tar.gz + dest: /usr/local + remote_src: yes + - name: "create npm symlink" + file: + src: /usr/local/node-v16.20.2-linux-x64/bin/npm + dest: /usr/local/bin/npm + state: link + mode: '755' - name: "Include signalfx.splunk_otel_collector.collector role" include_role: name: "collector" diff --git a/deployments/ansible/molecule/with_instrumentation_preload_custom/verify.yml b/deployments/ansible/molecule/with_instrumentation_preload_custom/verify.yml index aebf638eda..21a748a03e 100644 --- a/deployments/ansible/molecule/with_instrumentation_preload_custom/verify.yml +++ b/deployments/ansible/molecule/with_instrumentation_preload_custom/verify.yml @@ -17,6 +17,15 @@ set_fact: auto_instrumentation_version: "{{ ansible_facts.packages['splunk-otel-auto-instrumentation'][0].version }}" + - name: splunk-otel-js installed + community.general.npm: + name: /usr/lib/splunk-instrumentation/splunk-otel-js.tgz + path: /usr/lib/splunk-instrumentation/splunk-otel-js + state: present + check_mode: yes + register: splunk_otel_js_installed + failed_when: splunk_otel_js_installed is changed + - name: Check for systemd drop-in file ansible.builtin.stat: path: /usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf @@ -53,58 +62,85 @@ register: config failed_when: config is changed + - name: Assert instrumentation config contains NODE_OPTIONS + ansible.builtin.lineinfile: + line: NODE_OPTIONS=-r /usr/lib/splunk-instrumentation/splunk-otel-js/node_modules/@splunk/otel/instrument + dest: /etc/splunk/zeroconfig/node.conf + state: present + check_mode: yes + register: config + failed_when: config is changed + - name: Assert instrumentation config contains OTEL_RESOURCE_ATTRIBUTES ansible.builtin.lineinfile: line: "OTEL_RESOURCE_ATTRIBUTES=\ splunk.zc.method=splunk-otel-auto-instrumentation-{{ auto_instrumentation_version }},\ deployment.environment=test" - dest: /etc/splunk/zeroconfig/java.conf + dest: "/etc/splunk/zeroconfig/{{ item }}" state: present check_mode: yes register: config failed_when: config is changed + loop: + - java.conf + - node.conf - name: Assert instrumentation config contains OTEL_SERVICE_NAME ansible.builtin.lineinfile: line: OTEL_SERVICE_NAME=test - dest: /etc/splunk/zeroconfig/java.conf + dest: "/etc/splunk/zeroconfig/{{ item }}" state: present check_mode: yes register: config failed_when: config is changed + loop: + - java.conf + - node.conf - name: Assert instrumentation config contains SPLUNK_PROFILER_ENABLED ansible.builtin.lineinfile: line: SPLUNK_PROFILER_ENABLED=true - dest: /etc/splunk/zeroconfig/java.conf + dest: "/etc/splunk/zeroconfig/{{ item }}" state: present check_mode: yes register: config failed_when: config is changed + loop: + - java.conf + - node.conf - name: Assert instrumentation config contains SPLUNK_PROFILER_MEMORY_ENABLED ansible.builtin.lineinfile: line: SPLUNK_PROFILER_MEMORY_ENABLED=true - dest: /etc/splunk/zeroconfig/java.conf + dest: "/etc/splunk/zeroconfig/{{ item }}" state: present check_mode: yes register: config failed_when: config is changed + loop: + - java.conf + - node.conf - name: Assert instrumentation config contains SPLUNK_METRICS_ENABLED ansible.builtin.lineinfile: line: SPLUNK_METRICS_ENABLED=true - dest: /etc/splunk/zeroconfig/java.conf + dest: "/etc/splunk/zeroconfig/{{ item }}" state: present check_mode: yes register: config failed_when: config is changed + loop: + - java.conf + - node.conf - name: Assert instrumentation config contains OTEL_EXPORTER_OTLP_ENDPOINT ansible.builtin.lineinfile: line: OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4317 - dest: /etc/splunk/zeroconfig/java.conf + dest: "/etc/splunk/zeroconfig/{{ item }}" state: present check_mode: yes register: config failed_when: config is changed + loop: + - java.conf + - node.conf diff --git a/deployments/ansible/roles/collector/defaults/main.yml b/deployments/ansible/roles/collector/defaults/main.yml index 19390ac5df..90de49277b 100644 --- a/deployments/ansible/roles/collector/defaults/main.yml +++ b/deployments/ansible/roles/collector/defaults/main.yml @@ -74,6 +74,8 @@ splunk_otel_auto_instrumentation_enable_profiler: false splunk_otel_auto_instrumentation_enable_profiler_memory: false splunk_otel_auto_instrumentation_enable_metrics: false splunk_otel_auto_instrumentation_otlp_endpoint: http://127.0.0.1:4317 +splunk_otel_auto_instrumentation_sdks: ["java", "node"] +splunk_otel_auto_instrumentation_npm_path: "npm" # Custom environment variables for the collector service splunk_otel_collector_additional_env_vars: {} diff --git a/deployments/ansible/roles/collector/tasks/linux_auto_instrumentation.yml b/deployments/ansible/roles/collector/tasks/linux_auto_instrumentation.yml index a1cd4d9b21..f2781ede16 100644 --- a/deployments/ansible/roles/collector/tasks/linux_auto_instrumentation.yml +++ b/deployments/ansible/roles/collector/tasks/linux_auto_instrumentation.yml @@ -20,19 +20,43 @@ set_fact: auto_instrumentation_version: "{{ ansible_facts.packages['splunk-otel-auto-instrumentation'][0].version }}" -- name: Set up /etc/ld.so.preload for Splunk OpenTelemetry Auto Instrumentation - ansible.builtin.template: - src: ld_so_preload.j2 - dest: /etc/ld.so.preload - owner: root - group: root - mode: '644' +- name: Set auto instrumentation facts + set_fact: + with_new_instrumentation: > + {{ auto_instrumentation_version is version('0.87.0', '>=') }} + with_systemd: > + {{ splunk_otel_auto_instrumentation_systemd | bool }} + with_java: > + {{ "java" in (splunk_otel_auto_instrumentation_sdks | default([])) }} + with_nodejs: > + {{ "nodejs" in (splunk_otel_auto_instrumentation_sdks | default([])) and + auto_instrumentation_version is version('0.87.0', '>=') }} + +- name: Check for npm + shell: "command -v {{ splunk_otel_auto_instrumentation_npm_path | default('npm') }}" + check_mode: yes + register: npm_check + ignore_errors: true + when: with_nodejs + +- name: Install splunk-otel-js + block: + - name: Create /usr/lib/splunk-instrumentation/splunk-otel-js + ansible.builtin.file: + path: /usr/lib/splunk-instrumentation/splunk-otel-js + state: directory + - name: npm install + community.general.npm: + name: /usr/lib/splunk-instrumentation/splunk-otel-js.tgz + path: /usr/lib/splunk-instrumentation/splunk-otel-js + executable: "{{ npm_check.stdout.strip() }}" + when: with_nodejs and (npm_check.rc == 0) - name: Delete the Splunk OpenTelemetry Auto Instrumentation systemd config ansible.builtin.file: path: /usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf state: absent - when: not (splunk_otel_auto_instrumentation_systemd | bool) + when: not with_systemd notify: "Reload systemd daemon" - name: Set up the Splunk OpenTelemetry Auto Instrumentation config file @@ -42,9 +66,7 @@ owner: root group: root mode: '644' - when: > - auto_instrumentation_version is version('0.87.0', '<') and - not (splunk_otel_auto_instrumentation_systemd | bool) + when: with_java and not with_new_instrumentation and not with_systemd - name: Set up the Splunk OpenTelemetry Auto Instrumentation for Java config file ansible.builtin.template: @@ -53,15 +75,22 @@ owner: root group: root mode: '644' - when: > - auto_instrumentation_version is version('0.87.0', '>=') and - not (splunk_otel_auto_instrumentation_systemd | bool) + when: with_java and with_new_instrumentation and not with_systemd + +- name: Set up the Splunk OpenTelemetry Auto Instrumentation for Node.js config file + ansible.builtin.template: + src: node.conf.j2 + dest: /etc/splunk/zeroconfig/node.conf + owner: root + group: root + mode: '644' + when: with_nodejs and (npm_check.rc == 0) and not with_systemd - name: Ensure the system.conf.d directory exists ansible.builtin.file: path: /usr/lib/systemd/system.conf.d state: directory - when: splunk_otel_auto_instrumentation_systemd | bool + when: with_systemd - name: Set up systemd for Splunk OpenTelemetry Auto Instrumentation ansible.builtin.template: @@ -70,5 +99,13 @@ owner: root group: root mode: '644' - when: splunk_otel_auto_instrumentation_systemd | bool + when: with_systemd and (with_java or (with_nodejs and npm_check.rc == 0)) notify: "Reload systemd daemon" + +- name: Set up /etc/ld.so.preload for Splunk OpenTelemetry Auto Instrumentation + ansible.builtin.template: + src: ld_so_preload.j2 + dest: /etc/ld.so.preload + owner: root + group: root + mode: '644' diff --git a/deployments/ansible/roles/collector/templates/node.conf.j2 b/deployments/ansible/roles/collector/templates/node.conf.j2 new file mode 100644 index 0000000000..79e771d098 --- /dev/null +++ b/deployments/ansible/roles/collector/templates/node.conf.j2 @@ -0,0 +1,13 @@ +NODE_OPTIONS=-r /usr/lib/splunk-instrumentation/splunk-otel-js/node_modules/@splunk/otel/instrument +{% if splunk_otel_auto_instrumentation_resource_attributes is defined and splunk_otel_auto_instrumentation_resource_attributes %} +OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-{{ auto_instrumentation_version }},{{ splunk_otel_auto_instrumentation_resource_attributes }} +{% else %} +OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-{{ auto_instrumentation_version }} +{% endif %} +{% if splunk_otel_auto_instrumentation_service_name is defined and splunk_otel_auto_instrumentation_service_name %} +OTEL_SERVICE_NAME={{ splunk_otel_auto_instrumentation_service_name }} +{% endif %} +SPLUNK_PROFILER_ENABLED={{ splunk_otel_auto_instrumentation_enable_profiler | string | lower }} +SPLUNK_PROFILER_MEMORY_ENABLED={{ splunk_otel_auto_instrumentation_enable_profiler_memory | string | lower }} +SPLUNK_METRICS_ENABLED={{ splunk_otel_auto_instrumentation_enable_metrics | string | lower }} +OTEL_EXPORTER_OTLP_ENDPOINT={{ splunk_otel_auto_instrumentation_otlp_endpoint }}