File tree 2 files changed +26
-0
lines changed
tests/ert/unit_tests/plugins
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
+ from io import StringIO
3
+
4
+ from opentelemetry .sdk .trace .export import BatchSpanProcessor , ConsoleSpanExporter
2
5
3
6
from ert import ForwardModelStepPlugin , plugin
4
7
@@ -76,6 +79,14 @@ def add_log_handle_to_root():
76
79
return fh
77
80
78
81
82
+ span_output = StringIO ()
83
+
84
+
85
+ @plugin (name = "dummy" )
86
+ def add_span_processor ():
87
+ return BatchSpanProcessor (ConsoleSpanExporter (out = span_output ))
88
+
89
+
79
90
class DummyFMStep (ForwardModelStepPlugin ):
80
91
def __init__ (self ):
81
92
super ().__init__ (name = "DummyForwardModel" , command = ["touch" , "dummy.out" ])
Original file line number Diff line number Diff line change
1
+ import json
1
2
import logging
2
3
import tempfile
3
4
from unittest .mock import Mock
4
5
6
+ from opentelemetry .sdk .trace import TracerProvider
7
+
5
8
import ert .plugins .hook_implementations
6
9
from ert .plugins import ErtPluginManager
7
10
from tests .ert .unit_tests .plugins import dummy_plugins
@@ -115,6 +118,18 @@ def test_add_logging_handle(tmpdir):
115
118
assert "I should write this to spam.log" in result
116
119
117
120
121
+ def test_add_span_processor ():
122
+ pm = ErtPluginManager (plugins = [dummy_plugins ])
123
+ tracer_provider = TracerProvider ()
124
+ tracer = tracer_provider .get_tracer ("ert.tests" )
125
+ pm .add_span_processor_to_trace_provider (tracer_provider )
126
+ with tracer .start_as_current_span ("test_span" ):
127
+ print ("test_span" )
128
+ tracer_provider .force_flush ()
129
+ span_info = json .loads (dummy_plugins .span_output .getvalue ())
130
+ assert span_info ["name" ] == "test_span"
131
+
132
+
118
133
def test_that_forward_model_step_is_registered (tmpdir ):
119
134
with tmpdir .as_cwd ():
120
135
pm = ErtPluginManager (plugins = [dummy_plugins ])
You can’t perform that action at this time.
0 commit comments