tp-trace 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. tp_trace-0.4.0/PKG-INFO +177 -0
  2. tp_trace-0.4.0/README.md +145 -0
  3. {tp_trace-0.3.0 → tp_trace-0.4.0}/pyproject.toml +1 -1
  4. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/__init__.py +12 -26
  5. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/config.py +0 -30
  6. tp_trace-0.4.0/src/tp_trace/exporter.py +280 -0
  7. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/middleware.py +114 -1
  8. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/request.py +61 -86
  9. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/metrics.py +31 -308
  10. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/normalize.py +23 -0
  11. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/version.py +1 -1
  12. tp_trace-0.4.0/src/tp_trace.egg-info/PKG-INFO +177 -0
  13. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace.egg-info/SOURCES.txt +0 -3
  14. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_django.py +203 -28
  15. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_django_migration_regressions.py +6 -18
  16. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_init.py +218 -0
  17. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_metrics.py +118 -277
  18. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_n_plus_one.py +7 -9
  19. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_n_plus_one_dashboard_contract.py +114 -34
  20. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_red_comparison.py +2 -2
  21. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_red_dashboard_contract.py +201 -49
  22. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_safety.py +103 -0
  23. tp_trace-0.3.0/PKG-INFO +0 -67
  24. tp_trace-0.3.0/README.md +0 -35
  25. tp_trace-0.3.0/src/tp_trace/exporter.py +0 -144
  26. tp_trace-0.3.0/src/tp_trace/red.py +0 -317
  27. tp_trace-0.3.0/src/tp_trace.egg-info/PKG-INFO +0 -67
  28. tp_trace-0.3.0/tests/test_cardinality_diagnostics.py +0 -386
  29. tp_trace-0.3.0/tests/test_red.py +0 -880
  30. {tp_trace-0.3.0 → tp_trace-0.4.0}/setup.cfg +0 -0
  31. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/compat/__init__.py +0 -0
  32. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/compat/attributes.py +0 -0
  33. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/config_access.py +0 -0
  34. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/__init__.py +0 -0
  35. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/base.py +0 -0
  36. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/boto/__init__.py +0 -0
  37. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/boto/integration.py +0 -0
  38. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/celery/__init__.py +0 -0
  39. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/celery/context.py +0 -0
  40. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/celery/instrumentor.py +0 -0
  41. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/celery/integration.py +0 -0
  42. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/__init__.py +0 -0
  43. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/auth.py +0 -0
  44. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/cache.py +0 -0
  45. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/compat.py +0 -0
  46. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/integration.py +0 -0
  47. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/template.py +0 -0
  48. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/django/view.py +0 -0
  49. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/manager.py +0 -0
  50. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/postgres/__init__.py +0 -0
  51. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/postgres/cursor.py +0 -0
  52. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/postgres/integration.py +0 -0
  53. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/redis/__init__.py +0 -0
  54. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/redis/integration.py +0 -0
  55. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/requests/__init__.py +0 -0
  56. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/requests/client.py +0 -0
  57. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/integrations/requests/integration.py +0 -0
  58. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/propagator.py +0 -0
  59. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/route_context.py +0 -0
  60. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/safety.py +0 -0
  61. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/sampler.py +0 -0
  62. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/sanitize.py +0 -0
  63. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace/tracing.py +0 -0
  64. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace.egg-info/dependency_links.txt +0 -0
  65. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace.egg-info/requires.txt +0 -0
  66. {tp_trace-0.3.0 → tp_trace-0.4.0}/src/tp_trace.egg-info/top_level.txt +0 -0
  67. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_base_integration.py +0 -0
  68. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_boto.py +0 -0
  69. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_celery_integration.py +0 -0
  70. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_celery_probe.py +0 -0
  71. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_django_advanced.py +0 -0
  72. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_django_safety_regressions.py +0 -0
  73. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_postgres.py +0 -0
  74. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_redis.py +0 -0
  75. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_requests.py +0 -0
  76. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_sample_telemetry.py +0 -0
  77. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_sampling_rules.py +0 -0
  78. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_sanitization_regressions.py +0 -0
  79. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_shared_config.py +0 -0
  80. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_smoke_probe.py +0 -0
  81. {tp_trace-0.3.0 → tp_trace-0.4.0}/tests/test_traffic_generator.py +0 -0
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: tp_trace
3
+ Version: 0.4.0
4
+ Summary: tp_trace: High-performance Python Observability SDK for OpenTelemetry
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: opentelemetry-api>=1.20.0
8
+ Requires-Dist: opentelemetry-sdk>=1.20.0
9
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.20.0
10
+ Requires-Dist: opentelemetry-instrumentation-requests>=0.44b0
11
+ Requires-Dist: opentelemetry-instrumentation-psycopg2>=0.44b0
12
+ Requires-Dist: opentelemetry-instrumentation-redis>=0.44b0
13
+ Requires-Dist: opentelemetry-instrumentation-botocore>=0.44b0
14
+ Requires-Dist: opentelemetry-instrumentation-celery>=0.54b1
15
+ Requires-Dist: opentelemetry-instrumentation-django>=0.44b0
16
+ Requires-Dist: wrapt>=1.14.0
17
+ Requires-Dist: urllib3<2,>=1.26.0; python_version < "3.9"
18
+ Provides-Extra: django
19
+ Requires-Dist: django>=4.2; extra == "django"
20
+ Requires-Dist: opentelemetry-instrumentation-django>=0.44b0; extra == "django"
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
23
+ Requires-Dist: botocore>=1.37.38; extra == "dev"
24
+ Requires-Dist: build>=1.0.0; extra == "dev"
25
+ Requires-Dist: requests>=2.25.0; extra == "dev"
26
+ Requires-Dist: redis>=3.5.0; extra == "dev"
27
+ Requires-Dist: celery>=5.0; extra == "dev"
28
+ Requires-Dist: django>=4.2; extra == "dev"
29
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
30
+ Requires-Dist: mypy>=1.0.0; python_version >= "3.10" and extra == "dev"
31
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
32
+
33
+ # tp_trace
34
+
35
+ `tp_trace` is a production Python APM library built on OpenTelemetry. It provides distributed tracing and native RED (Rate, Errors, Duration) metrics instrumentation for Django, PostgreSQL, Redis, Celery, and HTTP clients, paired with a complete local development observability stack.
36
+
37
+ ---
38
+
39
+ ## Repository Structure
40
+
41
+ ```text
42
+ tp_trace/
43
+ ├── src/tp_trace/ # Core Python SDK and framework integrations
44
+ ├── config/ # Shared canonical configuration (Collector, Tempo, Prometheus)
45
+ ├── dev/ # Local development stack (docker-compose.yml and dev configs)
46
+ │ └── sample-app/ # Instrumented Django sample application and traffic generator
47
+ ├── setup/ # Standalone Tempo trace store deployment (Docker Compose)
48
+ ├── ansible/ # Ansible playbooks and roles for fleet Collector deployment
49
+ ├── grafana/ # Canonical Grafana dashboards and datasource provisioning
50
+ ├── docs/ # Core documentation
51
+ │ ├── 01-basics.md # Observability concepts (traces, metrics, context propagation)
52
+ │ ├── 02-architecture.md # End-to-end lifecycle from tp_trace.init() to Grafana
53
+ │ └── 03-integration.md # SDK setup, Docker Tempo setup, and Ansible Collector setup
54
+ └── tests/ # SDK test suite and e2e validation probes
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Local Setup
60
+
61
+ ### Prerequisites
62
+
63
+ - Docker with Docker Compose support
64
+ - Python 3.8+ (for running the host SDK; Python 3.10+ required for `make lint`)
65
+
66
+ ### Start the Local Observability Stack
67
+
68
+ From the repository root:
69
+
70
+ ```bash
71
+ # 1. Copy local environment defaults
72
+ cp .env.example .env
73
+
74
+ # 2. Set up host virtual environment and install development tools
75
+ make install
76
+
77
+ # 3. Validate shared configuration files
78
+ make check-config
79
+ make check-collector-config
80
+
81
+ # 4. Build images and start the local services
82
+ make rebuild
83
+ ```
84
+
85
+ > **Note:** Root Makefile commands target `dev/docker-compose.yml` automatically. If you modify application dependencies or Dockerfiles, run `make rebuild`. For everyday restarts without rebuilding images, use `make up`.
86
+
87
+ ---
88
+
89
+ ## How to Work With It
90
+
91
+ ### Service Endpoints
92
+
93
+ Once `make rebuild` or `make up` completes, local services are accessible at:
94
+
95
+ | Service | Host URL / Port | Notes |
96
+ | --- | --- | --- |
97
+ | **Sample Django App** | <http://localhost:8002/api/> | Instrumented Django application |
98
+ | **Grafana** | <http://localhost:3001> | Anonymous admin access enabled |
99
+ | **Prometheus** | <http://localhost:9090> | TSDB metrics engine |
100
+ | **Tempo Query API** | <http://localhost:3200> | Trace store query API |
101
+ | **Tempo OTLP/gRPC** | `localhost:4327` | Traces ingress |
102
+ | **Collector OTLP** | `localhost:4318` (HTTP) / `4317` (gRPC) | Application telemetry ingress |
103
+ | **Collector Health** | <http://localhost:13133/> | Health probe endpoint |
104
+ | **MinIO Console** | <http://localhost:9003> | S3-compatible trace object storage |
105
+
106
+ ### Generate and Inspect Telemetry
107
+
108
+ 1. **Send synthetic traffic** to the sample application:
109
+ ```bash
110
+ # Run standard traffic generator workload
111
+ make traffic
112
+
113
+ # Or run specific workload flags
114
+ make traffic ARGS='--count 20 --redis --http'
115
+ ```
116
+
117
+ 2. **Run end-to-end smoke verification**:
118
+ ```bash
119
+ make smoke
120
+ ```
121
+ `make smoke` verifies that spans and metrics have reached Prometheus and Tempo storage.
122
+
123
+ 3. **View Dashboards in Grafana**:
124
+ - Open <http://localhost:3001>.
125
+ - Navigate to **Dashboards > TP Trace Dashboards**.
126
+ - Filter by Project: `otel-sample`, Cluster: `Dummy`.
127
+ - Inspect request rates, error ratios, latency distributions, and trace waterfalls.
128
+
129
+ ### Managing the Stack
130
+
131
+ ```bash
132
+ # Check container status
133
+ make ps
134
+
135
+ # View service logs
136
+ make logs SERVICE=sample-app
137
+ make logs SERVICE=otel-collector
138
+
139
+ # Restart a specific service (e.g. after changing collector config)
140
+ make restart SERVICE=otel-collector
141
+
142
+ # Stop services (preserves database and trace volumes)
143
+ make down
144
+
145
+ # Complete teardown (removes all volumes and persistent data)
146
+ make nuke
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Shared Telemetry Configuration (`config/`)
152
+
153
+ To prevent drift between development and production, canonical service configurations reside in `config/`:
154
+
155
+ | File | Shared Usage |
156
+ | --- | --- |
157
+ | `config/otel-collector.yaml` | Mounted by local Compose; copied by Ansible to production application servers |
158
+ | `config/tempo.yaml` | Mounted by local Compose; mounted by standalone Tempo in `setup/` |
159
+ | `config/prometheus.yml` | Mounted by local Compose; reference scrape configuration for production Prometheus |
160
+
161
+ The Collector uses `${env:VAR_NAME}` substitutions for endpoints and identities. Local Compose provides environment variables through `.env` and `dev/docker-compose.yml`, while Ansible injects inventory variables during fleet deployment.
162
+
163
+ To validate configuration syntax across all environments:
164
+
165
+ ```bash
166
+ make check-config
167
+ make check-collector-config
168
+ docker compose -f setup/docker-compose.yml config --quiet
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Documentation
174
+
175
+ - **[01. Observability Basics](docs/01-basics.md)**: Fundamental observability concepts — traces, spans, RED metrics, context propagation, and cardinality.
176
+ - **[02. Architecture](docs/02-architecture.md)**: Complete lifecycle walkthrough from `tp_trace.init()` to metrics and traces rendered in Grafana.
177
+ - **[03. Integration and Deployment](docs/03-integration.md)**: Application SDK integration, Docker Tempo setup, and Ansible fleet Collector deployment.
@@ -0,0 +1,145 @@
1
+ # tp_trace
2
+
3
+ `tp_trace` is a production Python APM library built on OpenTelemetry. It provides distributed tracing and native RED (Rate, Errors, Duration) metrics instrumentation for Django, PostgreSQL, Redis, Celery, and HTTP clients, paired with a complete local development observability stack.
4
+
5
+ ---
6
+
7
+ ## Repository Structure
8
+
9
+ ```text
10
+ tp_trace/
11
+ ├── src/tp_trace/ # Core Python SDK and framework integrations
12
+ ├── config/ # Shared canonical configuration (Collector, Tempo, Prometheus)
13
+ ├── dev/ # Local development stack (docker-compose.yml and dev configs)
14
+ │ └── sample-app/ # Instrumented Django sample application and traffic generator
15
+ ├── setup/ # Standalone Tempo trace store deployment (Docker Compose)
16
+ ├── ansible/ # Ansible playbooks and roles for fleet Collector deployment
17
+ ├── grafana/ # Canonical Grafana dashboards and datasource provisioning
18
+ ├── docs/ # Core documentation
19
+ │ ├── 01-basics.md # Observability concepts (traces, metrics, context propagation)
20
+ │ ├── 02-architecture.md # End-to-end lifecycle from tp_trace.init() to Grafana
21
+ │ └── 03-integration.md # SDK setup, Docker Tempo setup, and Ansible Collector setup
22
+ └── tests/ # SDK test suite and e2e validation probes
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Local Setup
28
+
29
+ ### Prerequisites
30
+
31
+ - Docker with Docker Compose support
32
+ - Python 3.8+ (for running the host SDK; Python 3.10+ required for `make lint`)
33
+
34
+ ### Start the Local Observability Stack
35
+
36
+ From the repository root:
37
+
38
+ ```bash
39
+ # 1. Copy local environment defaults
40
+ cp .env.example .env
41
+
42
+ # 2. Set up host virtual environment and install development tools
43
+ make install
44
+
45
+ # 3. Validate shared configuration files
46
+ make check-config
47
+ make check-collector-config
48
+
49
+ # 4. Build images and start the local services
50
+ make rebuild
51
+ ```
52
+
53
+ > **Note:** Root Makefile commands target `dev/docker-compose.yml` automatically. If you modify application dependencies or Dockerfiles, run `make rebuild`. For everyday restarts without rebuilding images, use `make up`.
54
+
55
+ ---
56
+
57
+ ## How to Work With It
58
+
59
+ ### Service Endpoints
60
+
61
+ Once `make rebuild` or `make up` completes, local services are accessible at:
62
+
63
+ | Service | Host URL / Port | Notes |
64
+ | --- | --- | --- |
65
+ | **Sample Django App** | <http://localhost:8002/api/> | Instrumented Django application |
66
+ | **Grafana** | <http://localhost:3001> | Anonymous admin access enabled |
67
+ | **Prometheus** | <http://localhost:9090> | TSDB metrics engine |
68
+ | **Tempo Query API** | <http://localhost:3200> | Trace store query API |
69
+ | **Tempo OTLP/gRPC** | `localhost:4327` | Traces ingress |
70
+ | **Collector OTLP** | `localhost:4318` (HTTP) / `4317` (gRPC) | Application telemetry ingress |
71
+ | **Collector Health** | <http://localhost:13133/> | Health probe endpoint |
72
+ | **MinIO Console** | <http://localhost:9003> | S3-compatible trace object storage |
73
+
74
+ ### Generate and Inspect Telemetry
75
+
76
+ 1. **Send synthetic traffic** to the sample application:
77
+ ```bash
78
+ # Run standard traffic generator workload
79
+ make traffic
80
+
81
+ # Or run specific workload flags
82
+ make traffic ARGS='--count 20 --redis --http'
83
+ ```
84
+
85
+ 2. **Run end-to-end smoke verification**:
86
+ ```bash
87
+ make smoke
88
+ ```
89
+ `make smoke` verifies that spans and metrics have reached Prometheus and Tempo storage.
90
+
91
+ 3. **View Dashboards in Grafana**:
92
+ - Open <http://localhost:3001>.
93
+ - Navigate to **Dashboards > TP Trace Dashboards**.
94
+ - Filter by Project: `otel-sample`, Cluster: `Dummy`.
95
+ - Inspect request rates, error ratios, latency distributions, and trace waterfalls.
96
+
97
+ ### Managing the Stack
98
+
99
+ ```bash
100
+ # Check container status
101
+ make ps
102
+
103
+ # View service logs
104
+ make logs SERVICE=sample-app
105
+ make logs SERVICE=otel-collector
106
+
107
+ # Restart a specific service (e.g. after changing collector config)
108
+ make restart SERVICE=otel-collector
109
+
110
+ # Stop services (preserves database and trace volumes)
111
+ make down
112
+
113
+ # Complete teardown (removes all volumes and persistent data)
114
+ make nuke
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Shared Telemetry Configuration (`config/`)
120
+
121
+ To prevent drift between development and production, canonical service configurations reside in `config/`:
122
+
123
+ | File | Shared Usage |
124
+ | --- | --- |
125
+ | `config/otel-collector.yaml` | Mounted by local Compose; copied by Ansible to production application servers |
126
+ | `config/tempo.yaml` | Mounted by local Compose; mounted by standalone Tempo in `setup/` |
127
+ | `config/prometheus.yml` | Mounted by local Compose; reference scrape configuration for production Prometheus |
128
+
129
+ The Collector uses `${env:VAR_NAME}` substitutions for endpoints and identities. Local Compose provides environment variables through `.env` and `dev/docker-compose.yml`, while Ansible injects inventory variables during fleet deployment.
130
+
131
+ To validate configuration syntax across all environments:
132
+
133
+ ```bash
134
+ make check-config
135
+ make check-collector-config
136
+ docker compose -f setup/docker-compose.yml config --quiet
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Documentation
142
+
143
+ - **[01. Observability Basics](docs/01-basics.md)**: Fundamental observability concepts — traces, spans, RED metrics, context propagation, and cardinality.
144
+ - **[02. Architecture](docs/02-architecture.md)**: Complete lifecycle walkthrough from `tp_trace.init()` to metrics and traces rendered in Grafana.
145
+ - **[03. Integration and Deployment](docs/03-integration.md)**: Application SDK integration, Docker Tempo setup, and Ansible fleet Collector deployment.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tp_trace"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "tp_trace: High-performance Python Observability SDK for OpenTelemetry"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -13,7 +13,7 @@ from opentelemetry import trace
13
13
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
14
14
  from opentelemetry.sdk.resources import Resource
