tp-trace 0.4.0__tar.gz → 0.4.1__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.
- {tp_trace-0.4.0 → tp_trace-0.4.1}/PKG-INFO +1 -1
- {tp_trace-0.4.0 → tp_trace-0.4.1}/pyproject.toml +1 -1
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/metrics.py +8 -8
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/version.py +1 -1
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace.egg-info/PKG-INFO +1 -1
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_metrics.py +40 -1
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_n_plus_one.py +19 -2
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_n_plus_one_dashboard_contract.py +16 -2
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_red_dashboard_contract.py +7 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/README.md +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/setup.cfg +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/compat/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/compat/attributes.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/config.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/config_access.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/exporter.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/base.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/boto/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/boto/integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/celery/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/celery/context.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/celery/instrumentor.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/celery/integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/auth.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/cache.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/compat.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/middleware.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/request.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/template.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/django/view.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/manager.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/postgres/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/postgres/cursor.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/postgres/integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/redis/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/redis/integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/requests/__init__.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/requests/client.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/integrations/requests/integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/normalize.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/propagator.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/route_context.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/safety.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/sampler.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/sanitize.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace/tracing.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace.egg-info/SOURCES.txt +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace.egg-info/dependency_links.txt +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace.egg-info/requires.txt +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/src/tp_trace.egg-info/top_level.txt +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_base_integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_boto.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_celery_integration.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_celery_probe.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_django.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_django_advanced.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_django_migration_regressions.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_django_safety_regressions.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_init.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_postgres.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_red_comparison.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_redis.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_requests.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_safety.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_sample_telemetry.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_sampling_rules.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_sanitization_regressions.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_shared_config.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_smoke_probe.py +0 -0
- {tp_trace-0.4.0 → tp_trace-0.4.1}/tests/test_traffic_generator.py +0 -0
|
@@ -315,7 +315,8 @@ class RedMetricsRecorder:
|
|
|
315
315
|
Fail-safe: Any error during recording is safely absorbed and never disrupts
|
|
316
316
|
the host application.
|
|
317
317
|
Strict low-cardinality label allowlist: normalized service, http.route, http.method,
|
|
318
|
-
project_name, cluster_name, metric_source, worker_id
|
|
318
|
+
project_name, cluster_name, metric_source, and worker_id. Request tags,
|
|
319
|
+
including institute, remain trace attributes and never split metric series.
|
|
319
320
|
Never emits raw SQL, query text, or trace IDs. ``worker_id`` keeps independent
|
|
320
321
|
process counters from being merged into one reset-prone stream by the Collector.
|
|
321
322
|
The configured cardinality limit admits detailed series independently
|
|
@@ -336,12 +337,6 @@ class RedMetricsRecorder:
|
|
|
336
337
|
"metric_source": "tp_trace_sdk",
|
|
337
338
|
}
|
|
338
339
|
|
|
339
|
-
if extra_attributes:
|
|
340
|
-
# Strictly allow only institute
|
|
341
|
-
val = extra_attributes.get("institute")
|
|
342
|
-
if val is not None:
|
|
343
|
-
attributes["institute"] = str(val)
|
|
344
|
-
|
|
345
340
|
# Counter streams from forked workers must remain distinct. The dashboard
|
|
346
341
|
# sums across this bounded identity label when calculating request totals.
|
|
347
342
|
current_pid = os.getpid()
|
|
@@ -380,7 +375,6 @@ class RedMetricsRecorder:
|
|
|
380
375
|
"http.route": "__other__",
|
|
381
376
|
"metric_source": "tp_trace_sdk",
|
|
382
377
|
"worker_id": worker_identity,
|
|
383
|
-
"institute": "__other__",
|
|
384
378
|
}
|
|
385
379
|
self.repeated_query_affected_requests_total.add(1, attributes)
|
|
386
380
|
except Exception as exc:
|
|
@@ -467,6 +461,12 @@ def create_red_metrics_recorder(
|
|
|
467
461
|
res_attrs["deployment.environment"] = config.environment
|
|
468
462
|
resource = Resource.create(res_attrs)
|
|
469
463
|
|
|
464
|
+
# Institute tags stay on traces but must not split SDK metric resources.
|
|
465
|
+
resource = Resource(
|
|
466
|
+
{key: value for key, value in resource.attributes.items()
|
|
467
|
+
if key not in {"institute", "institute.subdomain"}},
|
|
468
|
+
schema_url=resource.schema_url,
|
|
469
|
+
)
|
|
470
470
|
provider = MeterProvider(
|
|
471
471
|
resource=resource,
|
|
472
472
|
metric_readers=readers,
|
|
@@ -651,7 +651,7 @@ class _DummyInstitute:
|
|
|
651
651
|
|
|
652
652
|
|
|
653
653
|
def test_institute_tags_exported_on_server_spans():
|
|
654
|
-
"""Verify
|
|
654
|
+
"""Verify institute tags remain on server spans for Tempo investigation."""
|
|
655
655
|
span_exporter = InMemorySpanExporter()
|
|
656
656
|
tp_trace.init(
|
|
657
657
|
project_name="institute-app",
|
|
@@ -853,3 +853,42 @@ def test_owned_metric_export_temporality(monkeypatch, preference):
|
|
|
853
853
|
assert os.environ.get(key) == preference
|
|
854
854
|
finally:
|
|
855
855
|
recorder.shutdown()
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
def test_metric_resources_exclude_only_institute_without_changing_trace_resources():
|
|
859
|
+
reader = InMemoryMetricReader()
|
|
860
|
+
exporter = InMemorySpanExporter()
|
|
861
|
+
provider = tp_trace.init(
|
|
862
|
+
project_name="resource-bounds", cluster_name="prod", exporter=exporter,
|
|
863
|
+
export_batch=False, metric_readers=[reader],
|
|
864
|
+
tags={"institute": "tenant-a", "institute.subdomain": "tenant-a", "customer_id": "customer-a"},
|
|
865
|
+
resource_attributes={"request_id": "request-a", "host.name": "app-host"},
|
|
866
|
+
)
|
|
867
|
+
recorder = get_metrics_recorder()
|
|
868
|
+
recorder.record_repeated_query_affected_request(method="GET", route="/items/")
|
|
869
|
+
data = reader.get_metrics_data()
|
|
870
|
+
for rm in data.resource_metrics:
|
|
871
|
+
assert "institute" not in rm.resource.attributes
|
|
872
|
+
assert "institute.subdomain" not in rm.resource.attributes
|
|
873
|
+
assert rm.resource.attributes["customer_id"] == "customer-a"
|
|
874
|
+
assert rm.resource.attributes["request_id"] == "request-a"
|
|
875
|
+
assert rm.resource.attributes["project_name"] == "resource-bounds"
|
|
876
|
+
assert rm.resource.attributes["host.name"] == "app-host"
|
|
877
|
+
with provider.get_tracer("resource-bounds-test").start_as_current_span("trace"):
|
|
878
|
+
pass
|
|
879
|
+
resource = exporter.get_finished_spans()[-1].resource.attributes
|
|
880
|
+
assert resource["institute"] == "tenant-a"
|
|
881
|
+
assert resource["customer_id"] == "customer-a"
|
|
882
|
+
assert resource["request_id"] == "request-a"
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
def test_cardinality_diagnostic_services_remain_bounded():
|
|
886
|
+
reader = InMemoryMetricReader()
|
|
887
|
+
tp_trace.init(project_name="diagnostic-bounds", metric_readers=[reader], export_batch=False)
|
|
888
|
+
recorder = get_metrics_recorder()
|
|
889
|
+
for i in range(1000):
|
|
890
|
+
recorder.record_cardinality_grouping(service=str(i), scope=str(i), cause=str(i))
|
|
891
|
+
points = _get_metric_data_points(reader, "apm_cardinality_grouping_total")
|
|
892
|
+
assert len(points) == 65 # 64 admitted service names and a shared overflow.
|
|
893
|
+
assert sum(p.value for p in points) == 1000
|
|
894
|
+
assert all(p.attributes["scope"] == p.attributes["cause"] == "unknown" for p in points)
|
|
@@ -239,7 +239,6 @@ def test_repeated_query_metric_cardinality_preserves_counts_and_owners():
|
|
|
239
239
|
"http.route",
|
|
240
240
|
"metric_source",
|
|
241
241
|
"worker_id",
|
|
242
|
-
"institute",
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
|
|
@@ -274,7 +273,7 @@ def test_repeated_query_metric_allowlist():
|
|
|
274
273
|
assert attrs["http.method"] == "POST"
|
|
275
274
|
assert attrs["http.route"] == "/api/v1/checkout/"
|
|
276
275
|
assert attrs["metric_source"] == "tp_trace_sdk"
|
|
277
|
-
assert
|
|
276
|
+
assert "institute" not in attrs
|
|
278
277
|
|
|
279
278
|
# Strictly forbidden labels (cardinality explosion prevention):
|
|
280
279
|
assert "forbidden_worker_id" not in attrs
|
|
@@ -657,3 +656,21 @@ def test_repeated_query_evaluation_records_same_span_once():
|
|
|
657
656
|
assert points[0].value == 1
|
|
658
657
|
finally:
|
|
659
658
|
reset_request_db_tracker(token)
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def test_repeated_query_tenants_and_custom_tags_share_one_series():
|
|
662
|
+
reader = InMemoryMetricReader()
|
|
663
|
+
recorder = init_metrics(
|
|
664
|
+
config=SDKConfig(project_name="tenant-test", cluster_name="prod", metric_cardinality_limit=2),
|
|
665
|
+
metric_readers=[reader],
|
|
666
|
+
)
|
|
667
|
+
for i in range(1200):
|
|
668
|
+
record_repeated_query_affected_request(
|
|
669
|
+
method="GET", route="/items/",
|
|
670
|
+
extra_attributes={"institute": str(i), "request_id": str(i), "user_id": str(i)},
|
|
671
|
+
)
|
|
672
|
+
points = _get_metric_data_points(reader, "apm_repeated_query_affected_requests_total")
|
|
673
|
+
assert len(points) == 1
|
|
674
|
+
assert points[0].value == 1200
|
|
675
|
+
assert not {"institute", "request_id", "user_id"}.intersection(points[0].attributes)
|
|
676
|
+
assert len(recorder._repeated_query_series) == 1
|
|
@@ -159,7 +159,7 @@ def test_collector_spanmetrics_pipeline_and_filters():
|
|
|
159
159
|
assert metrics["receivers"] == ["otlp"]
|
|
160
160
|
assert metrics["exporters"] == ["spanmetrics"]
|
|
161
161
|
assert metrics["processors"] == [
|
|
162
|
-
"memory_limiter", "resource/drop_ephemeral", "filter/spanmetrics_drop_internal",
|
|
162
|
+
"memory_limiter", "resource/drop_ephemeral", "resource/drop_metric_institute", "filter/spanmetrics_drop_internal",
|
|
163
163
|
"transform/spanmetrics_route", "transform/spanmetrics_sanitize", "batch",
|
|
164
164
|
]
|
|
165
165
|
assert "filter/drop_unsampled" not in metrics["processors"]
|
|
@@ -172,7 +172,7 @@ def test_collector_spanmetrics_pipeline_and_filters():
|
|
|
172
172
|
assert connector["metrics_expiration"] == connector["series_expiration"] == "5m"
|
|
173
173
|
assert connector["aggregation_cardinality_limit"] == 5000
|
|
174
174
|
assert "span.name" in connector["exclude_dimensions"]
|
|
175
|
-
assert "institute" in [dimension["name"] for dimension in connector["dimensions"]]
|
|
175
|
+
assert "institute" not in [dimension["name"] for dimension in connector["dimensions"]]
|
|
176
176
|
assert cfg["processors"]["filter/spanmetrics_drop_internal"]["trace_conditions"] == [
|
|
177
177
|
"span.kind == SPAN_KIND_INTERNAL",
|
|
178
178
|
]
|
|
@@ -288,3 +288,17 @@ def test_dashboards_only_query_collector_red_metrics():
|
|
|
288
288
|
for _, target in _all_targets(json.loads(text)):
|
|
289
289
|
if "apm_calls_total" in target.get("expr", ""):
|
|
290
290
|
assert "span_name" not in target["expr"], path
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def test_institute_is_trace_only_and_does_not_filter_metric_queries():
|
|
294
|
+
for path in DASHBOARDS.rglob("*.json"):
|
|
295
|
+
text = path.read_text()
|
|
296
|
+
dashboard = json.loads(text)
|
|
297
|
+
for _, target in _all_targets(dashboard):
|
|
298
|
+
expr = target.get("expr", "")
|
|
299
|
+
assert "institute" not in expr, path
|
|
300
|
+
assert "${institute" not in text, path
|
|
301
|
+
assert "institute" not in {v["name"] for v in dashboard.get("templating", {}).get("list", [])}, path
|
|
302
|
+
cfg = __import__("yaml").safe_load((ROOT / "config/otel-collector.yaml").read_text())
|
|
303
|
+
assert "resource/drop_metric_institute" not in cfg["service"]["pipelines"]["traces"]["processors"]
|
|
304
|
+
assert "resource/drop_metric_institute" in cfg["service"]["pipelines"]["metrics"]["processors"]
|
|
@@ -696,3 +696,10 @@ def test_service_overview_always_includes_all_operations(tmp_path):
|
|
|
696
696
|
assert "var-operation=${__data.fields.Operation:percentencode}" in links
|
|
697
697
|
details = json.loads((DASHBOARDS / "Supporting Dashboards/operation_details.json").read_text())
|
|
698
698
|
assert "operation" in {v["name"] for v in details["templating"]["list"]}
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
def test_operation_details_has_no_institute_control_or_query_dependency():
|
|
702
|
+
dashboard = json.loads((DASHBOARDS / "Supporting Dashboards/operation_details.json").read_text())
|
|
703
|
+
assert "institute" not in {v["name"] for v in dashboard["templating"]["list"]}
|
|
704
|
+
assert "${institute" not in json.dumps(dashboard)
|
|
705
|
+
assert "operation" in {v["name"] for v in dashboard["templating"]["list"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|