Skip to main content

SkyWalking Python Agent

Sky Walking logo

SkyWalking-Python: The Python Agent for Apache SkyWalking, which provides the native tracing abilities for Python project.

SkyWalking: an APM(application performance monitor) system, especially designed for microservices, cloud native and container-based (Docker, Kubernetes, Mesos) architectures.

GitHub stars Twitter Follow

Build

Install

From Pypi

The Python agent module is published to Pypi, from where you can use pip to install:

# Install the latest version, using the default gRPC protocol to report data to OAP
pip install "apache-skywalking"

# Install the latest version, using the http protocol to report data to OAP
pip install "apache-skywalking[http]"

# Install the latest version, using the kafka protocol to report data to OAP
pip install "apache-skywalking[kafka]"

# Install a specific version x.y.z
# pip install apache-skywalking==x.y.z
pip install apache-skywalking==0.1.0  # For example, install version 0.1.0 no matter what the latest version is

From Source Codes

Refer to the FAQ.

Set up Python Agent

SkyWalking Python SDK requires SkyWalking 8.0+ and Python 3.5+.

If you want to try out the latest features that are not released yet, please refer to the guide to build from sources.

from skywalking import agent, config

config.init(collector='127.0.0.1:11800', service='your awesome service')
agent.start()

Alternatively, you can also pass the configurations via environment variables (such as SW_AGENT_NAME, SW_AGENT_COLLECTOR_BACKEND_SERVICES, etc.) so that you don't need to call config.init.

All supported environment variables can be found here

Supported Libraries

There are some built-in plugins (such as http.server, Flask, Django etc.) that support automatic instrumentation of Python libraries, the complete lists can be found here

API

Apart from the libraries that can be instrumented automatically, we also provide some APIs to enable manual instrumentation.

Create Spans

The code snippet below shows how to create entry span, exit span and local span.

from skywalking import Component
from skywalking.trace.context import SpanContext, get_context
from skywalking.trace.tags import Tag

context: SpanContext = get_context()  # get a tracing context
# create an entry span, by using `with` statement,
# the span automatically starts/stops when entering/exiting the context
with context.new_entry_span(op='https://github.com/apache') as span:
    span.component = Component.Flask
# the span automatically stops when exiting the `with` context

with context.new_exit_span(op='https://github.com/apache', peer='localhost:8080') as span:
    span.component = Component.Flask

with context.new_local_span(op='https://github.com/apache') as span:
    span.tag(Tag(key='Singer', val='Nakajima'))

Decorators

from time import sleep

from skywalking import Component
from skywalking.decorators import trace, runnable
from skywalking.trace.context import SpanContext, get_context
from skywalking.trace.ipc.process import SwProcess

@trace()  # the operation name is the method name('some_other_method') by default
def some_other_method():
    sleep(1)


@trace(op='awesome')  # customize the operation name to 'awesome'
def some_method():
    some_other_method()


@trace(op='async_functions_are_also_supported')
async def async_func():
    return 'asynchronous'


@trace()
async def async_func2():
    return await async_func()


@runnable() # cross thread propagation
def some_method(): 
    some_other_method()

from threading import Thread 
t = Thread(target=some_method)
t.start()

# When another process is started, agents will also be started in other processes, 
# supporting only the process mode of spawn.
p1 = SwProcess(target=some_method) 
p1.start()
p1.join()


context: SpanContext = get_context()
with context.new_entry_span(op=str('https://github.com/apache/skywalking')) as span:
    span.component = Component.Flask
    some_method()

Contributing

Before submitting a pull request or push a commit, please read our contributing and developer guide.

FAQs

Check the FAQ page or add the FAQs there.

License

Apache 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apache-skywalking-0.5.0.tar.gz (51.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apache_skywalking-0.5.0-py3-none-any.whl (161.4 kB view details)

Uploaded Python 3

File details

Details for the file apache-skywalking-0.5.0.tar.gz.

File metadata

  • Download URL: apache-skywalking-0.5.0.tar.gz
  • Upload date:
  • Size: 51.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.5.2

File hashes

Hashes for apache-skywalking-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e35f086fbc37710bee09b8c9399443c678e19c2f8a4a99d2e06f7952307f0251
MD5 efe02fba92d7f24b2ac7f6b6b8fe6bcb
BLAKE2b-256 a0a1b4dfbbde2acca7dbc5b9ea17a7aa80d065173a388aba2cd0df3fce65d1d2

See more details on using hashes here.

File details

Details for the file apache_skywalking-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: apache_skywalking-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 161.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.5.2

File hashes

Hashes for apache_skywalking-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 849411484157e737099c5c25f3b43eccf2d0b7cb9f2ab9756c9513b5e3456867
MD5 501b3683e17a8fd495feed01243a9423
BLAKE2b-256 6c6dbe13eb35b85d52c0dade3e064b94c2e3a74a3ae6ab54cb95d185867042c7

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page