Configuring the Python package

Configuration reference

A quick reference for all configuration options available in the Instana Python package. Each option links to its detailed section.

Environment variables

Environment variable Description Details
INSTANA_AGENT_HOST Host address of the Instana agent Establishing host agent communication
INSTANA_AGENT_PORT Port number of the Instana agent Establishing host agent communication
INSTANA_SERVICE_NAME Custom service name Setting the service name
INSTANA_PROCESS_NAME Custom process label Setting the process name
INSTANA_AUTOPROFILE Enable AutoProfile Enabling AutoProfile
INSTANA_DEBUG Enable debug logging Debugging and more verbosity
INSTANA_DISABLE_AUTO_INSTR Disable automatic instrumentation Disabling automatic instrumentation
INSTANA_ALLOW_ROOT_EXIT_SPAN Trace exit spans without an entry span Tracing root exit span without entry span
INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION Enable asyncio task context propagation Asyncio task context propagation
INSTANA_SECRETS Secrets matcher and list (<matcher>:<secret>[,<secret>]) General reference: Environment variables
INSTANA_EXTRA_HTTP_HEADERS Semicolon-separated list of HTTP headers to capture General reference: Environment variables
INSTANA_KAFKA_TRACE_CORRELATION Enable or disable Kafka trace correlation Configuring Kafka Trace correlation headers
INSTANA_TRACING_FILTER_* Span filtering rules Filtering by using environment variables
INSTANA_TRACING_DISABLE Disable span categories or types Disabling by using environment variables
INSTANA_STACK_TRACE Stack trace capture level Using environment variables
INSTANA_STACK_TRACE_LENGTH Number of stack trace frames to capture Using environment variables
INSTANA_CONFIG_PATH Path to a YAML configuration file Using YAML configuration
INSTANA_GEVENT_MONKEY_OPTIONS Comma-separated gevent monkey-patch options Gevent-based applications

In-code configuration

The instana.configurator.config object provides a Python-native alternative to environment variables for the following options. Import it with from instana.configurator import config.

Option config key Environment variable equivalent
Asyncio task context propagation config["asyncio_task_context_propagation"]["enabled"] INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION
Span filtering config["tracing"]["filter"] INSTANA_TRACING_FILTER_* or INSTANA_CONFIG_PATH
Span disabling config["tracing"]["disable"] INSTANA_TRACING_DISABLE or INSTANA_CONFIG_PATH
Stack trace capturing config["tracing"]["global"] or config["tracing"]["<tech>"] INSTANA_STACK_TRACE or INSTANA_STACK_TRACE_LENGTH
Kafka trace correlation config["tracing"]["kafka"]["trace_correlation"] INSTANA_KAFKA_TRACE_CORRELATION
Note:
As the package evolves, additional options are added.

General configuration

The Instana Python package aims to be a fully no-touch automatic solution for Python monitoring but still be fully configurable when needed. The following options are available to configure this package.

Enabling AutoProfile

AutoProfile generates and reports process profiles to Instana automatically and continuously. Learn more about profiles in the Analyze Profiles section.

To enable AutoProfile set the environment variable INSTANA_AUTOPROFILE=true. AutoProfile is supported for manual installation only. Make sure that the Instana sensor is initialized in the main thread.

Establishing host agent communication

The Instana Python package tries to communicate with the Instana agent through IP 127.0.0.1 and as a fallback through the host's default gateway for containerized environments. If the agent is not available at either of these locations, you can use environment variables to configure where to look for the Instana host agent.

The environment variables must be set in the environment of the running process.

export INSTANA_AGENT_HOST = '127.0.0.1'
export INSTANA_AGENT_PORT = '42699'
 

See also:

Setting the service name

By default, the Instana makes the best effort in naming your services appropriately. If for any reason you want to customize how services are named, you can do so by setting an environment variable:

export INSTANA_SERVICE_NAME=myservice
 

See also the General Reference: Environment Variables for Language Sensors

