Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- **[BUGFIX]**: fix(duration): snapshot duration not set [#37](https://github.com/intergral/deep/pull/37) [@Umaaz](https://github.com/Umaaz)
- **[BUGFIX]**: fix(attributes): snapshot attributes not set [#38](https://github.com/intergral/deep/pull/38) [@Umaaz](https://github.com/Umaaz)
- **[BUGFIX]**: fix(resource): discovered resources overwriting each other [#41](https://github.com/intergral/deep/pull/41) [@Umaaz](https://github.com/Umaaz)
- **[BUGFIX]**: feat(events): use events for snapshot in spans [#40](https://github.com/intergral/deep/pull/40) [@Umaaz](https://github.com/Umaaz)

# 1.1.0 (06/02/2024)

Expand Down
15 changes: 14 additions & 1 deletion src/deep/api/plugin/otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def add_attribute(self, key: str, value: str):
"""
self.proxy.set_attribute(key, value)

def add_event(self, name, attributes=None):
"""
Add an event to the span.

:param name: the event name
:param attributes: the event attributes
:return:
"""
self.proxy.add_event(name, attributes=attributes)

def close(self):
"""Close the span."""
if not self.proxy.end_time:
Expand Down Expand Up @@ -151,7 +161,10 @@ def decorate(self, snapshot_id: str, context: ActionContext) -> Optional[Bounded
"""
span = self.current_span()
if span is not None:
span.add_attribute("snapshot", snapshot_id)
span.add_event(context.location_action.location.name,
attributes={"snapshot": snapshot_id,
"tracepoint": context.location_action.id,
"context": context.trigger_context.id})
return BoundedAttributes(attributes={
"span_name": span.name,
"trace_id": span.trace_id,
Expand Down
11 changes: 11 additions & 0 deletions src/deep/api/plugin/span/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def add_attribute(self, key: str, value: str):
"""
pass

@abc.abstractmethod
def add_event(self, name, attributes=None):
"""
Add an event to the span.

:param name: the event name
:param attributes: the event attributes
:return:
"""
pass

@abc.abstractmethod
def close(self):
"""Close the span."""
Expand Down
16 changes: 14 additions & 2 deletions tests/unit_tests/api/plugin/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import unittest

import mockito
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource, SERVICE_NAME
from opentelemetry.sdk.trace import TracerProvider
Expand Down Expand Up @@ -41,12 +42,23 @@ def test_load_plugin(self):
def test_collect_attributes(self):
with trace.get_tracer_provider().get_tracer("test").start_as_current_span("test-span"):
plugin = OTelPlugin()
attributes = plugin.decorate("snap_id", None)

mock = mockito.mock()
mock.trigger_context = mock
mock.trigger_context.id = "id"
mock.location_action = mock
mock.location_action.id = "id"
mock.location_action.location = mock
mock.location_action.location.name = "test"

attributes = plugin.decorate("snap_id", mock)
self.assertIsNotNone(attributes)
self.assertEqual("test-span", attributes.get("span_name"))
self.assertIsNotNone(attributes.get("span_id"))
self.assertIsNotNone(attributes.get("trace_id"))
self.assertEqual(plugin.current_span().proxy.attributes, {"snapshot": "snap_id"})
self.assertEqual(plugin.current_span().proxy.events[0].name, "test")
self.assertEqual(plugin.current_span().proxy.events[0].attributes,
{'snapshot': 'snap_id', 'tracepoint': 'id', 'context': 'id'})

def test_create_span(self):
plugin = OTelPlugin()
Expand Down