From a5ff53f2ae76b07ea5348cbd63cee54085dea3b5 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 7 Jul 2022 21:51:04 +0200 Subject: [PATCH] allow configuring opentelementry callback via config file (#4916) this is especially useful for the `enable_from_environment` option, as this allows to set a default for the whole project, instead of relying on everyone setting the environment variable --- .../fragments/4916-opentelemetry-ini-options.yaml | 2 ++ plugins/callback/opentelemetry.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 changelogs/fragments/4916-opentelemetry-ini-options.yaml diff --git a/changelogs/fragments/4916-opentelemetry-ini-options.yaml b/changelogs/fragments/4916-opentelemetry-ini-options.yaml new file mode 100644 index 0000000000..5a20d7652a --- /dev/null +++ b/changelogs/fragments/4916-opentelemetry-ini-options.yaml @@ -0,0 +1,2 @@ +minor_changes: + - opentelemetry callback plugin - allow configuring opentelementry callback via config file (https://github.com/ansible-collections/community.general/pull/4916). diff --git a/plugins/callback/opentelemetry.py b/plugins/callback/opentelemetry.py index 1ea6e79622..7fc43d9a27 100644 --- a/plugins/callback/opentelemetry.py +++ b/plugins/callback/opentelemetry.py @@ -24,6 +24,10 @@ DOCUMENTATION = ''' - Hide the arguments for a task. env: - name: ANSIBLE_OPENTELEMETRY_HIDE_TASK_ARGUMENTS + ini: + - section: callback_opentelemetry + key: hide_task_arguments + version_added: 5.3.0 enable_from_environment: type: str description: @@ -34,6 +38,10 @@ DOCUMENTATION = ''' and if set to true this plugin will be enabled. env: - name: ANSIBLE_OPENTELEMETRY_ENABLE_FROM_ENVIRONMENT + ini: + - section: callback_opentelemetry + key: enable_from_environment + version_added: 5.3.0 version_added: 3.8.0 otel_service_name: default: ansible @@ -42,6 +50,10 @@ DOCUMENTATION = ''' - The service name resource attribute. env: - name: OTEL_SERVICE_NAME + ini: + - section: callback_opentelemetry + key: otel_service_name + version_added: 5.3.0 traceparent: default: None type: str @@ -61,11 +73,14 @@ examples: | Enable the plugin in ansible.cfg: [defaults] callbacks_enabled = community.general.opentelemetry + [callback_opentelemetry] + enable_from_environment = ANSIBLE_OPENTELEMETRY_ENABLED Set the environment variable: export OTEL_EXPORTER_OTLP_ENDPOINT= export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer your_otel_token" export OTEL_SERVICE_NAME=your_service_name + export ANSIBLE_OPENTELEMETRY_ENABLED=true ''' import getpass