Setting the process name

Use INSTANA_PROCESS_NAME to set a custom label for infrastructure entity that represents the Python process.

Asyncio task context propagation

Enable tracing context propagation across asyncio.ensure_future and asyncio.create_task calls. Disabled by default.

from instana.configurator import config

config['asyncio_task_context_propagation']['enabled'] = True
 

Alternatively, set the equivalent environment variable:

export INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION="true"
 

Disabling automatic instrumentation

This Instana package includes automatic instrumentation that is initialized on package load. This instrumentation provides distributed tracing information to your Instana dashboard. To see the complete list of automatic instrumentation, see the Supported versions document.

You can disable automatic instrumentation (tracing) by setting the environment variable INSTANA_DISABLE_AUTO_INSTR , which suppresses the loading of instrumentation that is built into the tracer.

export INSTANA_DISABLE_AUTO_INSTR="true"
 

Tracing root exit span without entry span

By default, the Instana Python Tracer captures only exit spans with an active entry span. However, in certain scenarios, you need to trace exit spans that occur without an entry span.

To configure the Python Tracer to trace standalone exit spans, set the INSTANA_ALLOW_ROOT_EXIT_SPAN environment variable to 1 or true as follows:

export INSTANA_ALLOW_ROOT_EXIT_SPAN=1
 

This feature is useful in the following scenarios:

  • Incoming messages from unsupported messaging libraries.
  • Requests that are made through unsupported protocols, such as raw Transmission Control Protocol (TCP) or WebSocket.
  • Scheduled jobs that are initiated internally by other applications.
  • Execution of Python scripts.

Frameworks

You can configure the Instana Python package to monitor and collect data from the following frameworks:

Django (Manual)

When the AUTOWRAPT_BOOTSTRAP=instana environment variable is set, the Django framework must be automatically detected and instrumented. If for some reason, you prefer to or need to manually instrument Django, you can instead add instana.instrumentation.django.middleware.InstanaMiddleware to your MIDDLEWARE list in settings.py:

import os
import instana

# ... <snip> ...

