Skip to main content

Instrumenting

install

  • install with your favorite Python package manager
pip3 install shopcloud-django-instrumenting

LogRequestMiddleware

add additional Information from request in AppEngine to Log

usage

add to MIDDLEWARE in django-app settings.py:

MIDDLEWARE = [
    ...
    'shopcloud_django_instrumenting.middleware.LogRequestMiddleware',
]

tracing

from shopcloud_django_instrumenting import tracing

tr = tracing.Tracer('name_of_service', 'name_of_operation')
with tr.start_span('event.processing') as span:
    pass

data = tr.close()

error management

A special layer on top of the API is the error boundary within the with blocks of spans. This layer catches exceptions and prints them. The pattern here is to catch all runtime errors and return a 422 status, indicating that an unexpected error has occurred, not a validation error. If you need to return validation data to the user, you must return a Result object on your own.

@action(detail=True, methods=["post"], url_path="my-action")
def my_action(self, request, pk):
    tr = tracing.DjangoAPITracer(request)

    serializer = serializers.ProductSyncSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)

    with tr.start_span('proceed') as span:
        raise Exception('something unhandle')

    trace_data = tr.close()
    return Response({
        'trace': trace_data,
    }, status=status.HTTP_201_CREATED if tr.is_success else status.HTTP_422_UNPROCESSABLE_ENTITY)

Another pattern to note is that every with block should contain a repeatable operation. You can create structures where you can run blocks side by side and only repeat some of them. However, be careful: while the with block catches exceptions, it may not guarantee that all variables are set.

tr = tracing.DjangoAPITracer(request)

is_a_success = False
is_b_success = False
is_c_success = False

with tr.start_span('A') as span_a:
    is_a_success = False

with tr.start_span('B') as span_b:
    is_b_success = True

with tr.start_span('C') as span_c:
    if is_a_success:
        pass

develop

$ pytest
$ pip3 install coverage
# shell report
$ coverage run -m pytest  && coverage report --show-missing
# html report
$ coverage run -m pytest  && coverage html
$ cd htmlcov
$ python3 -m http.server

Metadata

Release files for shopcloud-django-instrumenting 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shopcloud-django-instrumenting 1.6.0
File Size Uploaded Provenance Actions
shopcloud_django_instrumenting-1.6.0.tar.gz 6.9 kB Without provenance Details for shopcloud_django_instrumenting-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shopcloud-django-instrumenting 1.6.0
File Interpreter ABI Platform Actions
shopcloud_django_instrumenting-1.6.0-py3-none-any.whl Python 3 none any Details for shopcloud_django_instrumenting-1.6.0-py3-none-any.whl

Total release size: 13.7 kB

Release files / shopcloud_django_instrumenting-1.6.0.tar.gz

Download URL shopcloud_django_instrumenting-1.6.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
af40a6d62572facc76d03dbc49b5ce6d64ba46cb2f6741e1b1fa67ba5e9c5c76
BLAKE2b-256 checksum
How to use checksums
a73e61de94dcda203b053a1f886555d06b4532d6a53ff255e1a85d00ad6d72a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / shopcloud_django_instrumenting-1.6.0-py3-none-any.whl

Download URL shopcloud_django_instrumenting-1.6.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2efc762e9c736e7e49c0b09003daa39da34ecbd0d6c29ae1e417ba66635c43d1
BLAKE2b-256 checksum
How to use checksums
72b653931067fff8fc40e025e2a86b20829eff52ae66b7aeb0579a9b53e5a0eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Security for shopcloud-django-instrumenting 1.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page