Skip to content

Commit f6278c7

Browse files
authored
Merge pull request #14 from Dynatrace/release_130
Prepare release v1.3.0
2 parents a59b28c + 44c2748 commit f6278c7

File tree

19 files changed

+532
-146
lines changed

19 files changed

+532
-146
lines changed

README.md

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ This SDK enables Dynatrace customers to extend request level visibility into Pyt
1919
* [Incoming web requests](#incoming-web-requests)
2020
* [Outgoing web requests](#outgoing-web-requests)
2121
* [Trace in-process asynchronous execution](#trace-in-process-asynchronous-execution)
22-
* [Custom request attributes](#custom-request-attributes)
22+
* [Custom Request Attributes](#custom-request-attributes)
2323
* [Custom services](#custom-services)
2424
* [Messaging](#messaging)
25-
* [Outgoing Messages](#outgoing-messaging)
26-
* [Incoming Messages](#incoming-messaging)
25+
+ [Outgoing Messages](#outgoing-messages)
26+
+ [Incoming Messages](#incoming-messages)
27+
- [Using the OneAgent SDK for Python with forked child processes (only available on Linux)](#using-the-oneagent-sdk-for-python-with-forked-child-processes-only-available-on-linux)
2728
- [Troubleshooting](#troubleshooting)
28-
* [Installation issues](#installation-issues)
29-
* [Post-installation issues](#post-installation-issues)
29+
* [Extended SDK State](#extended-sdk-state)
3030
- [Repository contents](#repository-contents)
3131
- [Help & Support](#help--support)
3232
* [Read the manual](#read-the-manual)
@@ -40,12 +40,14 @@ This SDK enables Dynatrace customers to extend request level visibility into Pyt
4040
## Requirements
4141

4242
The SDK supports Python 2 ≥ 2.7 and Python 3 ≥ 3.4. Only the official CPython (that is, the "normal" Python, i.e. the Python implementation
43-
from <https://python.org>) is supported and only on Linux (musl libc is currently not supported) and Windows with the x86 (including
44-
x86-64) architecture. Additionally, `pip` ≥ 8.1.0 (2016-03-05) is required for installation.
43+
from <https://python.org>) is supported and only on Linux (musl libc which is used, e.g., on Alpine Linux, is currently not supported)
44+
and Windows with the x86 (including x86-64) architecture.
45+
Additionally, `pip` ≥ 8.1.0 (2016-03-05) is required for installation, and on Linux, the system should be
46+
[`manylinux1`-compatible](https://www.python.org/dev/peps/pep-0513/) to ensure a smooth installation via `pip`.
4547

4648
The Dynatrace OneAgent SDK for Python is a wrapper of the [Dynatrace OneAgent SDK for C/C++](https://github.com/Dynatrace/OneAgent-SDK-for-C)
4749
and therefore the SDK for C/C++ is required and delivered with the Python SDK. See
48-
[here](https://github.com/Dynatrace/OneAgent-SDK-for-C#dynatrace-oneagent-sdk-for-cc-requirements)
50+
[here](https://github.com/Dynatrace/OneAgent-SDK-for-C#requirements)
4951
for its requirements, which also apply to the SDK for Python.
5052

5153
The version of the SDK for C/C++ that is included in each version of the SDK for Python is shown in the following table along with the required
@@ -56,6 +58,7 @@ Dynatrace OneAgent version (it is the same as
5658

5759
|OneAgent SDK for Python|OneAgent SDK for C/C++|Dynatrace OneAgent|Support status |
5860
|:----------------------|:---------------------|:-----------------|:------------------|
61+
|1.3 |1.5.1 |≥1.179 |Supported |
5962
|1.2 |1.4.1 |≥1.161 |Supported |
6063
|1.1 |1.3.1 |≥1.151 |Supported |
6164
|1.0 |1.1.0 |≥1.141 |EAP (not supported)|
@@ -429,7 +432,6 @@ the callback of a periodic timer.
429432
```python
430433
with sdk.trace_custom_service('onTimer', 'CleanupTask'):
431434
# Do the cleanup task
432-
:
433435
```
434436

435437
Check out the documentation at:
@@ -535,31 +537,34 @@ See the documentation for more information:
535537
* [General information on tagging](https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/tagging.html)
536538
* [Messaging tracers in the specification repository](https://github.com/Dynatrace/OneAgent-SDK#messaging)
537539

538-
<a name="troubleshooting"></a>
539-
## Troubleshooting
540+
<a name="forking"></a>
541+
<a name="using-the-oneagent-sdk-for-python-with-forked-child-processes-only-available-on-linux"></a>
542+
## Using the OneAgent SDK for Python with forked child processes (only available on Linux)
540543

541-
<a name="installation-issues"></a>
542-
### Installation issues
544+
Some applications, especially web servers, use a concurrency model that is based on forked child processes.
545+
Typically a master process is started which is responsible only for creating and managing child processes by means of forking.
546+
The child processes do the real work, for example handling web requests.
543547

544-
* `ValueError` when installing, complaining about missing `DT_PYSDK_CSDK_PATH`.
548+
The recommended way to use the Python SDK in such a scenario is as follows: You initialize the SDK in the master process setting
549+
the `forkable` argument to `True`.
545550

546-
Make sure you are using pip to install a prebuilt package wheel for your system from PyPI, as described in [Using the OneAgent SDK for
547-
Python in your application](#installation). Also make sure you are using an up-to date version of `pip`, `setuptools` and `wheel`. You can
548-
try upgrading them with `python -m pip install --upgrade pip setuptools wheel` (make sure to use the same `python` that you use to install
549-
the `oneagent-sdk` package). ATTENTION: If you use the system-provided pip (e.g. installed via `apt-get` on Ubuntu) you should instead use
550-
a `pip` inside a `virtualenv` (the same as your project), as uprading system-provided packages via `pip` may cause issues.
551+
```python
552+
oneagent.initialize(sdk_options, forkable=True)
553+
```
551554

552-
If this does not resolve the issue, make sure you are using a supported platform, as listed in [Requirements](#requirements). If you *are*
553-
using a supported system, you can try downloading the [OneAgent SDK for C/C++](https://github.com/Dynatrace/OneAgent-SDK-for-C) in the
554-
version corresponding to your OneAgent SDK for Python as listed in [the table in Requirements](#requirements). Then set the
555-
`DT_PYSDK_CSDK_PATH` environment variable to the `.so`/`.dll` file corresponding to your platform in the `lib` subdirectory of the C SDK
556-
and retry the installation (e.g. in a bash shell, use `export DT_PYSDK_CSDK_PATH=path/to/onesdk_shared.so`). If there is no corresponding
557-
directory, your platfom is not supported. Otherwise, regardless if it works with that method or not, please report an issue as desribed in
558-
[Let us help you](#let-us-help-you).
555+
This way you will not be able to use the SDK in the master process (attempts to do so will be ignored, if applicable with
556+
an error code), but all forked child processes will share the same agent. This has a lower overhead, for example the
557+
startup of worker processes is not slowed down, and the per-worker memory overhead is reduced.
559558

559+
For more information on forked child processes, take a look at those resources:
560+
* [Documentation on forking for the Dynatrace OneAgent SDK for C/C++](https://github.com/Dynatrace/OneAgent-SDK-for-C/blob/master/README.md#forking)
561+
* [Forking sample application](./samples/fork-sdk-sample/fork_sdk_sample.py)
562+
563+
<a name="troubleshooting"></a>
564+
## Troubleshooting
560565

566+
<a name="installation-issues"></a>
561567
<a name="post-installation-issues"></a>
562-
### Post-installation issues
563568

564569
To debug your OneAgent SDK for Python installation, execute the following Python code:
565570

@@ -580,6 +585,34 @@ Known gotchas:
580585
Make sure that the `pip install` or equivalent succeeded (see [here](#installation)). Also make sure you use the `pip` corresponding to your
581586
`python` (if in doubt, use `python -m pip` instead of `pip` for installing).
582587

588+
* Output ending in a message like `InitResult=InitResult(status=-2, error=SDKError(-1342308345, 'Failed loading SDK stub from .../site-packages/oneagent/_impl/native/libonesdk_shared.so: "/.../libonesdk_shared.so: cannot open shared object file: No such file or directory". Check your installation of the oneagent-sdk Python package, e.g., try running `pip install --verbose --force-reinstall oneagent-sdk`.'))`.
589+
590+
Follow the advice of the message and run `python -m pip install --verbose --force-reinstall oneagent-sdk`
591+
(or the equivalent pip invocation with the `--verbose` and `--force-reinstall` flags).
592+
It is likely that you will now see another message like
593+
594+
******************************************************************************
595+
*** You are trying to build the Python SDK from source. ***
596+
*** This could mean that you are using an outdated version of pip (older ***
597+
*** than 8.1.0) or you are attempting to install the SDK on an ***
598+
*** unsupported platform. Please check the requirements at ***
599+
*** https://github.com/Dynatrace/OneAgent-SDK-for-Python#requirements ***
600+
******************************************************************************
601+
602+
Make sure you are using pip to install a prebuilt package wheel for your system from PyPI, as described in [Using the OneAgent SDK for
603+
Python in your application](#installation). Also make sure you are using an up-to date version of `pip`, `setuptools` and `wheel`. You can
604+
try upgrading them with `python -m pip install --upgrade pip setuptools wheel` (make sure to use the same `python` that you use to install
605+
the `oneagent-sdk` package). ATTENTION: If you use the system-provided pip (e.g. installed via `apt-get` on Ubuntu) you should instead use
606+
a `pip` inside a `virtualenv` (the same as your project), as upgrading system-provided packages via `pip` may cause issues.
607+
608+
If this does not resolve the issue, make sure you are using a supported platform, as listed in [Requirements](#requirements). If you *are*
609+
using a supported system, you can try downloading the [OneAgent SDK for C/C++](https://github.com/Dynatrace/OneAgent-SDK-for-C) in the
610+
version corresponding to your OneAgent SDK for Python as listed in [the table in Requirements](#requirements). Then set the
611+
`DT_PYSDK_CSDK_PATH` environment variable to the `.so`/`.dll` file corresponding to your platform in the `lib` subdirectory of the C SDK
612+
and retry the installation (e.g. in a bash shell, use `export DT_PYSDK_CSDK_PATH=path/to/onesdk_shared.so`). If there is no corresponding
613+
directory, your platform is not supported. Otherwise, regardless if it works with that method or not, please report an issue as described
614+
in [Let us help you](#let-us-help-you).
615+
583616

584617
<a name="extended-sdk-state"></a>
585618
### Extended SDK State

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
import datetime
3939

40-
from oneagent import __version__ as version
40+
from oneagent.version import __version__ as version
4141

4242
# Fix spurious "= None" for instance attributes
4343
# https://github.com/sphinx-doc/sphinx/issues/2044

pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ good-names=i,j,e,_
1212
max-line-length=100
1313

1414
[TYPECHECK]
15-
ignored-classes=oneagent._impl.native.sdkctypesiface.SDKDllInterface
15+
ignored-classes=oneagent._impl.native.sdkctypesiface.SDKDllInterface,oneagent.sdk.tracers.Tracer
1616
redefining-builtins-modules=oneagent._impl.six.moves
17-
disable=missing-docstring,fixme,too-few-public-methods,missing-return-doc,useless-object-inheritance
17+
disable=missing-docstring,fixme,too-few-public-methods,missing-return-doc,useless-object-inheritance,cyclic-import,import-outside-toplevel

samples/fork-sdk-sample/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# OneAgent SDK for Python forking sample
2+
3+
This example demonstrates how to use the [OneAgent SDK for
4+
Python](https://github.com/Dynatrace/OneAgent-SDK-for-Python) with forked child processes.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Dynatrace LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
'''This example demonstrates how to use the OneAgent SDK for Python in a
18+
parent/child process environment. The OneAgent SDK for Python will be initialized
19+
in the parent process and the child processes can then use the SDK.
20+
21+
Note: this example will only work on Linux. There's no Windows support available.
22+
'''
23+
24+
import os
25+
import sys
26+
27+
import oneagent # SDK initialization functions
28+
import oneagent.sdk as onesdk # All other SDK functions.
29+
30+
try: # Python 2 compatibility.
31+
input = raw_input #pylint:disable=redefined-builtin
32+
except NameError:
33+
pass
34+
35+
36+
getsdk = oneagent.get_sdk # Just to make the code shorter.
37+
38+
39+
def do_some_fancy_stuff(proc_number):
40+
sdk = getsdk()
41+
42+
# The agent state in the child process should be ACTIVE (0).
43+
print('Agent state (child process #{}): {}'.format(proc_number, sdk.agent_state), flush=True)
44+
45+
print('Agent found:', sdk.agent_found)
46+
print('Agent is compatible:', sdk.agent_is_compatible)
47+
print('Agent version:', sdk.agent_version_string)
48+
49+
# This call below will complete the OneAgent for Python SDK initialization and then it
50+
# will start the tracer for tracing the custom service
51+
with sdk.trace_custom_service('my_fancy_transaction', 'MyFancyService #{}'.format(proc_number)):
52+
print('do some fancy stuff')
53+
54+
def create_child_process(proc_number):
55+
pid = os.fork()
56+
if pid == 0:
57+
print('child #{} is running ...'.format(proc_number))
58+
do_some_fancy_stuff(proc_number)
59+
print('child #{} is exiting ...'.format(proc_number))
60+
sys.exit(0)
61+
62+
return pid
63+
64+
def fork_children():
65+
print('now starting children ...', flush=True)
66+
pid_1 = create_child_process(1)
67+
pid_2 = create_child_process(2)
68+
69+
print('waiting for child #1 ...', flush=True)
70+
os.waitpid(pid_1, 0)
71+
print('child #1 exited', flush=True)
72+
73+
print('waiting for child #2 ...', flush=True)
74+
os.waitpid(pid_2, 0)
75+
print('child #2 exited', flush=True)
76+
77+
print('all children exited', flush=True)
78+
79+
def main():
80+
# This gathers arguments prefixed with '--dt_' from sys.argv into the
81+
# returned list. See also the basic-sdk-sample.
82+
sdk_options = oneagent.sdkopts_from_commandline(remove=True)
83+
84+
# Before using the SDK you have to initialize the OneAgent. In this scenario, we
85+
# initialize the SDK and prepare it for forking.
86+
#
87+
# Passing in the sdk_options is entirely optional and usually not required
88+
# as all settings will be automatically provided by the Dynatrace OneAgent
89+
# that is installed on the host.
90+
#
91+
# To activate the forking support add the optional 'forkable' parameter and set it to True.
92+
#
93+
# If you run this example on Windows then you'll get an "Invalid Argument" error back
94+
# because there's no forking support for Windows available.
95+
init_result = oneagent.initialize(sdk_options, forkable=True)
96+
try:
97+
if init_result.error is not None:
98+
print('Error during SDK initialization:', init_result.error)
99+
100+
# While not by much, it is a bit faster to cache the result of
101+
# oneagent.get_sdk() instead of calling the function multiple times.
102+
sdk = getsdk()
103+
104+
# The agent state is one of the integers in oneagent.sdk.AgentState.
105+
# Since we're using the 'forkable' mode the state will be TEMPORARILY_INACTIVE (1) on Linux.
106+
print('Agent state (parent process):', sdk.agent_state)
107+
108+
# The instance attribute 'agent_found' indicates whether an agent could be found or not.
109+
print('Agent found:', sdk.agent_found)
110+
111+
# If an agent was found but it is incompatible with this version of the SDK for Python
112+
# then 'agent_is_compatible' would be set to false.
113+
print('Agent is compatible:', sdk.agent_is_compatible)
114+
115+
# The agent version is a string holding both the OneAgent version and the
116+
# OneAgent SDK for C/C++ version separated by a '/'.
117+
print('Agent version:', sdk.agent_version_string)
118+
119+
if init_result.error is None:
120+
fork_children()
121+
input('Now wait until the path appears in the UI ...')
122+
finally:
123+
shutdown_error = oneagent.shutdown()
124+
if shutdown_error:
125+
print('Error shutting down SDK:', shutdown_error)
126+
127+
if __name__ == '__main__':
128+
main()

samples/fork-sdk-sample/setup.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2018 Dynatrace LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import io
18+
19+
from setuptools import setup
20+
21+
with io.open('README.md', encoding='utf-8') as readmefile:
22+
long_description = readmefile.read()
23+
del readmefile
24+
25+
setup(
26+
py_modules=['fork_sdk_sample'],
27+
zip_safe=True,
28+
name='oneagent-sdk-fork-sample',
29+
version='0.0', # This sample is not separately versioned
30+
31+
install_requires=['oneagent-sdk==1.*,>=1.3'],
32+
33+
description='OneAgent SDK for Python: Fork sample application',
34+
long_description=long_description,
35+
long_description_content_type='text/markdown',
36+
url='https://github.com/Dynatrace/OneAgent-SDK-for-Python',
37+
maintainer='Dynatrace LLC',
38+
maintainer_email='dynatrace.oneagent.sdk@dynatrace.com',
39+
license='Apache License 2.0',
40+
entry_points={
41+
'console_scripts': ['oneagent-sdk-basic-sample=fork_sdk_sample:main'],
42+
},
43+
classifiers=[
44+
'Intended Audience :: Developers',
45+
'License :: OSI Approved',
46+
'License :: OSI Approved :: Apache Software License', # 2.0
47+
'Programming Language :: Python',
48+
'Programming Language :: Python :: 2',
49+
'Programming Language :: Python :: 2.7',
50+
'Programming Language :: Python :: 3',
51+
'Programming Language :: Python :: Implementation :: CPython',
52+
'Operating System :: POSIX :: Linux',
53+
'Operating System :: Microsoft :: Windows',
54+
'Topic :: System :: Monitoring'
55+
])

0 commit comments

Comments
 (0)