Skip to content

Commit fc79f80

Browse files
committed
feat: add basic attributes
1 parent 9cc3e2c commit fc79f80

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
from opentelemetry.instrumentation.remoulade.package import _instruments
1010
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
1111
from opentelemetry.propagate import extract, inject
12+
from opentelemetry.semconv.trace import SpanAttributes
13+
14+
15+
_MESSAGE_TAG_KEY = "remoulade.action"
16+
_MESSAGE_SEND = "send"
17+
_MESSAGE_RUN = "run"
18+
19+
_MESSAGE_NAME_KEY = "remoulade.actor_name"
1220

1321

1422
class InstrumentationMiddleware(Middleware):
@@ -35,6 +43,10 @@ def after_process_message(self, _broker, message, *, result=None, exception=None
3543
return
3644

3745
if span.is_recording():
46+
span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_RUN)
47+
# utils.set_attributes_from_context(span, kwargs)
48+
# utils.set_attributes_from_context(span, task.request)
49+
span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name)
3850
pass
3951

4052
activation.__exit__(None, None, None)
@@ -46,7 +58,10 @@ def before_enqueue(self, _broker, message, delay):
4658
span = self._tracer.start_span(operation_name, kind=trace.SpanKind.PRODUCER)
4759

4860
if span.is_recording():
49-
# span.set_attribute("TEST_ATTRIBUTE", "TEST_VALUE")
61+
span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_SEND)
62+
span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id)
63+
span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name)
64+
# utils.set_attributes_from_context(span, kwargs)
5065
pass
5166

5267
activation = trace.use_span(span, end_on_exit=True)

instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import remoulade
22
from remoulade.brokers.local import LocalBroker
3-
from remoulade.results import Results
4-
from remoulade.results.backends import LocalBackend
53
from opentelemetry.instrumentation.remoulade import RemouladeInstrumentor
64
from opentelemetry.test.test_base import TestBase
75
from opentelemetry.trace import SpanKind
8-
6+
from opentelemetry.semconv.trace import SpanAttributes
97

108

119
@remoulade.actor
@@ -19,17 +17,13 @@ def setUp(self):
1917

2018
broker = LocalBroker()
2119

22-
# Should a backend be added to wait for the result ?
23-
# result_backend = LocalBackend()
24-
# broker.add_middleware(Results(backend=result_backend))
2520
remoulade.set_broker(broker)
2621
RemouladeInstrumentor().instrument()
2722

2823
broker.declare_actor(actor_multiply)
2924

3025
def test_message(self):
31-
message = actor_multiply.send(1, 2)
32-
# result = message.result.get(block=True)
26+
actor_multiply.send(1, 2)
3327

3428
spans = self.sorted_spans(self.memory_exporter.get_finished_spans())
3529
self.assertEqual(len(spans), 2)
@@ -38,9 +32,23 @@ def test_message(self):
3832

3933
self.assertEqual(consumer.name, "remoulade/process")
4034
self.assertEqual(consumer.kind, SpanKind.CONSUMER)
35+
self.assertSpanHasAttributes(
36+
consumer,
37+
{
38+
"remoulade.action": "run",
39+
"remoulade.actor_name": "actor_multiply",
40+
},
41+
)
4142

4243
self.assertEqual(producer.name, "remoulade/send")
4344
self.assertEqual(producer.kind, SpanKind.PRODUCER)
45+
self.assertSpanHasAttributes(
46+
producer,
47+
{
48+
"remoulade.action": "send",
49+
"remoulade.actor_name": "actor_multiply",
50+
},
51+
)
4452

4553
self.assertNotEqual(consumer.parent, producer.context)
4654
self.assertEqual(consumer.parent.span_id, producer.context.span_id)

0 commit comments

Comments
 (0)