# Opentelemetry auto instrumentation for django-stomp
[//]: # ([](https://dev.azure.com/juntos-somos-mais-loyalty/python/_build/latest?definitionId=272&branchName=main))
[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_opentelemetry-instrumentation-django-stomp)
[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_opentelemetry-instrumentation-django-stomp)
[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_opentelemetry-instrumentation-django-stomp)
[](https://github.com/ambv/black)
[](https://badge.fury.io/py/opentelemetry-instrumentation-django-stomp)
[](https://github.com/juntossomosmais/opentelemetry-instrumentation-django-stomp/blob/main/LICENSE)
This library will help you to use opentelemetry traces and metrics on [Django STOMP](https://github.com/juntossomosmais/django-stomp) usage library.

#### Installation
pip install `opentelemetry-instrumentation-django-stomp`
#### How to use ?
You can use the `DjangoStompInstrumentor().instrument()` for example in `manage.py` file.
```python
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import typing
from opentelemetry_instrumentation_django_stomp import DjangoStompInstrumentor
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.trace.span import Span
def publisher_hook(span: Span, body: typing.Dict, headers: typing.Dict):
# Custom code in your project here we can see span attributes and make custom logic with then.
pass
def consumer_hook(span: Span, body: typing.Dict, headers: typing.Dict):
# Custom code in your project here we can see span attributes and make custom logic with then.
pass
provider = TracerProvider()
trace.set_tracer_provider(provider)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "application.settings")
DjangoStompInstrumentor().instrument(
trace_provider=trace,
publisher_hook=publisher_hook,
consumer_hook=consumer_hook,
)
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()
```
The code above will create telemetry wrappers inside django-stomp code and creates automatic spans with broker data.
The `DjangoStompInstrumentor` can receive three optional parameters:
- **trace_provider**: The tracer provider to use in open-telemetry spans.
- **publisher_hook**: The callable function on publisher action to call before the original function call, use this to override, enrich the span or get span information in the main project.
- **consumer_hook**: The callable function on consumer action to call before the original function call, use this to override, enrich the span or get span information in the main project.
:warning: The hook function will not raise an exception when an error occurs inside hook function, only a warning log is generated
### Span Generated
#### send {destination}
With the django-stomp, we can publish a message to a broker using `publisher.send` and the instrumentator
can include a span with telemetry data in this function utilization.
```python
from uuid import uuid4
from django_stomp.builder import build_publisher
publisher = build_publisher(f"publisher-unique-name-{uuid4()}")
publisher.send(
queue='/queue/a-destination',
body={"a": "random","body": "message"},
)
```
The publisher span had `send {destination}` name.

#### CONSUMER
With the django-stomp, we create a simple consumer using pubsub command and the instrumentator
can include a span with telemetry data in this function utilization.
```bash
python manage.py pubsub QUEUE_NAME callback_function_to_consume_message
```
Consumer spans can generate up to three types:
- process {destination}

- ack {destination}

- nack {destination}

#### Supress django-stomp traces and metrics
When the flag `OTEL_PYTHON_DJANGO_STOMP_INSTRUMENT` has `False` value traces and metrics will not be generated.
Use this to supress the django-stomp instrumentation.
#### HOW TO CONTRIBUTE ?
Look the [contributing](./CONTRIBUTING.md) specs
Raw data
{
"_id": null,
"home_page": "https://github.com/juntossomosmais/opentelemetry-instrumentation-django-stomp",
"name": "opentelemetry-instrumentation-django-stomp",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "django-stomp, stomp, django, opentelemetry, instrumentation",
"author": "Juntos Somos Mais",
"author_email": "labs@juntossomosmais.com.br",
"download_url": "https://files.pythonhosted.org/packages/6c/0a/41945f28ef6def3b8fc238ac85fb6ca302fed2811913a89f6c3c8fe8ec7e/opentelemetry_instrumentation_django_stomp-0.4.0.tar.gz",
"platform": null,
"description": "# Opentelemetry auto instrumentation for django-stomp\n\n[//]: # ([](https://dev.azure.com/juntos-somos-mais-loyalty/python/_build/latest?definitionId=272&branchName=main))\n[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_opentelemetry-instrumentation-django-stomp)\n[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_opentelemetry-instrumentation-django-stomp)\n[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_opentelemetry-instrumentation-django-stomp)\n[](https://github.com/ambv/black)\n[](https://badge.fury.io/py/opentelemetry-instrumentation-django-stomp)\n[](https://github.com/juntossomosmais/opentelemetry-instrumentation-django-stomp/blob/main/LICENSE)\n\nThis library will help you to use opentelemetry traces and metrics on [Django STOMP](https://github.com/juntossomosmais/django-stomp) usage library.\n\n\n\n\n#### Installation\npip install `opentelemetry-instrumentation-django-stomp`\n\n#### How to use ?\n\nYou can use the `DjangoStompInstrumentor().instrument()` for example in `manage.py` file.\n\n\n```python\n#!/usr/bin/env python\n\"\"\"Django's command-line utility for administrative tasks.\"\"\"\nimport os\nimport sys\nimport typing\n\nfrom opentelemetry_instrumentation_django_stomp import DjangoStompInstrumentor\n\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter\nfrom opentelemetry.trace.span import Span\n\n\ndef publisher_hook(span: Span, body: typing.Dict, headers: typing.Dict):\n # Custom code in your project here we can see span attributes and make custom logic with then.\n pass\n\n\ndef consumer_hook(span: Span, body: typing.Dict, headers: typing.Dict):\n # Custom code in your project here we can see span attributes and make custom logic with then.\n pass\n\n\nprovider = TracerProvider()\ntrace.set_tracer_provider(provider)\ntrace.get_tracer_provider().add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))\n\ndef main():\n os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"application.settings\")\n DjangoStompInstrumentor().instrument(\n trace_provider=trace,\n publisher_hook=publisher_hook,\n consumer_hook=consumer_hook,\n )\n try:\n from django.core.management import execute_from_command_line\n except ImportError as exc:\n raise ImportError(\n \"Couldn't import Django. Are you sure it's installed and \"\n \"available on your PYTHONPATH environment variable? Did you \"\n \"forget to activate a virtual environment?\"\n ) from exc\n execute_from_command_line(sys.argv)\n\n\nif __name__ == \"__main__\":\n main()\n```\n\nThe code above will create telemetry wrappers inside django-stomp code and creates automatic spans with broker data.\n\nThe `DjangoStompInstrumentor` can receive three optional parameters:\n- **trace_provider**: The tracer provider to use in open-telemetry spans.\n- **publisher_hook**: The callable function on publisher action to call before the original function call, use this to override, enrich the span or get span information in the main project.\n- **consumer_hook**: The callable function on consumer action to call before the original function call, use this to override, enrich the span or get span information in the main project.\n\n:warning: The hook function will not raise an exception when an error occurs inside hook function, only a warning log is generated\n\n### Span Generated\n\n#### send {destination}\n\nWith the django-stomp, we can publish a message to a broker using `publisher.send` and the instrumentator\ncan include a span with telemetry data in this function utilization.\n\n```python\n from uuid import uuid4\n from django_stomp.builder import build_publisher\n publisher = build_publisher(f\"publisher-unique-name-{uuid4()}\")\n publisher.send(\n queue='/queue/a-destination',\n body={\"a\": \"random\",\"body\": \"message\"},\n )\n```\n\nThe publisher span had `send {destination}` name.\n\n\n\n#### CONSUMER\nWith the django-stomp, we create a simple consumer using pubsub command and the instrumentator\ncan include a span with telemetry data in this function utilization.\n\n```bash\n python manage.py pubsub QUEUE_NAME callback_function_to_consume_message\n```\n\nConsumer spans can generate up to three types:\n\n- process {destination}\n\n- ack {destination}\n\n- nack {destination}\n\n\n#### Supress django-stomp traces and metrics\nWhen the flag `OTEL_PYTHON_DJANGO_STOMP_INSTRUMENT` has `False` value traces and metrics will not be generated.\nUse this to supress the django-stomp instrumentation.\n\n#### HOW TO CONTRIBUTE ?\nLook the [contributing](./CONTRIBUTING.md) specs\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Opentelemetry instrumentor for django-stomp package",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/juntossomosmais/opentelemetry-instrumentation-django-stomp",
"Repository": "https://github.com/juntossomosmais/opentelemetry-instrumentation-django-stomp"
},
"split_keywords": [
"django-stomp",
" stomp",
" django",
" opentelemetry",
" instrumentation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c789fb58a78de6ffcd30ec433f188b0ff9c1f3f9d252f7352c38ae57a8cc8a1",
"md5": "b06c2b98095f05db3b558d00b7823e50",
"sha256": "9225036fa1f4788dd4309ef7314ba516b9813a042626d4b61eea171e342ab75c"
},
"downloads": -1,
"filename": "opentelemetry_instrumentation_django_stomp-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b06c2b98095f05db3b558d00b7823e50",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 12806,
"upload_time": "2025-09-05T18:41:08",
"upload_time_iso_8601": "2025-09-05T18:41:08.703476Z",
"url": "https://files.pythonhosted.org/packages/9c/78/9fb58a78de6ffcd30ec433f188b0ff9c1f3f9d252f7352c38ae57a8cc8a1/opentelemetry_instrumentation_django_stomp-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6c0a41945f28ef6def3b8fc238ac85fb6ca302fed2811913a89f6c3c8fe8ec7e",
"md5": "002ee9b52c8cc1648de8c33bf2dd4deb",
"sha256": "40b942621b39542e1bccf0f1160e8f8364f2f8fba6d8a6e4ac6eefd89ea748b3"
},
"downloads": -1,
"filename": "opentelemetry_instrumentation_django_stomp-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "002ee9b52c8cc1648de8c33bf2dd4deb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 9564,
"upload_time": "2025-09-05T18:41:09",
"upload_time_iso_8601": "2025-09-05T18:41:09.514254Z",
"url": "https://files.pythonhosted.org/packages/6c/0a/41945f28ef6def3b8fc238ac85fb6ca302fed2811913a89f6c3c8fe8ec7e/opentelemetry_instrumentation_django_stomp-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-05 18:41:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "juntossomosmais",
"github_project": "opentelemetry-instrumentation-django-stomp",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"tox": true,
"lcname": "opentelemetry-instrumentation-django-stomp"
}