15
15
  from opentelemetry.sdk.trace import TracerProvider, SpanProcessor
16
- from opentelemetry.sdk.trace.export import BatchSpanProcessor, SimpleSpanProcessor, SpanExporter
16
+ from opentelemetry.sdk.trace.export import SpanExporter
17
17
  from opentelemetry.sdk.trace.sampling import ALWAYS_OFF, Sampler
18
18
  from opentelemetry.trace import get_current_span, get_tracer
19
19
  from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
@@ -21,8 +21,7 @@ from opentelemetry.baggage.propagation import W3CBaggagePropagator
21
21
  from opentelemetry.propagate import set_global_textmap
22
22
 
23
23
  from tp_trace.config import SDKConfig
24
- from tp_trace.exporter import SafeSpanExporter
25
- from tp_trace.red import RedSpanProcessor, SampledOnlySpanProcessor
24
+ from tp_trace.exporter import AllSpansBatchSpanProcessor, AllSpansSimpleSpanProcessor, SafeSpanExporter, batch_export_options
26
25
  from tp_trace.route_context import RouteEnrichingSpanProcessor
27
26
  from tp_trace.integrations import BaseIntegration, get_integration_manager
28
27
  from tp_trace.sanitize import sanitize_query_string, sanitize_sql, sanitize_url
