Skip to content

Commit

Permalink
update to Observability-utils 0.1.4 (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithralphs authored Nov 11, 2024
1 parent 0f210d5 commit d1b283b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 77 deletions.
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ mongoquery==1.4.2
msgpack==1.1.0
msgpack-numpy==0.4.8
multidict==6.1.0
mypy==1.13.0
mypy==1.13.0
mypy-extensions==1.0.0
myst-parser==4.0.0
networkx==3.4.2
Expand All @@ -132,7 +132,7 @@ nose2==0.15.1
nslsii==0.10.5
numcodecs==0.13.1
numpy==1.26.4
observability-utils==0.1.2
observability-utils==0.1.4
opencv-python-headless==4.10.0.84
opentelemetry-api==1.27.0
opentelemetry-distro==0.48b0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"event-model==1.21", # https://github.com/DiamondLightSource/blueapi/issues/684
"opentelemetry-distro>=0.48b0",
"opentelemetry-instrumentation-fastapi>=0.48b0",
"observability-utils>=0.1.2",
"observability-utils>=0.1.4"
]
dynamic = ["version"]
license.file = "LICENSE"
Expand Down
7 changes: 3 additions & 4 deletions src/blueapi/worker/task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
from bluesky.protocols import Status
from observability_utils.tracing import (
add_span_attributes,
get_trace_context,
get_tracer,
setup_tracing,
start_as_current_span,
)
from opentelemetry.baggage import get_baggage
from opentelemetry.context import Context
from opentelemetry.context import Context, get_current
from opentelemetry.trace import SpanKind
from pydantic import Field
from super_state_machine.errors import TransitionError
Expand Down Expand Up @@ -222,7 +221,7 @@ def mark_task_as_started(event: WorkerEvent, _: str | None) -> None:

LOGGER.info(f"Submitting: {trackable_task}")
try:
self._current_task_otel_context = get_trace_context()
self._current_task_otel_context = get_current()
sub = self.worker_events.subscribe(mark_task_as_started)
""" Cache the current trace context as the one for this task id """
self._task_channel.put_nowait(trackable_task)
Expand Down Expand Up @@ -326,7 +325,7 @@ def _cycle(self) -> None:
next_task # Informing mypy that the task is not None
)

self._current_task_otel_context = get_trace_context()
self._current_task_otel_context = get_current()
add_span_attributes({"next_task.task_id": next_task.task_id})

self._current.is_pending = False
Expand Down
20 changes: 7 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import pytest
from bluesky import RunEngine
from bluesky.run_engine import TransitionError
from observability_utils.tracing import setup_tracing
from observability_utils.tracing import JsonObjectSpanExporter, setup_tracing
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.trace import get_tracer_provider

from tests.unit_tests.utils.test_tracing import JsonObjectSpanExporter


@pytest.fixture(scope="function")
def RE(request):
Expand All @@ -33,15 +31,11 @@ def clean_event_loop():
return RE


@pytest.fixture
def provider() -> TracerProvider:
@pytest.fixture(scope="session")
def exporter() -> TracerProvider:
setup_tracing("test", False)
return cast(TracerProvider, get_tracer_provider())


@pytest.fixture
def exporter(provider: TracerProvider) -> JsonObjectSpanExporter:
exporter = JsonObjectSpanExporter()
processor = BatchSpanProcessor(exporter)
provider.add_span_processor(processor)
provider = cast(TracerProvider, get_tracer_provider())
# Use SimpleSpanProcessor to keep tests quick
provider.add_span_processor(SimpleSpanProcessor(exporter))
return exporter
2 changes: 1 addition & 1 deletion tests/unit_tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from bluesky_stomp.messaging import MessageContext
from tests.unit_tests.utils.test_tracing import (
from observability_utils.tracing import (
JsonObjectSpanExporter,
asserting_span_exporter,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/service/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from unittest.mock import MagicMock, patch

import pytest
from ophyd import Callable
from pydantic import BaseModel, ValidationError
from tests.unit_tests.utils.test_tracing import (
from observability_utils.tracing import (
JsonObjectSpanExporter,
asserting_span_exporter,
)
from ophyd import Callable
from pydantic import BaseModel, ValidationError

from blueapi.service import interface
from blueapi.service.model import EnvironmentResponse
Expand Down
52 changes: 0 additions & 52 deletions tests/unit_tests/utils/test_tracing.py

This file was deleted.

10 changes: 9 additions & 1 deletion tests/unit_tests/worker/test_task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest.mock import ANY, MagicMock, patch

import pytest
from tests.unit_tests.utils.test_tracing import (
from observability_utils.tracing import (
JsonObjectSpanExporter,
asserting_span_exporter,
)
Expand Down Expand Up @@ -554,3 +554,11 @@ def test_clear_task_span_ok(
with pytest.raises(KeyError):
with asserting_span_exporter(exporter, "clear_task", "task_id"):
worker.clear_task("foo")


def test_begin_task_span_ok(
exporter: JsonObjectSpanExporter, worker: TaskWorker
) -> None:
task_id = worker.submit_task(_SIMPLE_TASK)
with asserting_span_exporter(exporter, "begin_task", "task_id"):
worker.begin_task(task_id)

0 comments on commit d1b283b

Please sign in to comment.