Skip to content

Commit 1020ce4

Browse files
committed
Linting
1 parent 155a5aa commit 1020ce4

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

temporalio/contrib/opentelemetry.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import opentelemetry.trace.propagation.tracecontext
2727
import opentelemetry.util.types
2828
from opentelemetry.context import Context
29-
from opentelemetry.trace import SpanKind, _Links, Span, StatusCode, Status
29+
from opentelemetry.trace import Span, SpanKind, Status, StatusCode, _Links
3030
from opentelemetry.util import types
3131
from typing_extensions import Protocol, TypeAlias, TypedDict
3232

@@ -173,7 +173,13 @@ def _start_as_current_span(
173173
kind: opentelemetry.trace.SpanKind,
174174
context: Optional[Context] = None,
175175
) -> Iterator[None]:
176-
with self.tracer.start_as_current_span(name, attributes=attributes, kind=kind, context=context, set_status_on_exception=False) as span:
176+
with self.tracer.start_as_current_span(
177+
name,
178+
attributes=attributes,
179+
kind=kind,
180+
context=context,
181+
set_status_on_exception=False,
182+
) as span:
177183
if input:
178184
input.headers = self._context_to_headers(input.headers)
179185
try:

tests/contrib/test_opentelemetry.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider
1212
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
1313
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
14-
from opentelemetry.trace import get_tracer, StatusCode
14+
from opentelemetry.trace import StatusCode, get_tracer
1515

1616
from temporalio import activity, workflow
1717
from temporalio.client import Client
@@ -389,19 +389,27 @@ async def test_opentelemetry_always_create_workflow_spans(client: Client):
389389

390390

391391
attempted = False
392+
393+
392394
@activity.defn
393395
def benign_activity() -> str:
394396
global attempted
395397
if attempted:
396398
return "done"
397399
attempted = True
398-
raise ApplicationError(category=ApplicationErrorCategory.BENIGN, message="Benign Error")
400+
raise ApplicationError(
401+
category=ApplicationErrorCategory.BENIGN, message="Benign Error"
402+
)
403+
399404

400405
@workflow.defn
401406
class BenignWorkflow:
402407
@workflow.run
403408
async def run(self) -> str:
404-
return await workflow.execute_activity(benign_activity, schedule_to_close_timeout=timedelta(seconds=1))
409+
return await workflow.execute_activity(
410+
benign_activity, schedule_to_close_timeout=timedelta(seconds=1)
411+
)
412+
405413

406414
async def test_opentelemetry_benign_exception(client: Client):
407415
# Create a tracer that has an in-memory exporter
@@ -426,13 +434,16 @@ async def test_opentelemetry_benign_exception(client: Client):
426434
BenignWorkflow.run,
427435
id=f"workflow_{uuid.uuid4()}",
428436
task_queue=worker.task_queue,
429-
retry_policy=RetryPolicy(maximum_attempts=2, initial_interval=timedelta(milliseconds=10)),
437+
retry_policy=RetryPolicy(
438+
maximum_attempts=2, initial_interval=timedelta(milliseconds=10)
439+
),
430440
)
431441
spans = exporter.get_finished_spans()
432442
for span in spans:
433443
print(f"{span.name}: {span.status.status_code}")
434444
assert all(span.status.status_code == StatusCode.UNSET for span in spans)
435445

446+
436447
# TODO(cretz): Additional tests to write
437448
# * query without interceptor (no headers)
438449
# * workflow without interceptor (no headers) but query with interceptor (headers)

0 commit comments

Comments
 (0)