|
| 1 | +--- |
| 2 | +navigation_title: Configuration |
| 3 | +description: Configure the Elastic Distribution of OpenTelemetry Python (EDOT Python) to send data to Elastic. |
| 4 | +applies_to: |
| 5 | + stack: |
| 6 | + serverless: |
| 7 | + observability: |
| 8 | + product: |
| 9 | + edot_python: ga |
| 10 | +products: |
| 11 | + - id: cloud-serverless |
| 12 | + - id: observability |
| 13 | + - id: edot-sdk |
| 14 | +--- |
| 15 | + |
| 16 | +# Configure the EDOT Python agent |
| 17 | + |
| 18 | +Configure the {{edot}} Python (EDOT Python) to send data to Elastic. |
| 19 | + |
| 20 | +## Configuration method |
| 21 | + |
| 22 | +Configure the OpenTelemetry SDK through the mechanisms [documented on the OpenTelemetry website](https://opentelemetry.io/docs/zero-code/python/configuration/). EDOT Python is typically configured with `OTEL_*` environment variables defined by the OpenTelemetry spec. For example: |
| 23 | + |
| 24 | +```sh |
| 25 | +export OTEL_RESOURCE_ATTRIBUTES=service.name=<app-name>,deployment.environment.name=<env-name> |
| 26 | +export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.ingest.us-west1.gcp.cloud.es.io |
| 27 | +export OTEL_EXPORTER_OTLP_HEADERS="Authorization=ApiKey P....l" |
| 28 | +opentelemetry-instrument <command to start your service> |
| 29 | +``` |
| 30 | + |
| 31 | +## Configuration options |
| 32 | + |
| 33 | +Because the {{edot}} Python is an extension of OpenTelemetry Python, it supports both: |
| 34 | + |
| 35 | +* [General OpenTelemetry configuration options](#opentelemetry-configuration-options) |
| 36 | +* [Specific configuration options that are only available in EDOT Python](#configuration-options-only-available-in-edot-python) |
| 37 | + |
| 38 | +## Central configuration |
| 39 | + |
| 40 | +```{applies_to} |
| 41 | +serverless: unavailable |
| 42 | +stack: preview 9.1 |
| 43 | +product: |
| 44 | + edot_python: preview 1.4.0 |
| 45 | +``` |
| 46 | + |
| 47 | +APM Agent Central Configuration lets you configure EDOT Python instances remotely, see [Central configuration docs](opentelemetry://reference/central-configuration.md) for more details. |
| 48 | + |
| 49 | +### Turn on central configuration |
| 50 | + |
| 51 | +To activate central configuration, set the `ELASTIC_OTEL_OPAMP_ENDPOINT` environment variable to the OpAMP server endpoint. |
| 52 | + |
| 53 | +```sh |
| 54 | +export ELASTIC_OTEL_OPAMP_ENDPOINT=http://localhost:4320/v1/opamp |
| 55 | +``` |
| 56 | + |
| 57 | +To deactivate central configuration, remove the `ELASTIC_OTEL_OPAMP_ENDPOINT` environment variable and restart the instrumented application. |
| 58 | + |
| 59 | +### Central configuration settings |
| 60 | + |
| 61 | +You can modify the following settings for EDOT Python through APM Agent Central Configuration: |
| 62 | + |
| 63 | +| Settings | Description | Type | Versions | |
| 64 | +|---------------|----------------------------------------------|---------|---------| |
| 65 | +| Logging level | Configure EDOT Python agent logging level. | Dynamic | {applies_to}`stack: preview 9.1` <br> {applies_to}`edot_python: preview 1.4.0` | |
| 66 | +| Sampling rate | Configure EDOT Python tracing sampling rate. | Dynamic | {applies_to}`stack: preview 9.2` <br> {applies_to}`edot_python: preview 1.7.0` | |
| 67 | + |
| 68 | +Dynamic settings can be changed without having to restart the application. |
| 69 | + |
| 70 | +### OpenTelemetry configuration options |
| 71 | + |
| 72 | +EDOT Python supports all configuration options listed in the [OpenTelemetry General SDK Configuration documentation](https://opentelemetry.io/docs/languages/sdk-configuration/general/) and [OpenTelemetry Python](https://opentelemetry.io/docs/languages/python). |
| 73 | + |
| 74 | +#### Logs |
| 75 | + |
| 76 | +Instrument Python `logging` module to format and forward logs in OTLP format is turned off by default and gated under a configuration environment variable: |
| 77 | + |
| 78 | +```sh |
| 79 | +export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true |
| 80 | +``` |
| 81 | + |
| 82 | +:::{note} |
| 83 | +Turning this on will make any call to [logging.basicConfig](https://docs.python.org/3/library/logging.html#logging.basicConfig) from your application a no-op. |
| 84 | +::: |
| 85 | + |
| 86 | +#### Differences from OpenTelemetry Python |
| 87 | + |
| 88 | +EDOT Python uses different defaults than OpenTelemetry Python for the following configuration options: |
| 89 | + |
| 90 | +| Option | EDOT Python default | OpenTelemetry Python default | |
| 91 | +|---|---|---| |
| 92 | +| `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` | `process_runtime,os,otel,telemetry_distro,service_instance,containerid,_gcp,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm` | `otel` | |
| 93 | +| `OTEL_METRICS_EXEMPLAR_FILTER` | `always_off` | `trace_based` | |
| 94 | +| `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` | `DELTA` | `CUMULATIVE` | |
| 95 | +| `OTEL_TRACES_SAMPLER` | `parentbased_traceidratio` | `parentbased_always_on` | |
| 96 | +| `OTEL_TRACES_SAMPLER_ARG` | `1.0` | | |
| 97 | + |
| 98 | +:::{note} |
| 99 | +`OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` cloud resource detectors are dynamically set. When running in a Kubernetes Pod it will be set to `process_runtime,os,otel,telemetry_distro,service_instance,_gcp,aws_eks`. |
| 100 | +::: |
| 101 | + |
| 102 | + |
| 103 | +### Configuration options only available in EDOT Python |
| 104 | + |
| 105 | +`ELASTIC_OTEL_` options are specific to Elastic and will always live in EDOT Python include the following. |
| 106 | + |
| 107 | +| Option(s) | Default | Description | |
| 108 | +|---|---|---| |
| 109 | +| `ELASTIC_OTEL_SYSTEM_METRICS_ENABLED` | `false` | When sets to `true`, sends *system namespace* metrics. | |
| 110 | + |
| 111 | +## LLM settings |
| 112 | + |
| 113 | +LLM instrumentations implement the following configuration options: |
| 114 | + |
| 115 | +| Option | default | description | |
| 116 | +|-------------------------------------------------------|---------|:--------------------------| |
| 117 | +| `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` | `false`| If set to `true`, enables the capturing of request and response content in the log events outputted by the agent. |
| 118 | + |
| 119 | + |
| 120 | +## Prevent logs export |
| 121 | + |
| 122 | +To prevent logs from being exported, set `OTEL_LOGS_EXPORTER` to `none`. However, application logs might still be gathered and exported by the Collector through the `filelog` receiver. |
| 123 | + |
| 124 | +To prevent application logs from being collected and exported by the Collector, refer to [Exclude paths from logs collection](elastic-agent://reference/edot-collector/config/configure-logs-collection.md#exclude-logs-paths). |
0 commit comments