MIDDLEWARE = [
    'instana.instrumentation.django.middleware.InstanaMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
 

Pyramid

Note:
Starting from Instana Python 3.0.0, the Pyramid instrumentation is automatic.

Starting from version 1.22.0 to 2.5.3, the Instana Python package includes manual support for Pyramid. To add visibility to your Pyramid-based application, complete the following steps:

  1. Make sure that the instana package is added to the requirements.txt and installed in the virtual environment or container.
  2. Add import instana to the beginning of your __init__.py file for your Pyramid application.
  3. Add the Instana instrumentation Tween to your configuration.
import instana

with Configurator(settings=settings) as config:
    # ...
    config.include('instana.instrumentation.pyramid.tweens')
    # ...
 

The following image displays an example of the Instana instrumentation in your Pyramid configuration:

pyramid

In case you have the pyramid.tweens option set in your production.ini config, make sure that instana.instrumentation.pyramid.tweens.InstanaTweenFactory is the first entry in this list:

pyramid.tweens =
    instana.instrumentation.pyramid.tweens.InstanaTweenFactory
    # other tweens
 

WSGI and ASGI stacks

The Instana Python package includes Web Server Gateway Interface (WSGI) and Asynchronous Server Gateway Interface (ASGI) middleware that can be added to any compliant stack. Automation is available for various stacks, but manual addition is also possible for those stacks that don't have automatic support yet from Instana.

After you install the Instana Python package, use the following commands:

import instana

from instana.middleware import InstanaWSGIMiddleware
# or
from instana.middleware import InstanaASGIMiddleware

# Wrap the wsgi app in Instana middleware (InstanaWSGIMiddleware)
wsgiapp = InstanaWSGIMiddleware(MyWSGIApplication())
 

Instana is working to automate instrumentation for all major frameworks but in the meantime, check some specific quick starts for those stacks that don't have automatic support yet from Instana.

Bottle WSGI

Use the following commands for instrumenting Bottle WSGI:

# Import Instana and the Instana WSGI middleware wrapper
import instana
from instana.middleware import InstanaWSGIMiddleware

from bottle import Bottle, run

app = Bottle()

@app.route('/hello')
def hello():
    return "Hello World!"

# Wrap the application with the Instana WSGI Middleware
app = InstanaWSGIMiddleware(app)

# Alternative method for reference
# app = InstanaWSGIMiddleware(bottle.default_app())

run(app, host='localhost', port=8080)
 

CherryPy WSGI

Use the following commands for instrumenting CherryPy WSGI:

import cherrypy

# Import Instana and the Instana WSGI middleware wrapper
import instana
from instana.middleware import InstanaWSGIMiddleware

# My CherryPy application
class Root(object):
    @cherrypy.expose
    def index(self):
        return "hello world"

cherrypy.config.update({'engine.autoreload.on': False})
cherrypy.server.unsubscribe()
cherrypy.engine.start()

# Wrap the application with the Instana WSGI Middleware
wsgiapp = InstanaWSGIMiddleware(cherrypy.tree.mount(Root()))
 

In this example, we use uwsgi as the web server and booted with:

uwsgi --socket 127.0.0.1:8080 --enable-threads --protocol=http --wsgi-file mycherry.py --callable wsgiapp -H ~/.local/share/virtualenvs/cherrypyapp-C1BUba0z
 

Where ~/.local/share/virtualenvs/cherrypyapp-C1BUba0z is the path to my local virtualenv from pipenv

Falcon WSGI

The Falcon framework can also be instrumented through the WSGI wrapper as such:

import falcon

# Import Instana and the Instana WSGI middleware wrapper
import instana
from instana.middleware import InstanaWSGIMiddleware

app = falcon.API()

# ...

# Wrap the application with the Instana WSGI Middleware
app = InstanaWSGIMiddleware(app)
 

Then, booting your stack with uwsgi --http :9000 --enable-threads --module=myfalcon.app as an example

Gevent-based applications

Instana supports applications based on gevent 1.4 and later.

If you are manually importing the Instana Python package, make sure that the gevent import and monkey patching happen first.

    from gevent import monkey
    monkey.patch_all()
    import instana # <--- after the gevent monkey patching of stdlib
 
Note:
Before Instana Python Tracer 2.5.0, the gevent-based applications must not use the Activating without code changes method of package activation (that uses the AUTOWRAPT_BOOTSTRAP environment variable). This method doesn't work due to gevent's first-order monkey patching requirements as described earlier. In this case, use the Activating with code changes method.

Starting with Instana Python Tracer 2.5.0, the tracer automatically performs monkey.patch_all() when the AutoTrace webhook or the Activating without code changes method is used. You can fine-tune this monkey patching by setting the INSTANA_GEVENT_MONKEY_OPTIONS environment variable. With this comma-separated list, you can specify the modules to include or exclude from monkey patching as MONKEY OPTIONS to gevent's gevent.monkey.main function.

The following examples show options that are available for customizing modules for monkey patching:

export INSTANA_GEVENT_MONKEY_OPTIONS='--no-socket, --dns, --no-time, --select, --no-ssl'
 
export INSTANA_GEVENT_MONKEY_OPTIONS='no-socket, dns, no-time, select, no-ssl'
 
export INSTANA_GEVENT_MONKEY_OPTIONS='no-socket,dns,no-time,select,no-ssl'
 

If you use Django together with gevent and Instana autotracing, then ensure that you set the DJANGO_SETTINGS_MODULE environment variable before the autotracing starts. For more information about the DJANGO_SETTINGS_MODULE environment variable, see the Django documentation.

If this level of customization is still insufficient, then use the Activating with code changes method of package activation.

Tools

You can configure the Instana Python package to monitor and collect data from different tools.

Web servers

The following configurations can be used to monitor different web servers:

uWSGI web server

Make sure enable-threads is enabled for uwsgi.

Threads

This Python instrumentation creates a lightweight background thread to periodically collect and report process metrics. By default, the GIL and threading are disabled under uWSGI. If you want to instrument your application that runs under uWSGI, make sure that you enable threads by passing the --enable-threads command (or enable-threads = true in INI style). For more information, see the uWSGI documentation.

uWSGI example: Command line

uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi -p 4 --enable-threads
 

uWSGI example: INI file

[uwsgi]
http = :5000
master = true
processes = 4
enable-threads = true # required
 

Gunicorn web server

To instrument your application that runs under Gunicorn, make sure that you give --preload as an argument.

Preload

This Python instrumentation creates a lightweight background thread to periodically collect and report process metrics. By default, the application code processes after workers are forked in Gunicorn. If you want to instrument your application that runs under Gunicorn, make sure that you enable preloading by passing the --preload command. For more information, see the Gunicorn documentation.

Gunicorn example: Command line

To run Gunicorn with preloading, use the following command that is shown in this example:

gunicorn -w 4 --preload "file:app"
 

Gunicorn example: Config file

To use Gunicorn with a config file, use a Python file with the following variables. Add -c file_name.py to the Gunicorn command.

bind = "0.0.0.0:8000"
workers = 4
preload_app = true  # required
 

end user monitoring (EUM)

Instana provides deep end user monitoring that links server-side traces with browser events to give you a complete view from server to browser.

See the end user monitoring page for more details.

Filtering spans

With Python Tracer 3.11.0 and later, you can reduce trace data volume by filtering spans based on their attributes. This feature helps optimize data ingestion costs and focuses monitoring on the most relevant traces for your application.

You can configure filtering rules to exclude or include spans based on the following criteria:

  • Span attributes: Specific attribute values (for example, kafka.topic or redis.command)
  • Categories: Technology types, such as databases, messaging, or protocols
  • Types: Library or framework identifiers (for example, httpor kafka)
  • Kinds: Span types, such as entry, exit, or intermediate

Configuring span filtering

You can configure span filtering by using any of the following methods. When multiple methods are used, the filtering is applied in the following order of precedence (highest to lowest):

  1. YAML configuration (INSTANA_CONFIG_PATH)
  2. INSTANA_TRACING_FILTER_* environment variables
  3. In-code configuration (config["tracing"]["filter"])
  4. Agent configuration (configuration.yaml)
Note:
If multiple configurations are provided, only the highest-precedence source that is present takes effect; the others are ignored entirely.

Filtering by using YAML configuration

Set the INSTANA_CONFIG_PATH environment variable to point to a local YAML configuration file:

INSTANA_CONFIG_PATH=/path/to/your/configuration.yaml
 

The file must follow the same YAML structure as described in Filtering by using agent configuration.

Filtering by using environment variables

Configure span filtering rules by using the following environment variables:

  • INSTANA_TRACING_FILTER_<policy>_<rule-name>_ATTRIBUTES
    INSTANA_TRACING_FILTER_<policy>_<rule-name>_ATTRIBUTES="rule-key;rule-value;match-type"

The following table lists the parameters along with their details and supported values:

Parameter Description Values
<policy> Filter policy type
  • EXCLUDE: Excludes spans matching the rule
  • INCLUDE: Include only spans matching the rule
<rule-name> Unique identifier for the rule (prevents conflicts with other rules)
rule-key Attribute to filter on
  • category: Technology groups (databases, messaging, or protocols)
  • kind: Span type (entry, exit, or intermediate) - type: Library or framework (http, kafka, or redis)
  • attribute: Specific span attribute (kafka.access, redis.command, or dynamodb.op)
rule-value Comma-separated list of values to match
  • For kafka.access: consume, send, produce
  • For redis.command: SET, GET
match-type Matching strategy
  • strict: Exact match
  • startswith: Prefix match
  • endswith: Suffix match
  • contains: Substring match
Examples
# Exclude all HTTP spans
INSTANA_TRACING_FILTER_EXCLUDE_HTTP_ATTRIBUTES="type;http"

# Include only health check endpoints
INSTANA_TRACING_FILTER_INCLUDE_HEALTH_ATTRIBUTES="http.url;/health"

# Exclude all messaging spans
INSTANA_TRACING_FILTER_EXCLUDE_CATEGORY_ATTRIBUTES="category;messaging"

# Include only specific Kafka topic and operations
INSTANA_TRACING_FILTER_INCLUDE_KAFKA_ATTRIBUTES="kafka.topic;topic1;strict|kafka.access;consume,send"

# Exclude all exit spans
INSTANA_TRACING_FILTER_EXCLUDE_KIND_ATTRIBUTES="kind;exit"

Filtering by using in-code configuration

Define filtering rules directly in the Python code by using the config object. The structure mirrors the agent configuration.yaml format:

from instana.configurator import config

config["tracing"]["filter"] = {
    "exclude": [
        {
            "name": "Exclude all health check endpoints",
            "attributes": [
                {"key": "http.url", "values": ["/health"], "match_type": "contains"}
            ],
        }
    ],
    "include": [
        {
            "name": "Include specific internal health endpoint",
            "attributes": [
                {"key": "http.url", "values": ["/internal/health"], "match_type": "strict"}
            ],
        }
    ],
}

Filtering by using agent configuration

Define filtering rules in the tracing.filter section of the agent configuration.yaml file. The configuration uses a YAML structure to specify filter rules based on span attributes:

tracing:
  filter:
    deactivate: <boolean>
    <policy>: # exclude | include
      - name: <string>
        suppression: <boolean>
        attributes:
          - key: <string> # category | kind | type | span attribute (e.g., kafka.access, http.host)
            values: <list of strings>
            match_type: <string> # strict | startswith | endswith | contains
Important:
You can define multiple filter rules within a policy. Each rule can specify multiple attributes, and all attributes must match for the rule to apply.
Field Required Description Default
filter Yes Root node for all filtering rules.
deactivate No Feature toggle to disable filtering without deleting configured rules. Whentrue, filtering is disabled. false
policy Yes Filter policy type:exclude orinclude.
name Yes Human-readable name describing the filter rule.
suppression No Controls whether child spans are suppressed. Whentrue, all child spans are suppressed. Whenfalse, child spans are allowed.Applies to only Exclude policy true
attributes Yes List of span attributes that must all match for the rule to apply.
key Yes Span attribute key (for example,category,kind,type, or specific attributes, such askafka.access orhttp.host).
values Yes List of values to match. An attribute matches if any value matches. Use'*' as a wildcard to match any value (useful for filtering based on attribute presence).
match_type No Matching strategy:strict,startswith,endswith, orcontains

Rule evaluation

Filter rules are evaluated in order of appearance. When a span matches a rule, that rule is applied and no subsequent rules are evaluated. Arrange rules from most specific to most general to ensure correct filtering behavior.

Example configuration

tracing:
  filter:
    exclude:
      - name: Exclude all health check endpoints
        attributes:
          - key: http.url
            values: [/health]
            match_type: contains
      - name: Exclude all messaging spans
        attributes:
          - key: category
            values: [messaging]
            match_type: strict
    include:
      - name: Include specific internal health endpoint
        attributes:
          - key: http.url
            values: [/internal/health]
            match_type: strict

In the preceding example, the filtering configuration enforces the following rules:

  • Includes spans matching /internal/health (first matching rule)
  • Excludes spans matching /health (but not /internal/health)
  • Excludes all messaging category spans
  • Filters out all /health endpoints except /internal/health

Disabling spans

With Python Tracer 3.7.0 and later, you can disable spans by using the span disabling feature of the Instana Python Tracer. With the span disabling feature, you can completely disable the generation of spans in your application. This feature can be useful in the following scenarios:

  • You want to reduce the volume of spans generated by your application.
  • You have operations that are not relevant for monitoring.
  • You want to focus on other parts of your application performance.

Supported categories

Categories are sets of libraries grouped by a common type of technology or protocol. Currently, you can disable spans for only for the logging category.

Configuring span disabling

You can disable spans by using one of the following options. When multiple methods are used, the configuration is applied in the following order of precedence (highest to lowest):

  1. INSTANA_CONFIG_PATH (YAML file)
  2. INSTANA_TRACING_DISABLE environment variable
  3. In-code configuration (config["tracing"]["disable"])
  4. Agent configuration (configuration.yaml)
Note:
If multiple configurations are provided, only the highest-precedence source that is present takes effect; the others are ignored entirely.

Disabling by using YAML configuration

Set the INSTANA_CONFIG_PATH environment variable to a local YAML configuration file by using the following specification:

tracing:
  disable:
    - <category_or_type>: <boolean>

The disable key can receive a list of category or type names. A type name is the reference for any framework, library name, or instrumentation name supported by the Instana Python Tracer. Individual type configurations take precedence over their parent category settings, regardless of the definition order. This approach allows granular control where specific instrumentations can remain enabled even when their broader category is disabled. The following configuration example disables all database spans, except those for Redis:

com.instana.tracing:
  disable:
    - databases: true
    - redis: false

Disabling using environment variables

You can use the INSTANA_TRACING_DISABLE environment variable to disable spans as shown in the following example:

# Disable Redis spans
INSTANA_TRACING_DISABLE=redis

# Disable all logging spans
INSTANA_TRACING_DISABLE=logging

# Disable multiple technologies
INSTANA_TRACING_DISABLE=redis,logging

Disabling by using in-code configuration

Set the disable configuration directly in the Python code by using the config object:

from instana.configurator import config

# Disable all database spans, except those for Redis
config["tracing"]["disable"] = [
    {"databases": True},
    {"redis": False},
]

Individual type configurations take precedence over their parent category settings, regardless of the definition order.

Disabling by using agent configuration

To disable Redis spans by using the agent configuration approach, add the disable configuration to the agent configuration.yaml file:

com.instana.tracing:
  disable:
    - redis: true

To disable the logging category spans by using the agent configuration approach, add the disable configuration to the agent configuration.yaml file:

com.instana.tracing:
  disable:
    - logging: true

Configuring stack traces

By default, the Instana Python Tracer captures the last 30 stack trace frames for every captured EXIT span. This value can be increased or decreased as per your requirements.

Note:
Stack traces are not collected for ENTRY spans, as they usually don't contain any useful application-level information.

With Python Tracer 3.10.0 and later, you can configure two aspects of stack trace capturing:

  • Stack trace length: The number of stack trace frames to capture.
    • Supported values: 1–40
    • Default value: 30
  • Stack trace level: How stack traces are captured.
    • Supported values:
      • all: Collects stack trace for all exit spans (default).
      • error: Collects stack trace only for erroneous spans.
      • none: Doesn't collect stack trace.
Note:
For erroneous spans, the full stack trace is collected irrespective of the stack trace length, ensuring the complete root cause is captured.

You can configure stack trace capturing by using any one of the following options. When multiple methods are used, the configuration is applied in the following order of precedence (highest to lowest):

  1. INSTANA_CONFIG_PATH (YAML file)
  2. INSTANA_STACK_TRACE / INSTANA_STACK_TRACE_LENGTH environment variables
  3. In-code configuration (config["tracing"]["global"] / config["tracing"]["<tech>"])
  4. Agent configuration (configuration.yaml)
Note:
INSTANA_CONFIG_PATH and in-code configuration are mutually exclusive. If INSTANA_CONFIG_PATH is set, the in-code configuration is skipped entirely.

For configuring technology-specific stack trace capturing through the agent and YAML configuration methods, see Technology-specific configuration.

Using YAML configuration

Set the INSTANA_CONFIG_PATH environment variable to a local YAML configuration file by using the following specification:

tracing:
  global:
    stack-trace: <string>
    stack-trace-length: <int>

Using environment variables

You can use the INSTANA_STACK_TRACE and INSTANA_STACK_TRACE_LENGTH environment variables to filter stack traces as shown in the following example:

  • Capture stack traces only for erroneous spans: Use this setting to collect stack traces only when an error occurs.
    # Captures stack trace only for erroneous spans.
    INSTANA_STACK_TRACE=error
  • Disable stack trace collection: Use this setting to turn off stack trace collection completely.
    # Disable collection of stack trace.
    INSTANA_STACK_TRACE=none
  • Capture stack traces for all spans: Use this setting to collect stack traces for all spans.
    # Captures stack trace for all spans.
    INSTANA_STACK_TRACE=all
  • Limit the number of stack trace frames: Use this setting to limit how many stack trace frames are captured.
    # Limits capture of stack trace frames to 25.
    INSTANA_STACK_TRACE_LENGTH=25
     

Using in-code configuration

Set the stack trace configuration directly in the Python code by using the config object. Use stack_trace (not stack-trace) and stack_trace_length (not stack-trace-length) as key names. This configuration is ignored if INSTANA_CONFIG_PATH is set.

from instana.configurator import config

# Global configuration
config["tracing"]["global"] = {
    "stack_trace": "error",   # "all" | "error" | "none"
    "stack_trace_length": 25, # default: 30
}

# Technology-specific override (overrides the global setting for Kafka)
config["tracing"]["kafka"] = {
    "stack_trace": "all",
    "stack_trace_length": 35,
}

Using agent configuration

To configure stack trace capturing by using the agent configuration approach, define the parameters under the com.instana.tracing.global section in your agent configuration file, as shown in the following example:

com.instana.tracing:
  global:
    stack-trace-length: 15
    stack-trace: 'error' 

Technology-specific configuration

The Instana Python Tracer offers technology-specific configuration that overrides the global configurations. You can fine-tune the configuration and control the stack trace capture by using the following specification:

com.instana.tracing:
  global:
    stack-trace: <string>
    stack-trace-length: <int>

  <technology>:
    stack-trace: <string>
    stack-trace-length: <int>

In this configuration, the following values are supported for the <technology> key:

  • kafka
  • rabbitmq
  • aioamqp
  • aiohttp
  • urllib3 (for both urllib3 and requests spans)
  • httpx
  • log
  • redis
  • mysql
  • postgres
  • mongo
  • pymongo
  • cassandra
  • couchbase
  • dynamodb
  • sqlalchemy
  • boto3
  • s3
  • rpc

The following example captures stack traces for all spans and limits it to 25 frames as a global configuration, but for Kafka it captures the full stack trace only for erroneous spans:

com.instana.tracing:
  global:
    stack-trace: all
    stack-trace-length: 25

  kafka:
    stack-trace: error

Configuring Kafka Trace correlation headers

With trace correlation, spans maintain relationship between distributed span creations. For example, when trace correlation is enabled, the Trace ID is same for both producer span and consumer span. When the trace correlation is disabled, the producer and consumer spans have different Trace IDs, resulting in no correlation between them.

To disable Kafka Trace correlation entirely, you can use any of the following configuration options:

  • Environment variable: Set the environment variable INSTANA_KAFKA_TRACE_CORRELATION to false.

  • In-code configuration: Use the following configuration:

    from instana.configurator import config
    
    config["tracing"]["kafka"]["trace_correlation"] = False
     
  • Agent configuration: Configure the Kafka Trace correlation options at the level of the Instana host agent.

For more information, see Kafka Header Migration.

Monitoring specific processes

Instana automatically monitors processes with gunicorn, uwsgi, or python names in their command line. You can include a specific process name in the agent configuration file to monitor a running Python application that has a different name in the command line. For more information, see how to configure host agents using agent configuration file.