Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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}",
]

14 changes: 0 additions & 14 deletions setup.py

This file was deleted.

50 changes: 4 additions & 46 deletions tracereq/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
]
2 changes: 1 addition & 1 deletion tracereq/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .engine import Engine
from .client import Client
from . import setup_integrations
from .integrations import setup_integrations

__all__ = ['Engine', 'Client']

Expand Down
2 changes: 1 addition & 1 deletion tracereq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Client(object):
def __init__(
self,
api_key: str = '',
api_key,
*args,
**kwargs
):
Expand Down
2 changes: 1 addition & 1 deletion tracereq/customlib.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 48 additions & 0 deletions tracereq/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tracereq/flasklib.py → tracereq/integrations/flasklib.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down