Documentation forSolarWinds Observability

Configure the Python Library

See the following sections for information about the configuration options available for the Python Library and how to set them. The Service key is the only required configuration; all other configurations are optional.

How to set configuration options

Options to control the Python Library behavior can be set using system environment variables.

Complete list of configuration options

The following is the complete list of instrumentation configuration options:

Service key

The Service key is used to identify your account and the service being instrumented. It is shown in the Add Data dialog when adding the new service.

It is a required configuration and should be in the form of YourApiToken:YourServiceName. Replace YourApiToken with the SolarWinds Observability API token (ingestion type) generated for this service, and replace YourServiceName with your chosen name for this service. See API Tokens.

System environment variable

SW_APM_SERVICE_KEY

Required

Yes

Default

None

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export SW_APM_SERVICE_KEY="ABC123abcABC123abcABC123abcABC123abcABC123abcABC123abcABC123abcABC123ab:my-service"

Host name alias

An optional descriptive host name that can be used to easily identify the host. If configured, the host name alias is displayed and can be used as a filter in the Traces Explorer.

System environment variable

SW_APM_HOSTNAME_ALIAS

Required

No

Default

None

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export SW_APM_HOSTNAME_ALIAS=apm-host-east

Logging level

By default, the Python Library and its underlying native extension library send debug output to stderr. For most environments, stderr is included in the web application's logs. To troubleshoot the Python Library, enable debug-level logging (4 or higher) and check the messages. Python Library logging can be disabled by setting the log level to -1.

System environment variable

SW_APM_DEBUG_LEVEL

Valid Values

-1 disable
0 fatal
1 error
2 warning
3 info
4 debug low
5 debug medium
6 debug high

Required

No

Default

2 (warning)

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export SW_APM_DEBUG_LEVEL=-1

EC2 Metadata Timeout

The Python Library is able to detect if it is running on an AWS EC2 or OpenStack instance by querying Instance Metadata. The timeout (in milli seconds) for retrieving the metadata can be set through this configuration. It is safe to set this value to 0 for apps that do not run on EC2/OpenStack.

System environment variable

SW_APM_EC2_METADATA_TIMEOUT

Valid values

This field expects an integer between 0 and 3000

Required

No

Default

1000

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export SW_APM_EC2_METADATA_TIMEOUT=500

Use HTTP proxy

The agent can connect to the SolarWinds APM collector through a proxy. The config value should either be http://<proxyHost>:<proxyPort> for a proxy server that does not require authentication, or http://<username>:<password>@<proxyHost>:<proxyPort> for a proxy server that requires Basic authentication. HTTP is the only type of connection supported between the Python Library and the proxy, however the library traffic to SolarWinds Observability is still encrypted using SSL/TLS.

It is recommended to use the Python Library-specific configuration. However, if a Python Library-specific configuration is not set, its underlying network library uses a system-wide proxy defined in the environment variables grpc_proxy, https_proxy or http_proxy. Refer to gRPC environment variables for more information.

System environment variable

SW_APM_PROXY

Valid Values

Any string starting with http://

This field is case-sensitive.

Required

No

Default

none

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Examples

export SW_APM_PROXY="http://my-proxy:3306"

Disable the library

The Python Library provides the option to completely disable the instrumentation without explicitly removing the library from your application. To disable the library, set the SW_APM_AGENT_ENABLED environment variable as described below.

System environment variable

SW_APM_AGENT_ENABLED

Valid values

This field is case-insensitive.

false

Do not instrument the application (i.e. do not generate any trace data)

true Normal tracing operation

Required

No

Default

true

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export SW_APM_AGENT_ENABLED=false

Disable specific instrumentation libraries

The Python Library provides the option to disable the instrumentation of specific Python libraries, while still instrumenting other libraries in your application. To disable specific libraries, set the OTEL_PYTHON_DISABLED_INSTRUMENTATIONS environment variable as described below.

System environment variable

OTEL_PYTHON_DISABLED_INSTRUMENTATIONS

Required

No

Default

None

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=urllib3,asyncpg

Customize OpenTelemetry Propagators

The Python Library sets the OpenTelemetry propagators necessary for distributed tracing by default, so no changes to the propagators are required for the library to work. If you want additional propagators, you can install and use them. For example:

pip install my-custom-propagator

After installing the propagators, set the OTEL_PROPAGATORS environment variable as described below.

System environment variable

OTEL_PROPAGATORS

Valid values

A string representing a list of valid propagator entry point names, delimited by commas.

Both tracecontext and solarwinds_propagator must be included, and tracecontext must come before solarwinds_propagator.

This field is case-sensitive.

Required

No

Default

tracecontext,baggage,solarwinds_propagator

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export OTEL_PROPAGATORS="my_custom_propagator,tracecontext,solarwinds_propagator"

Customize OpenTelemetry Exporters

The Python Library sets an OpenTelemetry exporter for SolarWinds Observability platform by default, so no changes to the exporters are necessary for the library to work. If you want additional exporters, you can install and use them. For example:

pip install opentelemetry-exporter-otlp-proto-grpc

After installing the exporters, set the OTEL_TRACES EXPORTER environment variable as described below.

System environment variable

OTEL_TRACES_EXPORTER

Valid values

A string representing a list of valid exporter entry point names, delimited by commas.

solarwinds_exporter must be included. The order of the exporters does not matter.

This field is case-sensitive.

Required

No

Default

solarwinds_exporter

History

Introduced with version 0.1.0 of the Python Instrumentation Library.

Example

export OTEL_TRACES_EXPORTER="solarwinds_exporter,otlp_proto_grpc"

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.