The Python agent for Apache SkyWalking

Clone this repo:

Branches

  1. 1bfced8 Feature: adapt HTTP protocol (#8) by kezhenxu94 · 4 weeks ago master
  2. 445d64c BugFix: plugin urllib.request (#7) by kezhenxu94 · 4 weeks ago
  3. 5ae9d30 Feature: report service instance to backend (#6) by kezhenxu94 · 4 weeks ago
  4. 2a14ae0 Test: forward POST method to GET method for e2e tests by kezhenxu94 · 4 weeks ago
  5. 43794ac Feature: logging level and disabling plugins (#5) by kezhenxu94 · 4 weeks ago

SkyWalking Python Agent

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

Set up Python Agent

SkyWalking Python SDK requires SkyWalking 8.0+.

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 and you don't need to call config.init.

The supported environment variables are as follows:

Environment VariableDescriptionDefault
SW_AGENT_NAMEThe name of the Python servicePython Service Name
SW_AGENT_INSTANCEThe name of the Python service instanceRandomly generated
SW_AGENT_COLLECTOR_BACKEND_SERVICESThe backend OAP server address127.0.0.1:11800
SW_AGENT_PROTOCOLThe protocol to communicate with the backend OAP, http or grpc, we highly suggest using grpc in production as it's well optimized than httpgrpc
SW_AGENT_LOGGING_LEVELThe logging level, could be one of CRITICAL, FATAL, ERROR, WARN(WARNING), INFO, DEBUGINFO
SW_AGENT_DISABLE_PLUGINSThe name patterns in CSV pattern, plugins whose name matches one of the pattern won't be installed''

Supported Libraries

There're some built-in plugins that support automatic instrumentation of Python libraries, the complete lists are as follow:

LibraryPlugin Name
http.serversw_http_server
urllib.requestsw_urllib_request

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
from skywalking.trace.context import SpanContext, get_context

@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()


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

FAQs

Check the FAQ page or add the FAQs there.

License

Apache 2.0