Skip to content

Commit f0071dd

Browse files
committed
test fixture
1 parent adabb16 commit f0071dd

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

sdks/python/hatchet_sdk/opentelemetry/instrumentor.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,23 @@ class HatchetInstrumentor(BaseInstrumentor): # type: ignore[misc]
258258
The instrumentor provides an OpenTelemetry integration for Hatchet by setting up
259259
tracing and metrics collection.
260260
261-
:param tracer_provider: TracerProvider | None: The OpenTelemetry TracerProvider to use.
261+
:param tracer_provider: The OpenTelemetry TracerProvider to use.
262262
If not provided and `enable_hatchet_otel_collector` is True, a new SDKTracerProvider
263263
will be created. Otherwise, the global tracer provider will be used.
264-
:param meter_provider: MeterProvider | None: The OpenTelemetry MeterProvider to use.
264+
:param meter_provider: The OpenTelemetry MeterProvider to use.
265265
If not provided, a no-op meter provider will be used.
266-
:param config: ClientConfig | None: The configuration for the Hatchet client. If not provided,
266+
:param config: The configuration for the Hatchet client. If not provided,
267267
a default configuration will be used.
268-
:param enable_hatchet_otel_collector: bool: If True (the default), adds an OTLP exporter
268+
:param enable_hatchet_otel_collector: If True (the default), adds an OTLP exporter
269269
to send traces to the Hatchet engine. Uses the same connection settings (host, TLS,
270270
token) as the Hatchet client. This can be combined with your own tracer_provider to
271271
send traces to multiple destinations (e.g., both Hatchet and Jaeger/Datadog).
272+
:param schedule_delay_millis: The delay in milliseconds between two consecutive
273+
exports of the BatchSpanProcessor. Defaults to the OTel SDK default (5000ms) if not set.
274+
:param max_export_batch_size: The maximum batch size for the BatchSpanProcessor.
275+
Defaults to the OTel SDK default (512) if not set.
276+
:param max_queue_size: The maximum queue size for the BatchSpanProcessor.
277+
Defaults to the OTel SDK default (2048) if not set.
272278
273279
Example usage::
274280

sdks/python/tests/otel_traces/test_otel_traces.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,37 +116,29 @@ async def test_otel_traces_on_retry(
116116

117117
spans = _get_trace_spans(hatchet, ref.workflow_run_id)
118118

119-
# Both the failed first attempt and the successful retry should have spans
119+
# The DB query returns only spans for the latest retry (MAX retry_count),
120+
# so we expect exactly the successful retry's span.
120121
step_run_spans = [s for s in spans if s.get("spanName") == "hatchet.start_step_run"]
121-
assert len(step_run_spans) >= 2, (
122-
f"Expected at least 2 hatchet task run spans (initial + retry), "
122+
assert len(step_run_spans) >= 1, (
123+
f"Expected at least 1 hatchet task run span for the successful retry, "
123124
f"got {len(step_run_spans)}. All spans: {[s.get('spanName') for s in spans]}"
124125
)
125126

126-
# The first attempt should have errored
127-
error_spans = [s for s in step_run_spans if s.get("statusCode") == "ERROR"]
128-
assert len(error_spans) >= 1, (
129-
f"Expected at least one ERROR span from the failed first attempt. "
130-
f"Statuses: {[s.get('statusCode') for s in step_run_spans]}"
127+
# The returned span should be from the successful retry (retryCount >= 1)
128+
latest_span = step_run_spans[0]
129+
assert latest_span.get("retryCount", 0) >= 1, (
130+
f"Expected span from retry attempt (retryCount >= 1), "
131+
f"got retryCount={latest_span.get('retryCount')}"
131132
)
132133

133-
# All step run spans should have valid hatchet.* attributes
134-
for span in step_run_spans:
135-
attrs = span.get("spanAttributes", {})
136-
assert (
137-
"hatchet.step_run_id" in attrs
138-
), f"Step run span missing hatchet.step_run_id. Attrs: {attrs}"
139-
assert (
140-
"hatchet.workflow_run_id" in attrs
141-
), f"Step run span missing hatchet.workflow_run_id. Attrs: {attrs}"
142-
assert (
143-
"hatchet.tenant_id" in attrs
144-
), f"Step run span missing hatchet.tenant_id. Attrs: {attrs}"
145-
146-
# Verify retry count differs between attempts
147-
retry_counts = [
148-
s.get("spanAttributes", {}).get("hatchet.retry_count") for s in step_run_spans
149-
]
134+
# The span should have valid hatchet.* attributes
135+
attrs = latest_span.get("spanAttributes", {})
136+
assert (
137+
"hatchet.step_run_id" in attrs
138+
), f"Step run span missing hatchet.step_run_id. Attrs: {attrs}"
139+
assert (
140+
"hatchet.workflow_run_id" in attrs
141+
), f"Step run span missing hatchet.workflow_run_id. Attrs: {attrs}"
150142
assert (
151-
len(set(retry_counts)) >= 2
152-
), f"Expected different retry_count values across attempts, got {retry_counts}"
143+
"hatchet.tenant_id" in attrs
144+
), f"Step run span missing hatchet.tenant_id. Attrs: {attrs}"

0 commit comments

Comments
 (0)