diff --git a/automon/integrations/openTelemetryWrapper/client.py b/automon/integrations/openTelemetryWrapper/client.py index fb553acd..87eecf03 100644 --- a/automon/integrations/openTelemetryWrapper/client.py +++ b/automon/integrations/openTelemetryWrapper/client.py @@ -16,18 +16,18 @@ class OpenTelemetryClient(object): def __init__(self): self.config = OpenTelemetryConfig() - async def add_event(self, name: str, attributes: types.Attributes = None, **kwargs): + def add_event(self, name: str, attributes: types.Attributes = None, **kwargs): logger.debug(dict(name=name, attributes=attributes, kwargs=kwargs)) - span = await self.current_span() + span = self.current_span() return span.add_event(name=name, attributes=attributes, **kwargs) async def clear(self): logger.debug('clear') return await self.config.clear() - async def current_span(self): + def current_span(self): logger.debug('current_span') - return await self.config.current_span() + return self.config.current_span() async def is_ready(self): if await self.config.is_ready(): @@ -47,7 +47,7 @@ async def record_exception(self, exception: Exception): span.set_status(Status(StatusCode.ERROR)) return span.record_exception(exception=exception) - async def start_as_current_span( + def start_as_current_span( self, name: str, attributes: types.Attributes = None, **kwargs @@ -72,13 +72,25 @@ async def start_producer(self): async def test(self): with await self.start_as_current_span(name='rootSpan') as trace_root: - await self.add_event('AAAAAAAA') + self.config.opentelemetry.trace.get_current_span().add_event('AAAAAAAA') with await self.start_as_current_span(name='childSpan') as trace_child: - await self.add_event('AAAAAAAA') - await self.add_event('BBBBBBBB') + self.config.opentelemetry.trace.get_current_span().add_event('AAAAAAAA') + self.config.opentelemetry.trace.get_current_span().add_event('BBBBBBBB') + + self.config.opentelemetry.trace.get_current_span().add_event('BBBBBBBB') + + return True + + async def test2(self): + with self.config.tracer.start_as_current_span(name='rootSpan') as trace_root: + self.config.opentelemetry.trace.get_current_span().add_event('AAAAAAAA') + + with self.config.tracer.start_as_current_span(name='childSpan') as trace_child: + self.config.opentelemetry.trace.get_current_span().add_event('AAAAAAAA') + self.config.opentelemetry.trace.get_current_span().add_event('BBBBBBBB') - await self.add_event('BBBBBBBB') + self.config.opentelemetry.trace.get_current_span().add_event('BBBBBBBB') return True diff --git a/automon/integrations/openTelemetryWrapper/config.py b/automon/integrations/openTelemetryWrapper/config.py index e496b5ba..ac2327d5 100644 --- a/automon/integrations/openTelemetryWrapper/config.py +++ b/automon/integrations/openTelemetryWrapper/config.py @@ -13,6 +13,7 @@ class OpenTelemetryConfig(object): def __init__(self): + self.opentelemetry = opentelemetry self.provider = TracerProvider() self.memory_processor = InMemorySpanExporter() self.processor = SimpleSpanProcessor(self.memory_processor) @@ -29,7 +30,7 @@ async def clear(self): logger.debug('clear') return self.memory_processor.clear() - async def current_span(self): + def current_span(self): logger.debug('get_current_span') return opentelemetry.trace.get_current_span() diff --git a/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client.py b/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client.py deleted file mode 100644 index b00b7105..00000000 --- a/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client.py +++ /dev/null @@ -1,21 +0,0 @@ -# import unittest -# import asyncio -# -# from automon.integrations.openTelemetryWrapper import OpenTelemetryClient -# -# -# class MyTestCase(unittest.TestCase): -# client = OpenTelemetryClient() -# -# def test_something(self): -# self.assertTrue(asyncio.run( -# self.client.test())) -# -# spans = asyncio.run( -# self.client.get_finished_spans()) -# -# pass -# -# -# if __name__ == '__main__': -# unittest.main() diff --git a/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client_test1.py b/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client_test1.py new file mode 100644 index 00000000..01bda634 --- /dev/null +++ b/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client_test1.py @@ -0,0 +1,18 @@ +import unittest +import asyncio + +from automon.integrations.openTelemetryWrapper import OpenTelemetryClient + + +class MyTestCase(unittest.TestCase): + client = OpenTelemetryClient() + + def test_something(self): + self.assertTrue(asyncio.run( + self.client.test())) + + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client_test2.py b/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client_test2.py new file mode 100644 index 00000000..6b6cd75f --- /dev/null +++ b/automon/integrations/openTelemetryWrapper/test/test_memory_trace_client_test2.py @@ -0,0 +1,21 @@ +import unittest +import asyncio + +from automon.integrations.openTelemetryWrapper import OpenTelemetryClient + + +class MyTestCase(unittest.TestCase): + client = OpenTelemetryClient() + + def test_something(self): + self.assertTrue(asyncio.run( + self.client.test2())) + + spans = asyncio.run( + self.client.get_finished_spans()) + + pass + + +if __name__ == '__main__': + unittest.main()