@@ -42,8 +41,6 @@ __all__ = [
42
41
  "BaseIntegration",
43
42
  "get_integration_manager",
44
43
  "RouteEnrichingSpanProcessor",
45
- "RedSpanProcessor",
46
- "SampledOnlySpanProcessor",
47
44
  "SafeSpanExporter",
48
45
  ]
49
46
 
@@ -200,18 +197,6 @@ def init(
200
197
  except Exception as exc:
201
198
  logger.debug("tp_trace: Failed to register RouteEnrichingSpanProcessor: %s", exc)
202
199
 
203
- # Register RED metrics aggregator: computes 100% RED metrics for all dependencies
204
- try:
205
- provider.add_span_processor(
206
- RedSpanProcessor(
207
- cardinality_limit_per_service=config.operation_cardinality_limit,
208
- route_limit=config.route_cardinality_limit,
209
- service_limit=config.service_cardinality_limit,
210
- )
211
- )
212
- except Exception as exc:
213
- logger.debug("tp_trace: Failed to register RedSpanProcessor: %s", exc)
214
-
215
200
  # Configure Exporter and Processor if not disabled
216
201
  if not config.disabled:
217
202
  if exporter is None:
@@ -239,17 +224,18 @@ def init(
239
224
 
240
225
  if span_processor is None:
241
226
  if export_batch:
242
- span_processor = BatchSpanProcessor(
227
+ batch_options = batch_export_options()
228
+ span_processor = AllSpansBatchSpanProcessor(
243
229
  safe_exporter,
244
- max_queue_size=2048,
245
- max_export_batch_size=256,
246
- schedule_delay_millis=1000,
230
+ max_queue_size=batch_options["max_queue_size"],
231
+ max_export_batch_size=batch_options["max_export_batch_size"],
232
+ schedule_delay_millis=batch_options["schedule_delay_millis"],
247
233
  )
248
234
  else:
249
- span_processor = SimpleSpanProcessor(safe_exporter)
235
+ span_processor = AllSpansSimpleSpanProcessor(safe_exporter)
250
236
 
251
- # Gate exports: only spans with trace_flags.sampled=True are serialized/transmitted
252
- provider.add_span_processor(SampledOnlySpanProcessor(span_processor))
237
+ # Export spans to local Collector (spanmetrics computes metrics; filter drops unsampled before Tempo)
238
+ provider.add_span_processor(span_processor)
253
239
 
254
240
  # Set as global tracer provider
255
241
  trace.set_tracer_provider(provider)
@@ -272,13 +258,13 @@ def init(
272
258
  except Exception as exc:
273
259
  logger.debug("Failed to auto-apply integrations during init: %s", exc)
274
260
 
275
- # Initialize independent RED metrics recorder
261
+ # Initialize custom metrics recorder
276
262
  try:
277
263
  from tp_trace.metrics import init_metrics
278
264
 
279
265
  init_metrics(config=config, metric_readers=metric_readers, resource=resource)
280
266
  except Exception as exc:
281
- logger.debug("tp_trace: Failed to initialize independent RED metrics: %s", exc)
267
+ logger.debug("tp_trace: Failed to initialize custom metrics: %s", exc)
282
268
 
283
269
  # Register shutdown on process exit exactly once
284
270
  global _ATEXIT_REGISTERED
@@ -10,9 +10,6 @@ from tp_trace.version import __version__
10
10
 
11
11
  logger = logging.getLogger("tp_trace.config")
12
12
 
13
- DEFAULT_OPERATION_CARDINALITY_LIMIT = 1000
14
- DEFAULT_ROUTE_CARDINALITY_LIMIT = 5000
15
- DEFAULT_SERVICE_CARDINALITY_LIMIT = 16
16
13
 
17
14
  # Deprecated inputs that name the *project* after a *service*. Warned once each so
18
15
  # operators learn the canonical name without log spam.
@@ -266,9 +263,6 @@ class SDKConfig:
266
263
  query_mode: str = "expose"
267
264
  n_plus_one_duplicate_threshold: int = 15
268
265
  n_plus_one_max_fingerprints: int = 256
269
- operation_cardinality_limit: int = DEFAULT_OPERATION_CARDINALITY_LIMIT
270
- route_cardinality_limit: int = DEFAULT_ROUTE_CARDINALITY_LIMIT
271
- service_cardinality_limit: int = DEFAULT_SERVICE_CARDINALITY_LIMIT
272
266
 
273
267
  @classmethod
274
268
  def from_env_and_kwargs(
@@ -302,9 +296,6 @@ class SDKConfig:
302
296
  query_mode: Optional[str] = None,
303
297
  n_plus_one_duplicate_threshold: Optional[int] = None,
304
298
  n_plus_one_max_fingerprints: Optional[int] = None,
305
- operation_cardinality_limit: Optional[int] = None,
306
- route_cardinality_limit: Optional[int] = None,
307
- service_cardinality_limit: Optional[int] = None,
308
299
  **extra: Any,
309
300
  ) -> "SDKConfig":
310
301
  """Build SDKConfig by prioritizing explicit kwargs over environment variables."""
@@ -430,24 +421,6 @@ class SDKConfig:
430
421
  except Exception:
431
422
  resolved_metric_cardinality_limit = 5000
432
423
 
433
- resolved_operation_cardinality_limit = _parse_positive_int_default(
434
- operation_cardinality_limit if operation_cardinality_limit is not None else os.getenv("TP_TRACE_OPERATION_CARDINALITY_LIMIT"),
435
- default=DEFAULT_OPERATION_CARDINALITY_LIMIT,
436
- field_name="operation_cardinality_limit",
437
- )
438
-
439
- resolved_route_cardinality_limit = _parse_positive_int_default(
440
- route_cardinality_limit if route_cardinality_limit is not None else os.getenv("TP_TRACE_ROUTE_CARDINALITY_LIMIT"),
441
- default=DEFAULT_ROUTE_CARDINALITY_LIMIT,
442
- field_name="route_cardinality_limit",
443
- )
444
-
445
- resolved_service_cardinality_limit = _parse_positive_int_default(
446
- service_cardinality_limit if service_cardinality_limit is not None else os.getenv("TP_TRACE_SERVICE_CARDINALITY_LIMIT"),
447
- default=DEFAULT_SERVICE_CARDINALITY_LIMIT,
448
- field_name="service_cardinality_limit",
449
- )
450
-
451
424
  resolved_service_instance_id = (
452
425
  service_instance_id
453
426
  or extra.get("service_instance_id")
@@ -780,9 +753,6 @@ class SDKConfig:
780
753
  metrics_enabled=resolved_metrics_enabled,
781
754
  metrics_export_interval_millis=resolved_metrics_interval,
782
755
  metric_cardinality_limit=resolved_metric_cardinality_limit,
783
- operation_cardinality_limit=resolved_operation_cardinality_limit,
784
- route_cardinality_limit=resolved_route_cardinality_limit,
785
- service_cardinality_limit=resolved_service_cardinality_limit,
786
756
  service_instance_id=resolved_service_instance_id,
787
757
  redis_mask_endpoint=resolved_redis_mask_endpoint,
788
758
  redis_mask_command=resolved_redis_mask_command,