Skip to content

Instantly share code, notes, and snippets.

View federicobond's full-sized avatar

Federico Bond federicobond

View GitHub Profile
@federicobond
federicobond / django_extras_instrumentor.py
Last active May 7, 2024 09:10
OpenTelemetry Instrumentor for tracing Django management command calls
from functools import wraps
from django.core.management.base import BaseCommand
from opentelemetry import trace
from opentelemetry.instrumentation.django_extras.package import _instruments
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
_COMMAND_TRACE_PREFIX = "command/"
_DJANGO_COMMAND_KEY = "django.command"
@federicobond
federicobond / mypy_celery_plugin.py
Created February 24, 2025 01:43
Mypy Celery plugin to patch the return type of shared_task and Celery.task decorators with a Django-specific task class.
from collections.abc import Callable
from mypy.nodes import MypyFile
from mypy.plugin import FunctionContext, MethodContext, Plugin
from mypy.types import CallableType, Instance, Type, get_proper_type
DJANGO_TASK_FULLNAME = "celery.contrib.django.task.DjangoTask"
class CeleryPlugin(Plugin):