Skip to content

Commit b8ac36a

Browse files
committed
Manual sync: v0.1a1.
1 parent a90b9cb commit b8ac36a

File tree

10 files changed

+214
-77
lines changed

10 files changed

+214
-77
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
prune test
22
graft src
3+
global-exclude onesdk_shared.*
34
global-exclude *.pyc
45
global-exclude *.pyo
56
global-exclude __pycache__/*

README.md

Lines changed: 122 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,141 @@
1-
**Disclaimer: This SDK is currently in early access and still work in
2-
progress.**
3-
1+
**Disclaimer: This SDK is currently still work in progress.
2+
Using the OneAgent SDK for Python is COMPLETELY UNSUPPORTED at this stage!**
43

54
# Dynatrace OneAgent SDK for Python
65

76
This SDK enables Dynatrace customers to extend request level visibility into
8-
Python applications.
9-
10-
It provides the Python implementation of the [Dynatrace OneAgent
11-
SDK](https://github.com/Dynatrace/OneAgent-SDK).
12-
13-
14-
## Package contents
15-
16-
- `LICENSE`: License under which the whole SDK and sample applications are
17-
published.
18-
- `src/`: Actual source code of the Python OneAgent SDK.
19-
- `docs/`: Source files for the ([Sphinx](https://sphinx-doc.org)-based) HTML
20-
documentation. For the actual, readable documentation, see
21-
[here](#documenation).
22-
- `tests/`: Contains tests that are useful (only) for developers wanting
23-
contribute to the SDK itself.
24-
- `setup.py`, `setup.cfg`, `MANIFEST.in`: Development Files required for
25-
creating e.g. the PyPI package for the Python OneAgent SDK.
26-
- `tox.ini`, `pylintrc`: Supporting files for developing the SDK itself. See
27-
<https://tox.readthedocs.io/en/latest/> and <https://www.pylint.org/>.
28-
7+
Python applications. It provides the Python implementation of the [Dynatrace OneAgent
8+
SDK](https://github.com/Dynatrace/OneAgent-SDK).
299

3010
## Features
3111

32-
Dynatrace OneAgent SDK for Python currently implements support for the following
33-
features (corresponding to features specified in [Dynatrace OneAgent
12+
The Dynatrace OneAgent SDK for Python currently supports the following features
13+
(corresponding to features specified in [Dynatrace OneAgent
3414
SDK](https://github.com/Dynatrace/OneAgent-SDK)):
3515

3616
- Outgoing and incoming remote calls
3717
- SQL Database requests
3818
- Incoming web requests
3919

20+
## Requirements
21+
22+
The SDK supports Python 2 ≥ 2.7 and Python 3 ≥ 3.4. Only the official CPython
23+
(that is, the "normal" Python, i.e. the Python implementation from
24+
<https://python.org>) is supported.
25+
26+
The Dynatrace OneAgent SDK for Python includes the [Dynatrace OneAgent SDK for
27+
C/C++](https://github.com/Dynatrace/OneAgent-SDK-for-C). See
28+
[here](https://github.com/Dynatrace/OneAgent-SDK-for-C#dynatrace-oneagent-sdk-for-cc-requirements)
29+
for its requirements, which also apply to the SDK for Python.
30+
31+
The version of the SDK for C/C++ that is included in each version of the SDK for
32+
Python is shown in the following table. The SDK for C/C++'s requirement for the
33+
Dynatrace OneAgent is also shown here, for your convenience (it is the same that
34+
is [listed in the OneAgent SDK for C/C++'s
35+
documentation](https://github.com/Dynatrace/OneAgent-SDK-for-C/blob/master/README.md#compatibility-of-dynatrace-oneagent-sdk-for-cc-releases-with-oneagent-releases)).
36+
37+
|OneAgent SDK for Python|OneAgent SDK for C/C++|Dynatrace OneAgent|
38+
|:----------------------|:---------------------|:-----------------|
39+
|0.1 |1.1.0 |≥1.141 |
40+
41+
## Using the OneAgent SDK for Python in your application
42+
43+
<a id="installation"></a>
44+
45+
Once the oneagent SDK is released to PyPI, you will be able to just do `python
46+
-m pip install oneagent-sdk`, to install the SDK.
47+
48+
While the SDK has no public release, please use the wheels provided on the
49+
[GitHub releases
50+
page](https://github.com/Dynatrace/OneAgent-SDK-for-Python/releases), by
51+
giving the additional option
52+
`--find-links DISTIDXURL` to pip (where `DISTIDXURL` is the URL linked on the
53+
GitHub release. This approach also works when
54+
installing packages that depend on the oneagent-sdk package, e.g. `pip install
55+
--find-links DISTIDXURL my-pkg-that-uses-oneagent-sdk`. (Note that this means that
56+
you cannot just use `python setup.py install` for the dependent package. If you
57+
only have a directoy with `setup.py` instead of a proper distribution, use
58+
`python setup.py sdist` and then `pip install --find-links dist --find-links
59+
DISTIDXURL PACKAGENAME`.)
60+
61+
To verify your installation, execute
62+
63+
```bash
64+
python -c "import oneagent; print(oneagent.try_init())"
65+
```
66+
67+
If everything worked, you should get some output ending with
68+
`InitResult(status=0, error=None)`. Otherwise, see
69+
[Troubleshooting](#troubleshooting).
70+
71+
The output should end with `InitResult(status=0, error=None)`.
72+
73+
You then need to load the SDK into the application and add code that traces your
74+
application using the SDK. For a quick “Hello World” that should give you a Path
75+
in the Dynatrace UI, try this:
76+
77+
```python
78+
import oneagent
79+
from oneagent.sdk import SDK
80+
81+
if not oneagent.try_init():
82+
print('Error initializing OneAgent SDK.')
83+
84+
with SDK.get().trace_incoming_remote_call('method', 'service', 'endpoint'):
85+
pass
86+
```
87+
88+
For this, follow the <tests/onesdksamplepy.py>
89+
example (see also the
90+
[documentation](https://dynatrace.github.io/OneAgent-SDK-for-Python/quickstart.html).
4091

4192
## Documentation
4293

43-
The reference documentation is included in this package. The most recent version
44-
is also available online at <https://dynatrace.github.io/OneAgent-SDK-for-Python/>
94+
The most recent version of the documentation can be viewed at
95+
<https://dynatrace.github.io/OneAgent-SDK-for-Python/>.
4596

4697
A high level documentation/description of OneAgent SDK concepts is available at
4798
<https://github.com/Dynatrace/OneAgent-SDK/>.
99+
100+
## Troubleshooting
101+
102+
To debug your OneSDK installation, execute the following Python code:
103+
104+
```python
105+
import oneagent
106+
oneagent.logger.setLevel(0)
107+
init_result = oneagent.try_init(['loglevelsdk=finest', 'loglevel=finest'])
108+
print('InitResult=' + repr(init_result))
109+
```
110+
111+
If you get output containing `InitResult=InitResult(status=0, error=None)`, your
112+
installation should be fine.
113+
114+
Otherwise, hopefully the output is helpful in determining the issue.
115+
116+
Known gotchas:
117+
118+
* `ImportError` or `ModuleNotFoundError` in line 1 that says that there is no
119+
module named `oneagent`.
120+
121+
Make sure that the `pip install` or equivalent succeeded (see
122+
[here](#installation)). Also make sure you use the `pip` corresponding to your
123+
`python` (if in doubt, use `python -m pip` instead of `pip` for installing).
124+
125+
## Repository contents
126+
127+
If you are viewing the [GitHub
128+
repository](https://github.com/Dynatrace/OneAgent-SDK-for-Python), you will see:
129+
130+
- `LICENSE`: License under which the whole SDK and sample applications are
131+
published.
132+
- `src/`: Actual source code of the Python OneAgent SDK.
133+
- `docs/`: Source files for the ([Sphinx](https://sphinx-doc.org)-based) HTML
134+
documentation. For the actual, readable documentation, see
135+
[here](#documenation).
136+
- `tests/`, `test-util-src/`: Contains tests and test support files that are
137+
useful (only) for developers wanting contribute to the SDK itself.
138+
- `setup.py`, `setup.cfg`, `MANIFEST.in`, `project.toml`: Development files
139+
required for creating e.g. the PyPI package for the Python OneAgent SDK.
140+
- `tox.ini`, `pylintrc`: Supporting files for developing the SDK itself. See
141+
<https://tox.readthedocs.io/en/latest/> and <https://www.pylint.org/>.

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# import sys
2222
# sys.path.insert(0, os.path.abspath('.'))
2323

24+
from oneagent import __version__ as version
25+
2426
# Fix spurious "= None" for instance attributes
2527
# https://github.com/sphinx-doc/sphinx/issues/2044
2628
from sphinx.ext.autodoc import (
@@ -69,9 +71,9 @@ def iad_add_directive_header(self, sig):
6971
# built documents.
7072
#
7173
# The short X.Y version.
72-
version = ''
74+
#version = '' # see import above
7375
# The full version, including alpha/beta/rc tags.
74-
release = ''
76+
release = version
7577

7678
# The language for content autogenerated by Sphinx. Refer to documentation
7779
# for a list of supported languages.

project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://www.python.org/dev/peps/pep-0518/
2+
[build-system]
3+
# http://setuptools.readthedocs.io/en/latest/history.html#v36-4-0
4+
# Required for Description-Content-Type
5+
requires = ["setuptools>=36.4"]

setup.py

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#! /usr/bin/env python3
22

3+
# Beware when cross-building 64/32 bit:
4+
# When using --plat-name to override this, make sure to `rm -r build` othewise
5+
# files from the wrong platform might be reused.
6+
# Also, on Linux because of https://bugs.python.org/issue18987, using a 32 bit
7+
# Python on a 64 bit OS is not enough to change the platform tag.
8+
39
from __future__ import print_function
410

511
import io
612
import os
713
from os import path
14+
import re
815

916
# https://github.com/PyCQA/pylint/issues/73
1017
#pylint:disable=no-name-in-module,import-error
@@ -24,10 +31,26 @@
2431

2532
CSDK_ENV_NAME = 'DT_PYSDK_CSDK_PATH'
2633

27-
with io.open('README.md', encoding='utf-8') as readmefile:
34+
_THIS_DIR = path.dirname(path.abspath(__file__))
35+
36+
with io.open(path.join(_THIS_DIR, 'README.md'), encoding='utf-8') as readmefile:
2837
long_description = readmefile.read()
2938
del readmefile
3039

40+
VER_RE = re.compile(r"^__version__ = '([^']+)'$")
41+
42+
verfilepath = path.join(_THIS_DIR, 'src/oneagent/__init__.py')
43+
with io.open(verfilepath, encoding='utf-8') as verfile:
44+
for line in verfile:
45+
match = VER_RE.match(line)
46+
if match:
47+
__version__ = match.group(1)
48+
break
49+
else:
50+
raise AssertionError('Version not found in src/oneagent/__init__.py')
51+
del match, verfile, verfilepath, VER_RE
52+
53+
3154
def compilefile(fname, mode='exec'):
3255
with open(fname) as srcfile:
3356
codestr = srcfile.read()
@@ -63,7 +86,8 @@ def get_tag(self):
6386
def get_dll_info(plat_name):
6487
dll_info = {}
6588
#pylint:disable=exec-used
66-
exec(compilefile('src/oneagent/_impl/native/sdkdllinfo.py'), dll_info)
89+
infopath = path.join(_THIS_DIR, 'src/oneagent/_impl/native/sdkdllinfo.py')
90+
exec(compilefile(infopath), dll_info)
6791
if plat_name:
6892
is_win32 = plat_name.startswith('win')
6993
is_64bit = plat_name.endswith('64')
@@ -158,39 +182,44 @@ def has_ext_modules(self): #pylint:disable=no-self-use
158182
if bdist_wheel is not None:
159183
cmdclss['bdist_wheel'] = BdistWheel
160184

161-
setup(
162-
packages=find_packages('src'),
163-
package_dir={'': 'src'},
164-
include_package_data=True,
165-
zip_safe=True,
166-
python_requires='>=2.7,!=3.0,!=3.1,!=3.2,!=3.3',
167-
cmdclass=cmdclss,
168-
name='oneagent-sdk',
169-
version='0.1',
170-
distclass=BinaryDistribution,
171-
172-
description='Dynatrace OneAgent SDK for Python',
173-
long_description=long_description,
174-
url='https://www.dynatrace.com/',
175-
maintainer='Dynatrace LLC',
176-
maintainer_email='[email protected]',
177-
license='Apache License 2.0',
178-
classifiers=[
179-
'Development Status :: 2 - Pre-Alpha',
180-
'Intended Audience :: Developers',
181-
'License :: OSI Approved :: Apache Software License', # 2.0
182-
'Programming Language :: Python',
183-
'Programming Language :: Python :: 2',
184-
'Programming Language :: Python :: 2.7',
185-
'Programming Language :: Python :: 3',
186-
'Programming Language :: Python :: 3.3',
187-
'Programming Language :: Python :: 3.4',
188-
'Programming Language :: Python :: 3.5',
189-
'Programming Language :: Python :: 3.6',
190-
'Programming Language :: Python :: Implementation :: CPython',
191-
#'Programming Language :: Python :: Implementation :: PyPy',
192-
'Operating System :: POSIX :: Linux',
193-
'Operating System :: Microsoft :: Windows',
194-
'Topic :: Software Development :: Libraries',
195-
'Topic :: System :: Monitoring'
196-
])
185+
def main():
186+
setup(
187+
packages=find_packages('src'),
188+
package_dir={'': 'src'},
189+
include_package_data=True,
190+
zip_safe=True,
191+
python_requires='>=2.7,!=3.0,!=3.1,!=3.2,!=3.3',
192+
cmdclass=cmdclss,
193+
name='oneagent-sdk',
194+
version=__version__,
195+
distclass=BinaryDistribution,
196+
197+
description='Dynatrace OneAgent SDK for Python',
198+
long_description=long_description,
199+
long_description_content_type='text/markdown',
200+
url='https://www.dynatrace.com/',
201+
maintainer='Dynatrace LLC',
202+
maintainer_email='[email protected]',
203+
license='Apache License 2.0',
204+
classifiers=[
205+
'Development Status :: 2 - Pre-Alpha',
206+
'Intended Audience :: Developers',
207+
'License :: OSI Approved :: Apache Software License', # 2.0
208+
'Programming Language :: Python',
209+
'Programming Language :: Python :: 2',
210+
'Programming Language :: Python :: 2.7',
211+
'Programming Language :: Python :: 3',
212+
'Programming Language :: Python :: 3.3',
213+
'Programming Language :: Python :: 3.4',
214+
'Programming Language :: Python :: 3.5',
215+
'Programming Language :: Python :: 3.6',
216+
'Programming Language :: Python :: Implementation :: CPython',
217+
#'Programming Language :: Python :: Implementation :: PyPy',
218+
'Operating System :: POSIX :: Linux',
219+
'Operating System :: Microsoft :: Windows',
220+
'Topic :: Software Development :: Libraries',
221+
'Topic :: System :: Monitoring'
222+
])
223+
224+
if __name__ == '__main__':
225+
main()

src/oneagent/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
The :class:`logging.Logger` on which managed Python SDK messages will be
77
written.
88
9-
This logger is not specially configured in any way. Unless you configure
10-
this or the root logger yourself, you won't see any output. See
11-
:ref:`logging-basic-tutorial` in the official Python documentation.
9+
This logger has set the log level so that no messages are displayed by
10+
default. Use e.g. :code:`oneagent.logger.setLevel(logging.INFO)` to see
11+
them. See :ref:`logging-basic-tutorial` in the official Python
12+
documentation for more on configuring the logger.
1213
1314
.. class:: InitResult
1415
@@ -70,7 +71,12 @@
7071
from .common import SDKError, ErrorCode
7172
from ._impl.native import nativeagent
7273

74+
# See https://www.python.org/dev/peps/pep-0440/ "Version Identification and
75+
# Dependency Specification"
76+
__version__ = '0.1a1'
77+
7378
logger = logging.getLogger('py_sdk')
79+
logger.setLevel(logging.CRITICAL + 1) # Disabled by default
7480

7581
class InitResult(namedtuple('InitResult', 'status error')):
7682
__slots__ = ()

src/oneagent/_impl/native/sdkctypesiface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def __init__(self, libname):
166166
initfn(
167167
'stub_set_logging_level',
168168
(log_level_t,),
169-
result_t)
169+
None)
170170
initfn(
171171
'stub_default_logging_function',
172172
(log_level_t, XStrPInArg),

src/oneagent/_impl/native/sdkmockiface.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ def stub_set_logging_level(self, level):
337337
_typecheck(level, int)
338338
if level < MessageSeverity.FINEST or level > MessageSeverity.DEBUG:
339339
warnings.warn('Bad message severity level.', RuntimeWarning)
340-
return ErrorCode.INVALID_ARGUMENT
341-
return ErrorCode.SUCCESS
342340

343341
def stub_default_logging_function(self, level, msg):
344342
print('[OneSDK:Mock]', level, msg, file=sys.stderr)

0 commit comments

Comments
 (0)