mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[opentelemetry][callback] add option to support enabling plugin in the CI (#3498)
* [opentelemetry][callback] add option to support enabling plugin in the CI only * [opentelemetry][callback] add changelog fragment * Apply suggestions from code review Co-authored-by: Ajpantuso <ajpantuso@gmail.com> * [opentelemetry][callback] use enable_from_environment * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * [opentelemetry] ensure the value is true otherwise the plugin is not enabled * [opentelemetry][changelog] update entry with the new option Co-authored-by: Ajpantuso <ajpantuso@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
e22fff2b12
commit
3a460751a4
2 changed files with 20 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- opentelemetry callback plugin - added option ``enable_from_environment`` to support enabling the plugin only if the given environment variable exists and it is set to true (https://github.com/ansible-collections/community.general/pull/3498).
|
|
@ -23,6 +23,17 @@ DOCUMENTATION = '''
|
|||
- Hide the arguments for a task.
|
||||
env:
|
||||
- name: ANSIBLE_OPENTELEMETRY_HIDE_TASK_ARGUMENTS
|
||||
enable_from_environment:
|
||||
type: str
|
||||
description:
|
||||
- Whether to enable this callback only if the given environment variable exists and it is set to C(true).
|
||||
- This is handy when you use Configuration as Code and want to send distributed traces
|
||||
if running in the CI rather when running Ansible locally.
|
||||
- For such, it evaluates the given I(enable_from_environment) value as environment variable
|
||||
and if set to true this plugin will be enabled.
|
||||
env:
|
||||
- name: ANSIBLE_OPENTELEMETRY_ENABLE_FROM_ENVIRONMENT
|
||||
version_added: 3.8.0
|
||||
otel_service_name:
|
||||
default: ansible
|
||||
type: str
|
||||
|
@ -57,6 +68,7 @@ examples: |
|
|||
'''
|
||||
|
||||
import getpass
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
@ -325,6 +337,12 @@ class CallbackModule(CallbackBase):
|
|||
var_options=var_options,
|
||||
direct=direct)
|
||||
|
||||
environment_variable = self.get_option('enable_from_environment')
|
||||
if environment_variable is not None and os.environ.get(environment_variable, 'false').lower() != 'true':
|
||||
self.disabled = True
|
||||
self._display.warning("The `enable_from_environment` option has been set and {0} is not enabled. "
|
||||
"Disabling the `opentelemetry` callback plugin.".format(environment_variable))
|
||||
|
||||
self.hide_task_arguments = self.get_option('hide_task_arguments')
|
||||
|
||||
self.otel_service_name = self.get_option('otel_service_name')
|
||||
|
|
Loading…
Reference in a new issue