diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d6912d9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 TraceReq + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index ffc58ee..db0c64a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is the Python SDK for [TraceReq](http://tracereq.com/) ## Installation ```bash -pip install --upgrade tracereq +pip install --upgrade tracereq-sdk ``` ## Usage with Flask diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7cb18ec --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,55 @@ +# pyproject.toml + +[build-system] +requires = ["setuptools>=61.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "tracereq-sdk" +version = "1.0.0" +description = "Python client for TraceReq (https://tracereq.com)" +readme = "README.md" +authors = [ + { name = "Prateek Sachan", email = "ps@prateeksachan.com" } +] +license = { file = "LICENSE" } +classifiers = [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", +] +keywords = ["flask", "trace", "api"] +dependencies = [ + 'urllib3>=1.26.16; python_version >="3.6"' +] +requires-python = ">=3.6" + +[project.optional-dependencies] +dev = ["pip-tools"] + +[project.urls] +Homepage = "https://github.com/tracereq/python-tracereq-sdk" + +[tool.bumpver] +current_version = "1.0.0" +version_pattern = "MAJOR.MINOR.PATCH" +commit_message = "bump version {old_version} -> {new_version}" +tag_message = "{new_version}" +tag_scope = "default" +commit = true +tag = true +push = false + +[tool.bumpver.file_patterns] +"pyproject.toml" = [ + 'current_version = "{version}"', +] +"setup.py" = [ + "{version}", + "{pep440_version}", +] +"README.md" = [ + "{version}", + "{pep440_version}", +] + diff --git a/setup.py b/setup.py deleted file mode 100644 index db3fd67..0000000 --- a/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name='tracereq', - setup_requires=['wheel'], - packages=['tracereq'], - include_package_data=True, - version='1.0.0', - author='Prateek Sachan', - author_email="ps@prateeksachan.com", - license='MIT', - python_requires=">=3.6", - install_requires=['urllib3>=1.26.11; python_version >="3.6"'] -) diff --git a/tracereq/__init__.py b/tracereq/__init__.py index 7631bad..6aeb3ae 100644 --- a/tracereq/__init__.py +++ b/tracereq/__init__.py @@ -1,48 +1,6 @@ -from threading import Lock +from tracereq.api import * -_installer_lock = Lock() -_installed_integrations = {} - -def get_core_integrations(): - from .customlib import CustomlibIntegration - yield CustomlibIntegration() - - -def get_custom_integrations(**kwargs): - if kwargs.get('flask_app'): - from .flasklib import FlasklibIntegration - yield FlasklibIntegration(kwargs.get('flask_app')) - - -def setup_integrations(*args, **kwargs): - integrations = list() - - core_integrations = get_core_integrations() - custom_integrations = get_custom_integrations(**kwargs) - for instance in core_integrations: - if not any(isinstance(x, type(instance)) for x in integrations): - integrations.append(instance) - - for instance in custom_integrations: - if not any(isinstance(x, type(instance)) for x in integrations): - integrations.append(instance) - - for integration in integrations: - integration() - - -class Integration(object): - integration_key = None - - def install(self): - raise NotImplementedError() - - def __call__(self, environ=None, start_response=None): - assert self.integration_key - with _installer_lock: - if self.integration_key in _installed_integrations: - return - - self.install() - _installed_integrations[self.integration_key] = self +__all__ = [ + "init" +] diff --git a/tracereq/api.py b/tracereq/api.py index 93fbaba..6a37fa8 100644 --- a/tracereq/api.py +++ b/tracereq/api.py @@ -1,6 +1,6 @@ from .engine import Engine from .client import Client -from . import setup_integrations +from .integrations import setup_integrations __all__ = ['Engine', 'Client'] diff --git a/tracereq/client.py b/tracereq/client.py index 7f50100..0682a96 100644 --- a/tracereq/client.py +++ b/tracereq/client.py @@ -5,7 +5,7 @@ class Client(object): def __init__( self, - api_key: str = '', + api_key, *args, **kwargs ): diff --git a/tracereq/customlib.py b/tracereq/customlib.py index 98b7122..ad0f903 100644 --- a/tracereq/customlib.py +++ b/tracereq/customlib.py @@ -1,4 +1,4 @@ -from . import Integration +from .integrations import Integration from .engine import Engine from .constants import HEADER_NAME, DESTINATION_URL from urllib.parse import urlsplit diff --git a/tracereq/integrations/__init__.py b/tracereq/integrations/__init__.py new file mode 100644 index 0000000..2e2e29e --- /dev/null +++ b/tracereq/integrations/__init__.py @@ -0,0 +1,48 @@ +from threading import Lock + +_installer_lock = Lock() +_installed_integrations = {} + + +def get_core_integrations(): + from tracereq.customlib import CustomlibIntegration + yield CustomlibIntegration() + + +def get_custom_integrations(**kwargs): + if kwargs.get('flask_app'): + from .flasklib import FlasklibIntegration + yield FlasklibIntegration(kwargs.get('flask_app')) + + +def setup_integrations(*args, **kwargs): + integrations = list() + + core_integrations = get_core_integrations() + custom_integrations = get_custom_integrations(**kwargs) + for instance in core_integrations: + if not any(isinstance(x, type(instance)) for x in integrations): + integrations.append(instance) + + for instance in custom_integrations: + if not any(isinstance(x, type(instance)) for x in integrations): + integrations.append(instance) + + for integration in integrations: + integration() + + +class Integration(object): + integration_key = None + + def install(self): + raise NotImplementedError() + + def __call__(self, environ=None, start_response=None): + assert self.integration_key + with _installer_lock: + if self.integration_key in _installed_integrations: + return + + self.install() + _installed_integrations[self.integration_key] = self diff --git a/tracereq/flasklib.py b/tracereq/integrations/flasklib.py similarity index 89% rename from tracereq/flasklib.py rename to tracereq/integrations/flasklib.py index 574a7b9..b3e8f16 100644 --- a/tracereq/flasklib.py +++ b/tracereq/integrations/flasklib.py @@ -1,8 +1,8 @@ from flask import Flask, _request_ctx_stack from flask.signals import request_started, request_finished from . import Integration -from .engine import Engine -from .tracing import generate_trace_event, Trace, generalize_request +from tracereq.engine import Engine +from tracereq.tracing import generate_trace_event, Trace, generalize_request class FlasklibIntegration(Integration):