divi 0.0.1.dev12__py3-none-macosx_11_0_arm64.whl → 0.0.1.dev13__py3-none-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. divi/__init__.py +1 -1
  2. divi/bin/core +0 -0
  3. divi/decorators/observable.py +75 -7
  4. divi/proto/common/v1/common.proto +6 -6
  5. divi/proto/common/v1/common_pb2.py +45 -0
  6. divi/proto/common/v1/common_pb2.pyi +56 -0
  7. divi/proto/core/health/v1/health_service_pb2.py +41 -0
  8. divi/proto/core/health/v1/health_service_pb2.pyi +19 -0
  9. divi/proto/core/health/v1/health_service_pb2_grpc.py +100 -0
  10. divi/proto/metric/v1/metric.proto +29 -0
  11. divi/proto/metric/v1/metric_pb2.py +40 -0
  12. divi/proto/metric/v1/metric_pb2.pyi +27 -0
  13. divi/proto/run/v1/run.proto +38 -0
  14. divi/proto/run/v1/run_pb2.py +40 -0
  15. divi/proto/run/v1/run_pb2.pyi +34 -0
  16. divi/proto/trace/v1/trace.proto +40 -8
  17. divi/proto/trace/v1/trace_pb2.py +42 -0
  18. divi/proto/trace/v1/trace_pb2.pyi +42 -0
  19. divi/run/__init__.py +2 -2
  20. divi/run/run.py +23 -1
  21. divi/run/setup.py +50 -0
  22. divi/run/teardown.py +7 -0
  23. divi/services/auth/init.py +2 -5
  24. divi/services/core/core.py +3 -3
  25. divi/services/core/init.py +5 -12
  26. divi/services/datapark/__init__.py +2 -1
  27. divi/services/datapark/init.py +2 -6
  28. divi/services/finish.py +4 -0
  29. divi/services/init.py +8 -2
  30. divi/signals/__init__.py +2 -3
  31. divi/signals/trace/__init__.py +2 -2
  32. divi/signals/trace/trace.py +81 -2
  33. {divi-0.0.1.dev12.dist-info → divi-0.0.1.dev13.dist-info}/METADATA +1 -1
  34. divi-0.0.1.dev13.dist-info/RECORD +49 -0
  35. divi/proto/resource/v1/resource.proto +0 -19
  36. divi/signals/metric/__init__.py +0 -3
  37. divi/signals/metric/metric.py +0 -2
  38. divi-0.0.1.dev12.dist-info/RECORD +0 -37
  39. {divi-0.0.1.dev12.dist-info → divi-0.0.1.dev13.dist-info}/WHEEL +0 -0
  40. {divi-0.0.1.dev12.dist-info → divi-0.0.1.dev13.dist-info}/licenses/LICENSE +0 -0
divi/__init__.py CHANGED
@@ -12,5 +12,5 @@ _core: Optional[Core] = None
12
12
  _auth: Optional[Auth] = None
13
13
  _datapark: Optional[DataPark] = None
14
14
 
15
- __version__ = "0.0.1.dev12"
15
+ __version__ = "0.0.1.dev13"
16
16
  __all__ = ["proto", "obs_openai", "observable"]
divi/bin/core CHANGED
Binary file
@@ -1,32 +1,100 @@
1
+ import contextvars
1
2
  import functools
2
3
  import inspect
3
- from typing import Any, Callable, List, overload
4
+ from typing import (
5
+ Any,
6
+ Callable,
7
+ Generic,
8
+ List,
9
+ Mapping,
10
+ Optional,
11
+ ParamSpec,
12
+ Protocol,
13
+ TypeVar,
14
+ Union,
15
+ overload,
16
+ runtime_checkable,
17
+ )
18
+
19
+ from divi.run import RunExtra
20
+ from divi.run.setup import setup
21
+ from divi.signals.trace import Span
22
+
23
+ R = TypeVar("R", covariant=True)
24
+ P = ParamSpec("P")
25
+
26
+ # ContextVar to store the extra information
27
+ # from the Run and parent Span
28
+ _RUNEXTRA = contextvars.ContextVar[Optional[RunExtra]](
29
+ "_RUNEXTRA", default=None
30
+ )
31
+
32
+
33
+ @runtime_checkable
34
+ class WithRunExtra(Protocol, Generic[P, R]):
35
+ def __call__(
36
+ self,
37
+ *args: P.args,
38
+ run_extra: Optional[RunExtra] = None, # type: ignore[valid-type]
39
+ **kwargs: P.kwargs,
40
+ ) -> R: ...
4
41
 
5
42
 
6
43
  @overload
7
- def observable(func: Callable) -> Callable: ...
44
+ def observable(func: Callable[P, R]) -> WithRunExtra[P, R]: ...
8
45
 
9
46
 
10
47
  @overload
11
- def observable() -> Callable: ...
48
+ def observable(
49
+ kind: str = "function",
50
+ *,
51
+ name: Optional[str] = None,
52
+ metadata: Optional[Mapping[str, Any]] = None,
53
+ ) -> Callable[[Callable[P, R]], WithRunExtra[P, R]]: ...
12
54
 
13
55
 
14
- def observable(*args, **kwargs) -> Callable:
56
+ def observable(
57
+ *args, **kwargs
58
+ ) -> Union[Callable, Callable[[Callable], Callable]]:
15
59
  """Observable decorator factory."""
16
60
 
17
- def decorator(func: Callable):
61
+ kind = kwargs.pop("kind", "function")
62
+ name = kwargs.pop("name", None)
63
+ metadata = kwargs.pop("metadata", None)
64
+
65
+ def decorator(func):
66
+ span = Span(kind=kind, name=name or func.__name__, metadata=metadata)
67
+
18
68
  @functools.wraps(func)
19
- def wrapper(*args, **kwargs):
69
+ def wrapper(*args, run_extra: Optional[RunExtra] = None, **kwargs):
70
+ run_extra = setup(span, _RUNEXTRA.get() or run_extra)
71
+ # set current context
72
+ token = _RUNEXTRA.set(run_extra)
73
+ # execute the function
74
+ span.start()
20
75
  result = func(*args, **kwargs)
76
+ span.end()
77
+ # recover parent context
78
+ _RUNEXTRA.reset(token)
21
79
  # TODO: collect result
22
80
  return result
23
81
 
24
82
  @functools.wraps(func)
25
- def generator_wrapper(*args, **kwargs):
83
+ def generator_wrapper(
84
+ *args, run_extra: Optional[RunExtra] = None, **kwargs
85
+ ):
86
+ run_extra = setup(span, _RUNEXTRA.get() or run_extra)
87
+ # set current context
88
+ token = _RUNEXTRA.set(run_extra)
89
+ # execute the function
26
90
  results: List[Any] = []
91
+ span.start()
27
92
  for item in func(*args, **kwargs):
28
93
  results.append(item)
29
94
  yield item
95
+ span.end()
96
+ # recover parent context
97
+ _RUNEXTRA.reset(token)
30
98
  # TODO: collect results
31
99
 
32
100
  if inspect.isgeneratorfunction(func):
@@ -48,12 +48,12 @@ message KeyValue {
48
48
  AnyValue value = 2;
49
49
  }
50
50
 
51
- // InstrumentationScope is a message representing the instrumentation scope information
52
- // such as the fully qualified name and version.
53
- message InstrumentationScope {
54
- // An empty instrumentation scope name means the name is unknown.
55
- string name = 1;
56
- string version = 2;
51
+ // RunScope specifies the scope of the message
52
+ message RunScope {
53
+ // The run_id is a unique identifier that represents a run. It is a 16-byte array.
54
+ bytes run_id = 1;
55
+ // The name of the run.
56
+ string run_name = 2;
57
57
 
58
58
  // Additional attributes that describe the scope. [Optional].
59
59
  // Attribute keys MUST be unique (it is not allowed to have more than one
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: divi/proto/common/v1/common.proto
5
+ # Protobuf Python Version: 5.29.0
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 5,
15
+ 29,
16
+ 0,
17
+ '',
18
+ 'divi/proto/common/v1/common.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n!divi/proto/common/v1/common.proto\x12\x14\x64ivi.proto.common.v1\"\xfa\x01\n\x08\x41nyValue\x12\x16\n\x0cstring_value\x18\x01 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x02 \x01(\x08H\x00\x12\x13\n\tint_value\x18\x03 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x04 \x01(\x01H\x00\x12\x37\n\x0b\x61rray_value\x18\x05 \x01(\x0b\x32 .divi.proto.common.v1.ArrayValueH\x00\x12:\n\x0ckvlist_value\x18\x06 \x01(\x0b\x32\".divi.proto.common.v1.KeyValueListH\x00\x12\x15\n\x0b\x62ytes_value\x18\x07 \x01(\x0cH\x00\x42\x07\n\x05value\"<\n\nArrayValue\x12.\n\x06values\x18\x01 \x03(\x0b\x32\x1e.divi.proto.common.v1.AnyValue\">\n\x0cKeyValueList\x12.\n\x06values\x18\x01 \x03(\x0b\x32\x1e.divi.proto.common.v1.KeyValue\"F\n\x08KeyValue\x12\x0b\n\x03key\x18\x01 \x01(\t\x12-\n\x05value\x18\x02 \x01(\x0b\x32\x1e.divi.proto.common.v1.AnyValue\"\x82\x01\n\x08RunScope\x12\x0e\n\x06run_id\x18\x01 \x01(\x0c\x12\x10\n\x08run_name\x18\x02 \x01(\t\x12\x32\n\nattributes\x18\x03 \x03(\x0b\x32\x1e.divi.proto.common.v1.KeyValue\x12 \n\x18\x64ropped_attributes_count\x18\x04 \x01(\rB\x10Z\x0eservices/protob\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'divi.proto.common.v1.common_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'Z\016services/proto'
35
+ _globals['_ANYVALUE']._serialized_start=60
36
+ _globals['_ANYVALUE']._serialized_end=310
37
+ _globals['_ARRAYVALUE']._serialized_start=312
38
+ _globals['_ARRAYVALUE']._serialized_end=372
39
+ _globals['_KEYVALUELIST']._serialized_start=374
40
+ _globals['_KEYVALUELIST']._serialized_end=436
41
+ _globals['_KEYVALUE']._serialized_start=438
42
+ _globals['_KEYVALUE']._serialized_end=508
43
+ _globals['_RUNSCOPE']._serialized_start=511
44
+ _globals['_RUNSCOPE']._serialized_end=641
45
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,56 @@
1
+ from google.protobuf.internal import containers as _containers
2
+ from google.protobuf import descriptor as _descriptor
3
+ from google.protobuf import message as _message
4
+ from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
5
+
6
+ DESCRIPTOR: _descriptor.FileDescriptor
7
+
8
+ class AnyValue(_message.Message):
9
+ __slots__ = ("string_value", "bool_value", "int_value", "double_value", "array_value", "kvlist_value", "bytes_value")
10
+ STRING_VALUE_FIELD_NUMBER: _ClassVar[int]
11
+ BOOL_VALUE_FIELD_NUMBER: _ClassVar[int]
12
+ INT_VALUE_FIELD_NUMBER: _ClassVar[int]
13
+ DOUBLE_VALUE_FIELD_NUMBER: _ClassVar[int]
14
+ ARRAY_VALUE_FIELD_NUMBER: _ClassVar[int]
15
+ KVLIST_VALUE_FIELD_NUMBER: _ClassVar[int]
16
+ BYTES_VALUE_FIELD_NUMBER: _ClassVar[int]
17
+ string_value: str
18
+ bool_value: bool
19
+ int_value: int
20
+ double_value: float
21
+ array_value: ArrayValue
22
+ kvlist_value: KeyValueList
23
+ bytes_value: bytes
24
+ def __init__(self, string_value: _Optional[str] = ..., bool_value: bool = ..., int_value: _Optional[int] = ..., double_value: _Optional[float] = ..., array_value: _Optional[_Union[ArrayValue, _Mapping]] = ..., kvlist_value: _Optional[_Union[KeyValueList, _Mapping]] = ..., bytes_value: _Optional[bytes] = ...) -> None: ...
25
+
26
+ class ArrayValue(_message.Message):
27
+ __slots__ = ("values",)
28
+ VALUES_FIELD_NUMBER: _ClassVar[int]
29
+ values: _containers.RepeatedCompositeFieldContainer[AnyValue]
30
+ def __init__(self, values: _Optional[_Iterable[_Union[AnyValue, _Mapping]]] = ...) -> None: ...
31
+
32
+ class KeyValueList(_message.Message):
33
+ __slots__ = ("values",)
34
+ VALUES_FIELD_NUMBER: _ClassVar[int]
35
+ values: _containers.RepeatedCompositeFieldContainer[KeyValue]
36
+ def __init__(self, values: _Optional[_Iterable[_Union[KeyValue, _Mapping]]] = ...) -> None: ...
37
+
38
+ class KeyValue(_message.Message):
39
+ __slots__ = ("key", "value")
40
+ KEY_FIELD_NUMBER: _ClassVar[int]
41
+ VALUE_FIELD_NUMBER: _ClassVar[int]
42
+ key: str
43
+ value: AnyValue
44
+ def __init__(self, key: _Optional[str] = ..., value: _Optional[_Union[AnyValue, _Mapping]] = ...) -> None: ...
45
+
46
+ class RunScope(_message.Message):
47
+ __slots__ = ("run_id", "run_name", "attributes", "dropped_attributes_count")
48
+ RUN_ID_FIELD_NUMBER: _ClassVar[int]
49
+ RUN_NAME_FIELD_NUMBER: _ClassVar[int]
50
+ ATTRIBUTES_FIELD_NUMBER: _ClassVar[int]
51
+ DROPPED_ATTRIBUTES_COUNT_FIELD_NUMBER: _ClassVar[int]
52
+ run_id: bytes
53
+ run_name: str
54
+ attributes: _containers.RepeatedCompositeFieldContainer[KeyValue]
55
+ dropped_attributes_count: int
56
+ def __init__(self, run_id: _Optional[bytes] = ..., run_name: _Optional[str] = ..., attributes: _Optional[_Iterable[_Union[KeyValue, _Mapping]]] = ..., dropped_attributes_count: _Optional[int] = ...) -> None: ...
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: divi/proto/core/health/v1/health_service.proto
5
+ # Protobuf Python Version: 5.29.0
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 5,
15
+ 29,
16
+ 0,
17
+ '',
18
+ 'divi/proto/core/health/v1/health_service.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n.divi/proto/core/health/v1/health_service.proto\x12\x19\x64ivi.proto.core.health.v1\"%\n\x12HealthCheckRequest\x12\x0f\n\x07version\x18\x01 \x01(\t\"6\n\x13HealthCheckResponse\x12\x0e\n\x06status\x18\x01 \x01(\x08\x12\x0f\n\x07message\x18\x02 \x01(\t2y\n\rHealthService\x12h\n\x05\x43heck\x12-.divi.proto.core.health.v1.HealthCheckRequest\x1a..divi.proto.core.health.v1.HealthCheckResponse\"\x00\x42\x10Z\x0eservices/protob\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'divi.proto.core.health.v1.health_service_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'Z\016services/proto'
35
+ _globals['_HEALTHCHECKREQUEST']._serialized_start=77
36
+ _globals['_HEALTHCHECKREQUEST']._serialized_end=114
37
+ _globals['_HEALTHCHECKRESPONSE']._serialized_start=116
38
+ _globals['_HEALTHCHECKRESPONSE']._serialized_end=170
39
+ _globals['_HEALTHSERVICE']._serialized_start=172
40
+ _globals['_HEALTHSERVICE']._serialized_end=293
41
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,19 @@
1
+ from google.protobuf import descriptor as _descriptor
2
+ from google.protobuf import message as _message
3
+ from typing import ClassVar as _ClassVar, Optional as _Optional
4
+
5
+ DESCRIPTOR: _descriptor.FileDescriptor
6
+
7
+ class HealthCheckRequest(_message.Message):
8
+ __slots__ = ("version",)
9
+ VERSION_FIELD_NUMBER: _ClassVar[int]
10
+ version: str
11
+ def __init__(self, version: _Optional[str] = ...) -> None: ...
12
+
13
+ class HealthCheckResponse(_message.Message):
14
+ __slots__ = ("status", "message")
15
+ STATUS_FIELD_NUMBER: _ClassVar[int]
16
+ MESSAGE_FIELD_NUMBER: _ClassVar[int]
17
+ status: bool
18
+ message: str
19
+ def __init__(self, status: bool = ..., message: _Optional[str] = ...) -> None: ...
@@ -0,0 +1,100 @@
1
+ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2
+ """Client and server classes corresponding to protobuf-defined services."""
3
+ import grpc
4
+ import warnings
5
+
6
+ from divi.proto.core.health.v1 import health_service_pb2 as divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2
7
+
8
+ GRPC_GENERATED_VERSION = '1.69.0'
9
+ GRPC_VERSION = grpc.__version__
10
+ _version_not_supported = False
11
+
12
+ try:
13
+ from grpc._utilities import first_version_is_lower
14
+ _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
15
+ except ImportError:
16
+ _version_not_supported = True
17
+
18
+ if _version_not_supported:
19
+ raise RuntimeError(
20
+ f'The grpc package installed is at version {GRPC_VERSION},'
21
+ + f' but the generated code in divi/proto/core/health/v1/health_service_pb2_grpc.py depends on'
22
+ + f' grpcio>={GRPC_GENERATED_VERSION}.'
23
+ + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
24
+ + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
25
+ )
26
+
27
+
28
+ class HealthServiceStub(object):
29
+ """HealthService is a service that implements health check.
30
+ """
31
+
32
+ def __init__(self, channel):
33
+ """Constructor.
34
+
35
+ Args:
36
+ channel: A grpc.Channel.
37
+ """
38
+ self.Check = channel.unary_unary(
39
+ '/divi.proto.core.health.v1.HealthService/Check',
40
+ request_serializer=divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2.HealthCheckRequest.SerializeToString,
41
+ response_deserializer=divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2.HealthCheckResponse.FromString,
42
+ _registered_method=True)
43
+
44
+
45
+ class HealthServiceServicer(object):
46
+ """HealthService is a service that implements health check.
47
+ """
48
+
49
+ def Check(self, request, context):
50
+ """Missing associated documentation comment in .proto file."""
51
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
52
+ context.set_details('Method not implemented!')
53
+ raise NotImplementedError('Method not implemented!')
54
+
55
+
56
+ def add_HealthServiceServicer_to_server(servicer, server):
57
+ rpc_method_handlers = {
58
+ 'Check': grpc.unary_unary_rpc_method_handler(
59
+ servicer.Check,
60
+ request_deserializer=divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2.HealthCheckRequest.FromString,
61
+ response_serializer=divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2.HealthCheckResponse.SerializeToString,
62
+ ),
63
+ }
64
+ generic_handler = grpc.method_handlers_generic_handler(
65
+ 'divi.proto.core.health.v1.HealthService', rpc_method_handlers)
66
+ server.add_generic_rpc_handlers((generic_handler,))
67
+ server.add_registered_method_handlers('divi.proto.core.health.v1.HealthService', rpc_method_handlers)
68
+
69
+
70
+ # This class is part of an EXPERIMENTAL API.
71
+ class HealthService(object):
72
+ """HealthService is a service that implements health check.
73
+ """
74
+
75
+ @staticmethod
76
+ def Check(request,
77
+ target,
78
+ options=(),
79
+ channel_credentials=None,
80
+ call_credentials=None,
81
+ insecure=False,
82
+ compression=None,
83
+ wait_for_ready=None,
84
+ timeout=None,
85
+ metadata=None):
86
+ return grpc.experimental.unary_unary(
87
+ request,
88
+ target,
89
+ '/divi.proto.core.health.v1.HealthService/Check',
90
+ divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2.HealthCheckRequest.SerializeToString,
91
+ divi_dot_proto_dot_core_dot_health_dot_v1_dot_health__service__pb2.HealthCheckResponse.FromString,
92
+ options,
93
+ channel_credentials,
94
+ insecure,
95
+ call_credentials,
96
+ compression,
97
+ wait_for_ready,
98
+ timeout,
99
+ metadata,
100
+ _registered_method=True)
@@ -0,0 +1,29 @@
1
+ syntax = "proto3";
2
+
3
+ package divi.proto.metric.v1;
4
+
5
+ import "divi/proto/common/v1/common.proto";
6
+
7
+ option go_package = "services/proto";
8
+
9
+ message ScopeMetrics {
10
+ // The scope of the message
11
+ divi.proto.common.v1.RunScope scope = 1;
12
+
13
+ // A list of spans that originate from a resource.
14
+ repeated Metric metrics = 2;
15
+ }
16
+
17
+ message Metric {
18
+ // The name of the metric.
19
+ string name = 1;
20
+
21
+ // The description of the metric.
22
+ string description = 2;
23
+
24
+ // The data of the metric.
25
+ divi.proto.common.v1.AnyValue data = 3;
26
+
27
+ // The metadata is a set of attributes that describe the span.
28
+ repeated divi.proto.common.v1.KeyValue metadata = 4;
29
+ }
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: divi/proto/metric/v1/metric.proto
5
+ # Protobuf Python Version: 5.29.0
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 5,
15
+ 29,
16
+ 0,
17
+ '',
18
+ 'divi/proto/metric/v1/metric.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from divi.proto.common.v1 import common_pb2 as divi_dot_proto_dot_common_dot_v1_dot_common__pb2
26
+
27
+
28
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n!divi/proto/metric/v1/metric.proto\x12\x14\x64ivi.proto.metric.v1\x1a!divi/proto/common/v1/common.proto\"l\n\x0cScopeMetrics\x12-\n\x05scope\x18\x01 \x01(\x0b\x32\x1e.divi.proto.common.v1.RunScope\x12-\n\x07metrics\x18\x02 \x03(\x0b\x32\x1c.divi.proto.metric.v1.Metric\"\x8b\x01\n\x06Metric\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12,\n\x04\x64\x61ta\x18\x03 \x01(\x0b\x32\x1e.divi.proto.common.v1.AnyValue\x12\x30\n\x08metadata\x18\x04 \x03(\x0b\x32\x1e.divi.proto.common.v1.KeyValueB\x10Z\x0eservices/protob\x06proto3')
29
+
30
+ _globals = globals()
31
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
32
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'divi.proto.metric.v1.metric_pb2', _globals)
33
+ if not _descriptor._USE_C_DESCRIPTORS:
34
+ _globals['DESCRIPTOR']._loaded_options = None
35
+ _globals['DESCRIPTOR']._serialized_options = b'Z\016services/proto'
36
+ _globals['_SCOPEMETRICS']._serialized_start=94
37
+ _globals['_SCOPEMETRICS']._serialized_end=202
38
+ _globals['_METRIC']._serialized_start=205
39
+ _globals['_METRIC']._serialized_end=344
40
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,27 @@
1
+ from divi.proto.common.v1 import common_pb2 as _common_pb2
2
+ from google.protobuf.internal import containers as _containers
3
+ from google.protobuf import descriptor as _descriptor
4
+ from google.protobuf import message as _message
5
+ from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
6
+
7
+ DESCRIPTOR: _descriptor.FileDescriptor
8
+
9
+ class ScopeMetrics(_message.Message):
10
+ __slots__ = ("scope", "metrics")
11
+ SCOPE_FIELD_NUMBER: _ClassVar[int]
12
+ METRICS_FIELD_NUMBER: _ClassVar[int]
13
+ scope: _common_pb2.RunScope
14
+ metrics: _containers.RepeatedCompositeFieldContainer[Metric]
15
+ def __init__(self, scope: _Optional[_Union[_common_pb2.RunScope, _Mapping]] = ..., metrics: _Optional[_Iterable[_Union[Metric, _Mapping]]] = ...) -> None: ...
16
+
17
+ class Metric(_message.Message):
18
+ __slots__ = ("name", "description", "data", "metadata")
19
+ NAME_FIELD_NUMBER: _ClassVar[int]
20
+ DESCRIPTION_FIELD_NUMBER: _ClassVar[int]
21
+ DATA_FIELD_NUMBER: _ClassVar[int]
22
+ METADATA_FIELD_NUMBER: _ClassVar[int]
23
+ name: str
24
+ description: str
25
+ data: _common_pb2.AnyValue
26
+ metadata: _containers.RepeatedCompositeFieldContainer[_common_pb2.KeyValue]
27
+ def __init__(self, name: _Optional[str] = ..., description: _Optional[str] = ..., data: _Optional[_Union[_common_pb2.AnyValue, _Mapping]] = ..., metadata: _Optional[_Iterable[_Union[_common_pb2.KeyValue, _Mapping]]] = ...) -> None: ...
@@ -0,0 +1,38 @@
1
+ syntax = "proto3";
2
+
3
+ package divi.proto.run.v1;
4
+
5
+ import "divi/proto/common/v1/common.proto";
6
+
7
+ option go_package = "services/proto";
8
+
9
+ message Run {
10
+ // The run_id is the unique identifier of the run. It is a 16-byte array.
11
+ bytes run_id = 1;
12
+
13
+ // The name of the run.
14
+ string name = 2;
15
+
16
+ enum RunKind {
17
+ // Observation represents a run that is used for observation.
18
+ Observation = 0;
19
+
20
+ // Evaluation represents a run that is used for evaluation.
21
+ Evaluation = 1;
22
+
23
+ // Dataset represents a run that is used for creating a dataset.
24
+ Dataset = 2;
25
+ }
26
+
27
+ // The kind of the run.
28
+ RunKind kind = 3;
29
+
30
+ // The start_time_unix_nano is the start time of the run in Unix nanoseconds.
31
+ fixed64 start_time_unix_nano = 4;
32
+
33
+ // The end_time_unix_nano is the end time of the run in Unix nanoseconds.
34
+ fixed64 end_time_unix_nano = 5;
35
+
36
+ // The metadata is a set of attributes that describe the run.
37
+ repeated divi.proto.common.v1.KeyValue metadata = 6;
38
+ }
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: divi/proto/run/v1/run.proto
5
+ # Protobuf Python Version: 5.29.0
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 5,
15
+ 29,
16
+ 0,
17
+ '',
18
+ 'divi/proto/run/v1/run.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from divi.proto.common.v1 import common_pb2 as divi_dot_proto_dot_common_dot_v1_dot_common__pb2
26
+
27
+
28
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1b\x64ivi/proto/run/v1/run.proto\x12\x11\x64ivi.proto.run.v1\x1a!divi/proto/common/v1/common.proto\"\x87\x02\n\x03Run\x12\x0f\n\x07user_id\x18\x01 \x01(\x0c\x12\x0e\n\x06run_id\x18\x02 \x01(\x0c\x12\x0c\n\x04name\x18\x03 \x01(\t\x12,\n\x04kind\x18\x04 \x01(\x0e\x32\x1e.divi.proto.run.v1.Run.RunKind\x12\x1c\n\x14start_time_unix_nano\x18\x05 \x01(\x06\x12\x1a\n\x12\x65nd_time_unix_nano\x18\x06 \x01(\x06\x12\x30\n\x08metadata\x18\x07 \x03(\x0b\x32\x1e.divi.proto.common.v1.KeyValue\"7\n\x07RunKind\x12\x0f\n\x0bObservation\x10\x00\x12\x0e\n\nEvaluation\x10\x01\x12\x0b\n\x07\x44\x61taset\x10\x02\x42\x10Z\x0eservices/protob\x06proto3')
29
+
30
+ _globals = globals()
31
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
32
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'divi.proto.run.v1.run_pb2', _globals)
33
+ if not _descriptor._USE_C_DESCRIPTORS:
34
+ _globals['DESCRIPTOR']._loaded_options = None
35
+ _globals['DESCRIPTOR']._serialized_options = b'Z\016services/proto'
36
+ _globals['_RUN']._serialized_start=86
37
+ _globals['_RUN']._serialized_end=349
38
+ _globals['_RUN_RUNKIND']._serialized_start=294
39
+ _globals['_RUN_RUNKIND']._serialized_end=349
40
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,34 @@
1
+ from divi.proto.common.v1 import common_pb2 as _common_pb2
2
+ from google.protobuf.internal import containers as _containers
3
+ from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
4
+ from google.protobuf import descriptor as _descriptor
5
+ from google.protobuf import message as _message
6
+ from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
7
+
8
+ DESCRIPTOR: _descriptor.FileDescriptor
9
+
10
+ class Run(_message.Message):
11
+ __slots__ = ("user_id", "run_id", "name", "kind", "start_time_unix_nano", "end_time_unix_nano", "metadata")
12
+ class RunKind(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
13
+ __slots__ = ()
14
+ Observation: _ClassVar[Run.RunKind]
15
+ Evaluation: _ClassVar[Run.RunKind]
16
+ Dataset: _ClassVar[Run.RunKind]
17
+ Observation: Run.RunKind
18
+ Evaluation: Run.RunKind
19
+ Dataset: Run.RunKind
20
+ USER_ID_FIELD_NUMBER: _ClassVar[int]
21
+ RUN_ID_FIELD_NUMBER: _ClassVar[int]
22
+ NAME_FIELD_NUMBER: _ClassVar[int]
23
+ KIND_FIELD_NUMBER: _ClassVar[int]
24
+ START_TIME_UNIX_NANO_FIELD_NUMBER: _ClassVar[int]
25
+ END_TIME_UNIX_NANO_FIELD_NUMBER: _ClassVar[int]
26
+ METADATA_FIELD_NUMBER: _ClassVar[int]
27
+ user_id: bytes
28
+ run_id: bytes
29
+ name: str
30
+ kind: Run.RunKind
31
+ start_time_unix_nano: int
32
+ end_time_unix_nano: int
33
+ metadata: _containers.RepeatedCompositeFieldContainer[_common_pb2.KeyValue]
34
+ def __init__(self, user_id: _Optional[bytes] = ..., run_id: _Optional[bytes] = ..., name: _Optional[str] = ..., kind: _Optional[_Union[Run.RunKind, str]] = ..., start_time_unix_nano: _Optional[int] = ..., end_time_unix_nano: _Optional[int] = ..., metadata: _Optional[_Iterable[_Union[_common_pb2.KeyValue, _Mapping]]] = ...) -> None: ...
@@ -2,17 +2,49 @@ syntax = "proto3";
2
2
 
3
3
  package divi.proto.trace.v1;
4
4
 
5
- import "divi/proto/resource/v1/resource.proto";
5
+ import "divi/proto/common/v1/common.proto";
6
6
 
7
7
  option go_package = "services/proto";
8
8
 
9
- message TracesData {
10
- // An array of ResourceSpans.
11
- // For data coming from a single resource this array will typically contain one element.
12
- repeated ResourceSpans resource_spans = 1;
9
+ message ScopeSpans {
10
+ // The scope of the message
11
+ divi.proto.common.v1.RunScope scope = 1;
12
+
13
+ // A list of spans that originate from a resource.
14
+ repeated Span spans = 2;
13
15
  }
14
16
 
15
- message ResourceSpans {
16
- // The resource for which the spans are reported.
17
- divi.proto.resource.v1.Resource resource = 1;
17
+ message Span {
18
+ // The trace_id is a unique identifier that represents a trace. It is a 16-byte array.
19
+ bytes trace_id = 1;
20
+
21
+ // The span_id is a unique identifier that represents a span. It is an 8-byte array.
22
+ bytes span_id = 2;
23
+
24
+ // The parent_span_id is the span_id of the parent span. It is an 8-byte array.
25
+ bytes parent_span_id = 3;
26
+
27
+ // The name of the span.
28
+ string name = 4;
29
+
30
+ // SpanKind is the type of the span.
31
+ enum SpanKind {
32
+ // Function represents a function call.
33
+ SPAN_KIND_FUNCTION = 0;
34
+
35
+ // LLM represents a llm api call.
36
+ SPAN_KIND_LLM = 1;
37
+ }
38
+
39
+ // The kind of the span.
40
+ SpanKind kind = 5;
41
+
42
+ // The start_time_unix_nano is the start time of the span in Unix nanoseconds.
43
+ fixed64 start_time_unix_nano = 6;
44
+
45
+ // The end_time_unix_nano is the end time of the span in Unix nanoseconds.
46
+ fixed64 end_time_unix_nano = 7;
47
+
48
+ // The metadata is a set of attributes that describe the span.
49
+ repeated divi.proto.common.v1.KeyValue metadata = 8;
18
50
  }
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: divi/proto/trace/v1/trace.proto
5
+ # Protobuf Python Version: 5.29.0
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 5,
15
+ 29,
16
+ 0,
17
+ '',
18
+ 'divi/proto/trace/v1/trace.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from divi.proto.common.v1 import common_pb2 as divi_dot_proto_dot_common_dot_v1_dot_common__pb2
26
+
27
+
28
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1f\x64ivi/proto/trace/v1/trace.proto\x12\x13\x64ivi.proto.trace.v1\x1a!divi/proto/common/v1/common.proto\"e\n\nScopeSpans\x12-\n\x05scope\x18\x01 \x01(\x0b\x32\x1e.divi.proto.common.v1.RunScope\x12(\n\x05spans\x18\x02 \x03(\x0b\x32\x19.divi.proto.trace.v1.Span\"\xa4\x02\n\x04Span\x12\x10\n\x08trace_id\x18\x01 \x01(\x0c\x12\x0f\n\x07span_id\x18\x02 \x01(\x0c\x12\x16\n\x0eparent_span_id\x18\x03 \x01(\x0c\x12\x0c\n\x04name\x18\x04 \x01(\t\x12\x30\n\x04kind\x18\x05 \x01(\x0e\x32\".divi.proto.trace.v1.Span.SpanKind\x12\x1c\n\x14start_time_unix_nano\x18\x06 \x01(\x06\x12\x1a\n\x12\x65nd_time_unix_nano\x18\x07 \x01(\x06\x12\x30\n\x08metadata\x18\x08 \x03(\x0b\x32\x1e.divi.proto.common.v1.KeyValue\"5\n\x08SpanKind\x12\x16\n\x12SPAN_KIND_FUNCTION\x10\x00\x12\x11\n\rSPAN_KIND_LLM\x10\x01\x42\x10Z\x0eservices/protob\x06proto3')
29
+
30
+ _globals = globals()
31
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
32
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'divi.proto.trace.v1.trace_pb2', _globals)
33
+ if not _descriptor._USE_C_DESCRIPTORS:
34
+ _globals['DESCRIPTOR']._loaded_options = None
35
+ _globals['DESCRIPTOR']._serialized_options = b'Z\016services/proto'
36
+ _globals['_SCOPESPANS']._serialized_start=91
37
+ _globals['_SCOPESPANS']._serialized_end=192
38
+ _globals['_SPAN']._serialized_start=195
39
+ _globals['_SPAN']._serialized_end=487
40
+ _globals['_SPAN_SPANKIND']._serialized_start=434
41
+ _globals['_SPAN_SPANKIND']._serialized_end=487
42
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,42 @@
1
+ from divi.proto.common.v1 import common_pb2 as _common_pb2
2
+ from google.protobuf.internal import containers as _containers
3
+ from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
4
+ from google.protobuf import descriptor as _descriptor
5
+ from google.protobuf import message as _message
6
+ from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
7
+
8
+ DESCRIPTOR: _descriptor.FileDescriptor
9
+
10
+ class ScopeSpans(_message.Message):
11
+ __slots__ = ("scope", "spans")
12
+ SCOPE_FIELD_NUMBER: _ClassVar[int]
13
+ SPANS_FIELD_NUMBER: _ClassVar[int]
14
+ scope: _common_pb2.RunScope
15
+ spans: _containers.RepeatedCompositeFieldContainer[Span]
16
+ def __init__(self, scope: _Optional[_Union[_common_pb2.RunScope, _Mapping]] = ..., spans: _Optional[_Iterable[_Union[Span, _Mapping]]] = ...) -> None: ...
17
+
18
+ class Span(_message.Message):
19
+ __slots__ = ("trace_id", "span_id", "parent_span_id", "name", "kind", "start_time_unix_nano", "end_time_unix_nano", "metadata")
20
+ class SpanKind(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
21
+ __slots__ = ()
22
+ SPAN_KIND_FUNCTION: _ClassVar[Span.SpanKind]
23
+ SPAN_KIND_LLM: _ClassVar[Span.SpanKind]
24
+ SPAN_KIND_FUNCTION: Span.SpanKind
25
+ SPAN_KIND_LLM: Span.SpanKind
26
+ TRACE_ID_FIELD_NUMBER: _ClassVar[int]
27
+ SPAN_ID_FIELD_NUMBER: _ClassVar[int]
28
+ PARENT_SPAN_ID_FIELD_NUMBER: _ClassVar[int]
29
+ NAME_FIELD_NUMBER: _ClassVar[int]
30
+ KIND_FIELD_NUMBER: _ClassVar[int]
31
+ START_TIME_UNIX_NANO_FIELD_NUMBER: _ClassVar[int]
32
+ END_TIME_UNIX_NANO_FIELD_NUMBER: _ClassVar[int]
33
+ METADATA_FIELD_NUMBER: _ClassVar[int]
34
+ trace_id: bytes
35
+ span_id: bytes
36
+ parent_span_id: bytes
37
+ name: str
38
+ kind: Span.SpanKind
39
+ start_time_unix_nano: int
40
+ end_time_unix_nano: int
41
+ metadata: _containers.RepeatedCompositeFieldContainer[_common_pb2.KeyValue]
42
+ def __init__(self, trace_id: _Optional[bytes] = ..., span_id: _Optional[bytes] = ..., parent_span_id: _Optional[bytes] = ..., name: _Optional[str] = ..., kind: _Optional[_Union[Span.SpanKind, str]] = ..., start_time_unix_nano: _Optional[int] = ..., end_time_unix_nano: _Optional[int] = ..., metadata: _Optional[_Iterable[_Union[_common_pb2.KeyValue, _Mapping]]] = ...) -> None: ...
divi/run/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
- from .run import Run
1
+ from .run import Run, RunExtra
2
2
 
3
- __all__ = ["Run"]
3
+ __all__ = ["RunExtra", "Run"]
divi/run/run.py CHANGED
@@ -1,2 +1,24 @@
1
+ from typing import Optional, TypedDict
2
+ from uuid import uuid4
3
+
4
+ from pydantic import UUID4
5
+
6
+
7
+ class RunExtra(TypedDict, total=False):
8
+ """Extra information for Run"""
9
+
10
+ run_name: Optional[str]
11
+ """Name of the Run"""
12
+ trace_id: Optional[UUID4]
13
+ """Trace ID UUID4"""
14
+ parent_span_id: Optional[UUID4]
15
+ """Parent Span ID UUID4"""
16
+
17
+
1
18
  class Run:
2
- pass
19
+ def __init__(
20
+ self,
21
+ name: Optional[str] = None,
22
+ ):
23
+ self.id = uuid4()
24
+ self.name = name
divi/run/setup.py ADDED
@@ -0,0 +1,50 @@
1
+ import divi
2
+ from divi.run import Run, RunExtra
3
+ from divi.signals.trace import Span
4
+
5
+
6
+ def init(run_extra: RunExtra) -> Run:
7
+ """init initializes the services and the Run"""
8
+ # init_services()
9
+ return Run(name=run_extra.get("run_name"))
10
+
11
+
12
+ def setup(
13
+ span: Span,
14
+ run_extra: RunExtra | None,
15
+ ):
16
+ """setup trace
17
+
18
+ Args:
19
+ span (Span): Span instance
20
+ run_extra (RunExtra | None): Extra information from user input
21
+ """
22
+ # TOOD: merge run_extra input by user with the one from the context
23
+ # temp solution: Priority: run_extra_context.get() > run_extra
24
+ run_extra = run_extra or RunExtra()
25
+
26
+ # init the Run if not already initialized
27
+ if not divi._run:
28
+ divi._run = init(run_extra=run_extra)
29
+
30
+ # setup current span
31
+ trace_id = run_extra.get("trace_id")
32
+ parent_span_id = run_extra.get("parent_span_id")
33
+ if trace_id and parent_span_id:
34
+ span._add_parent(trace_id, parent_span_id)
35
+ else:
36
+ span._as_root()
37
+
38
+ # set _RUNEXTRA
39
+ run_extra = RunExtra(
40
+ run_name=divi._run.name,
41
+ trace_id=span.trace_id,
42
+ # set the parent_span_id to the current span_id
43
+ parent_span_id=span.span_id,
44
+ )
45
+
46
+ # offer end hook to collect data at whe end of the span ?
47
+ # offer hook to reset the context with the token
48
+ # context = copy_context()
49
+ # context.run(run_extra_context.set, run_extra)
50
+ return run_extra
divi/run/teardown.py ADDED
@@ -0,0 +1,7 @@
1
+ import divi
2
+ from divi.services import finish as clean_up_services
3
+
4
+
5
+ def teardown():
6
+ clean_up_services()
7
+ divi._run = None
@@ -1,19 +1,16 @@
1
1
  import os
2
2
  from typing import Optional
3
3
 
4
- import divi
5
4
  from divi.services.auth import Auth
6
5
 
7
6
  DIVI_API_KEY = "DIVI_API_KEY"
8
7
 
9
8
 
10
- def init(api_key: Optional[str] = None) -> Optional[Auth]:
9
+ def init(api_key: Optional[str] = None) -> Auth:
11
10
  key = api_key if api_key else os.getenv(DIVI_API_KEY)
12
11
  if not key:
13
12
  raise ValueError("API key is required")
14
- divi._auth = Auth(api_key=key)
15
- # TODO: Test the token
16
- return divi._auth
13
+ return Auth(api_key=key)
17
14
 
18
15
 
19
16
  if __name__ == "__main__":
@@ -4,8 +4,8 @@ from typing import Callable, List, Optional
4
4
  import grpc
5
5
 
6
6
  import divi
7
- from divi.proto.core_pb2_grpc import CoreStub
8
- from divi.proto.health_pb2 import HealthCheckRequest
7
+ from divi.proto.core.health.v1.health_service_pb2 import HealthCheckRequest
8
+ from divi.proto.core.health.v1.health_service_pb2_grpc import HealthServiceStub
9
9
  from divi.services.service import Service
10
10
 
11
11
 
@@ -20,7 +20,7 @@ class Core(Service):
20
20
  def check_health(self) -> bool:
21
21
  """Check the health of the service."""
22
22
  with grpc.insecure_channel(self.target) as channel:
23
- stub = CoreStub(channel)
23
+ stub = HealthServiceStub(channel)
24
24
  response, call = stub.Check.with_call(
25
25
  HealthCheckRequest(version=divi.__version__),
26
26
  # Note: ((),) notice the `,` at the end of the tuple
@@ -2,28 +2,21 @@ import atexit
2
2
  import socket
3
3
  import subprocess
4
4
  import time
5
- from typing import Optional
6
5
 
7
6
  import grpc
8
7
 
9
- import divi
10
8
  from divi.services.core import Core
11
9
  from divi.utils import get_server_path
12
10
 
13
11
 
14
- def init(host="localhost", port=50051) -> Optional[Core]:
15
- divi._core = Core(host=host, port=port)
16
- _start_server()
17
- return divi._core
12
+ def init(host="localhost", port=50051) -> Core:
13
+ core = Core(host=host, port=port)
14
+ _start_server(core)
15
+ return core
18
16
 
19
17
 
20
- def _start_server():
18
+ def _start_server(core: Core):
21
19
  """Start the backend server."""
22
- # get the run object
23
- core = divi._core
24
- if core is None:
25
- return
26
-
27
20
  # start the server
28
21
  bin_path = get_server_path()
29
22
  command = [bin_path]
@@ -1,3 +1,4 @@
1
1
  from .datapark import DataPark
2
+ from .init import init
2
3
 
3
- __all__ = ["DataPark"]
4
+ __all__ = ["DataPark", "init"]
@@ -1,9 +1,5 @@
1
- from typing import Optional
2
-
3
- import divi
4
1
  from divi.services.datapark import DataPark
5
2
 
6
3
 
7
- def init() -> Optional[DataPark]:
8
- divi._datapark = DataPark()
9
- return divi._datapark
4
+ def init() -> DataPark:
5
+ return DataPark()
divi/services/finish.py CHANGED
@@ -1,5 +1,9 @@
1
+ import divi
1
2
  from divi.services.core import finish as clean_up_core
2
3
 
3
4
 
4
5
  def finish():
5
6
  clean_up_core()
7
+ divi._auth = None
8
+ divi._core = None
9
+ divi._datapark = None
divi/services/init.py CHANGED
@@ -1,7 +1,13 @@
1
+ import divi
1
2
  from divi.services.auth import init as init_auth
2
3
  from divi.services.core import init as init_core
4
+ from divi.services.datapark import init as init_datapark
3
5
 
4
6
 
5
7
  def init():
6
- init_core()
7
- init_auth()
8
+ if not divi._auth:
9
+ divi._auth = init_auth()
10
+ if not divi._core:
11
+ divi._core = init_core()
12
+ if not divi._datapark:
13
+ divi._datapark = init_datapark()
divi/signals/__init__.py CHANGED
@@ -1,4 +1,3 @@
1
- from .metric import Metric
2
- from .trace import Trace
1
+ from .trace import Span
3
2
 
4
- __all__ = ["Metric", "Trace"]
3
+ __all__ = ["Span"]
@@ -1,3 +1,3 @@
1
- from .trace import Trace
1
+ from .trace import Span
2
2
 
3
- __all__ = ["Trace"]
3
+ __all__ = ["Span"]
@@ -1,2 +1,81 @@
1
- class Trace:
2
- pass
1
+ import time
2
+ from typing import Any, Mapping, Optional
3
+ from uuid import uuid4
4
+
5
+ from pydantic import UUID4
6
+
7
+ from divi.proto.common.v1.common_pb2 import KeyValue
8
+ from divi.proto.trace.v1.trace_pb2 import Span as SpanProto
9
+
10
+
11
+ class Span:
12
+ KIND_MAP = {
13
+ "function": SpanProto.SpanKind.SPAN_KIND_FUNCTION,
14
+ "llm": SpanProto.SpanKind.SPAN_KIND_LLM,
15
+ }
16
+
17
+ def __init__(
18
+ self,
19
+ kind: str = "function",
20
+ name: Optional[str] = None,
21
+ metadata: Optional[Mapping[str, Any]] = None,
22
+ ):
23
+ self.span_id: UUID4 = uuid4()
24
+ self.name = name
25
+ self.kind = kind
26
+ self.metadata = metadata
27
+ self.start_time_unix_nano: int | None = None
28
+ self.end_time_unix_nano: int | None = None
29
+
30
+ self.trace_id: UUID4 | None = None
31
+ self.parent_span_id: UUID4 | None = None
32
+
33
+ @property
34
+ def signal(self):
35
+ signal: SpanProto = SpanProto(
36
+ name=self.name,
37
+ span_id=self.span_id.bytes,
38
+ kind=self._get_kind(self.kind),
39
+ )
40
+ signal.metadata.extend(
41
+ KeyValue(key=k, value=v)
42
+ for k, v in (self.metadata or dict()).items()
43
+ )
44
+ return signal
45
+
46
+ @classmethod
47
+ def _get_kind(cls, kind: str) -> SpanProto.SpanKind:
48
+ if (k := cls.KIND_MAP.get(kind)) is None:
49
+ raise ValueError(
50
+ f"Unknown kind: {kind}. Now allowed: {cls.KIND_MAP.keys()}"
51
+ )
52
+ return k
53
+
54
+ def start(self):
55
+ """Start the span by recording the current time in nanoseconds."""
56
+ self.start_time_unix_nano = time.time_ns()
57
+
58
+ def end(self):
59
+ """End the span by recording the end time in nanoseconds."""
60
+ if self.start_time_unix_nano is None:
61
+ raise ValueError("Span must be started before ending.")
62
+ self.end_time_unix_nano = time.time_ns()
63
+
64
+ def _as_root(self):
65
+ """Set the span as a root span."""
66
+ self.trace_id = uuid4()
67
+ print("as root")
68
+ print(f"name: {self.name}")
69
+ print(f"trace_id: {self.trace_id}")
70
+ print(f"span_id: {self.span_id}")
71
+
72
+ def _add_parent(self, trace_id: UUID4, parent_id: UUID4):
73
+ """Set the parent span ID."""
74
+ self.trace_id = trace_id
75
+ self.parent_span_id = parent_id
76
+
77
+ print("add parent")
78
+ print(f"name: {self.name}")
79
+ print(f"trace_id: {trace_id}")
80
+ print(f"span_id: {self.span_id}")
81
+ print(f"parent_span_id: {parent_id}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: divi
3
- Version: 0.0.1.dev12
3
+ Version: 0.0.1.dev13
4
4
  Summary: The Agent Platform for Observability & Evaluation
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.11
@@ -0,0 +1,49 @@
1
+ divi/__init__.py,sha256=gjUnJYCo6ZWzaFn7NsIZWrCPHiu6nS5ASwjWPwWsY60,380
2
+ divi/utils.py,sha256=3iVDogCjqQg0jEjhUKEuQ6vHPFp9w7kXNjSVwXt8KmI,574
3
+ divi/bin/core,sha256=5TH23JdCcV3dmWFAQgDUwjugZ1H6W41asTTnS2JG0pI,14648850
4
+ divi/config/config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ divi/decorators/__init__.py,sha256=HkyWdC1ctTsVFucCWCkj57JB4NmwONus1d2S2dUbvs4,110
6
+ divi/decorators/obs_openai.py,sha256=2KVF2U0Z1-hcVxwryE5rvDr7LTADqbNaQYrWfswStUs,993
7
+ divi/decorators/observable.py,sha256=nrlZpk4-p_7XBYIdR2P86qVkevURsjWLnJANusU6uYw,2837
8
+ divi/proto/common/v1/common.proto,sha256=VcXK6JVwBXJ-70dTtJxa8If-dU__N26oAPWOAYulsko,2252
9
+ divi/proto/common/v1/common_pb2.py,sha256=e-B4LJ6fDytcY9YO-wlR6Z-_VR0yiLe2FRowVZXbk6Y,2772
10
+ divi/proto/common/v1/common_pb2.pyi,sha256=Eo1DJJBTddi0isywywKh2cEFjoMGsbxGRUW7klhVBW0,2789
11
+ divi/proto/core/health/v1/health_service.proto,sha256=kUkCFAA1cJyQCN_jvdoUJli0pjHSgFKGysqLMs88Dyc,372
12
+ divi/proto/core/health/v1/health_service_pb2.py,sha256=JL34hqA0cogvRZ_Ql9c1RGIcCl4d-71fNtSUFfTl5gk,2007
13
+ divi/proto/core/health/v1/health_service_pb2.pyi,sha256=VbYHHTcp3epUVg0lTSxo3xpG52ZGhA7KKMRL5LR5e1c,691
14
+ divi/proto/core/health/v1/health_service_pb2_grpc.py,sha256=6owvQ41KPqSOQ8WjXDjYsunoDVydJfP93vZ4uVSG59s,3953
15
+ divi/proto/metric/v1/metric.proto,sha256=RMyzWSvH_hNH1MQO17dlS3JAuyLA26xcwkUsoioP5tM,666
16
+ divi/proto/metric/v1/metric_pb2.py,sha256=9zEhcqbzGsO8-3nst46Sjcd27xYMt98JFNpA0x7_RU4,2054
17
+ divi/proto/metric/v1/metric_pb2.pyi,sha256=7ZxtOhqP9sl4hzaFBlPJ0SIk4afEEYQT94fy5an56nM,1447
18
+ divi/proto/run/v1/run.proto,sha256=Znnj8ZvKUEMtDTlMhOTrjD3yFpcWnQ2glR_XCPqttlk,1018
19
+ divi/proto/run/v1/run_pb2.py,sha256=NpBsyZZvEZG90l8DEt0pqzxFZ1HyGP5o57wGvezENNI,2103
20
+ divi/proto/run/v1/run_pb2.pyi,sha256=H6sPhBN8fqsoeb_F_0vGCegH49ZWmPHSShvJ77jojDk,1768
21
+ divi/proto/trace/v1/trace.proto,sha256=a24OcSsMciwQnQx-aPBnF1U3jnQb9nUjHnueRVXxaHA,1365
22
+ divi/proto/trace/v1/trace_pb2.py,sha256=squnWqxwaLv8dJADvJfQhGMw0mTtXdHrAMIr1QSuBls,2407
23
+ divi/proto/trace/v1/trace_pb2.pyi,sha256=E-GMVDvJ6_c69BSeiQ7zFccVu1m4DEyhf8Q3lz6ZJHs,2279
24
+ divi/run/__init__.py,sha256=AiuwvrmmXT0me76bo6rRt3MGxzf3bBhDXH-sVFU2-rw,62
25
+ divi/run/run.py,sha256=6UGALwRRorA74Ak48mv1ZxVkTKu6A55f3qQHAw5vfhA,484
26
+ divi/run/setup.py,sha256=xz9CogPdlLpOqvEkU2Iq0xW7uDApOKM2Ga4YeRtriBE,1418
27
+ divi/run/teardown.py,sha256=Vguc8_x2NTucABIo0lE71yT5zpQI0a974IKz7BrI_No,129
28
+ divi/services/__init__.py,sha256=TcVJ_gKxyPIcwhT9GgttqHeyk0icW44uE285KmUiyh4,185
29
+ divi/services/finish.py,sha256=XKPKGJ5cWd5H95G_VpIOlOZOLrcf9StoTs7ayRic2jY,173
30
+ divi/services/init.py,sha256=ocfMDylWc6_6HdlIr_xyf_3iuP6KZ6M8eOObPdYo76o,361
31
+ divi/services/service.py,sha256=1c7JQ49BSdBipGLfVIxTHaNxTuyvVAgrvxV7lyYv_68,285
32
+ divi/services/auth/__init__.py,sha256=PIQ9rQ0jcRqcy03a3BOY7wbzwluIRG_4kI_H4J4mRFk,74
33
+ divi/services/auth/auth.py,sha256=dTpFnNhxbEjzOkBLPQvRblFSO5tedJsdObWTXt84MaE,631
34
+ divi/services/auth/init.py,sha256=UXsOweatrWnuFO9ivSjEsJnHrK9YtStKYX2Nup64KEU,477
35
+ divi/services/auth/tokman.py,sha256=V03wcV6TEy1k9o55teDVB9JZ3Ve2cJdwzWstQhWx4BQ,1070
36
+ divi/services/core/__init__.py,sha256=FWl4ShX0AEnOyL24NEc9mNIVoQOeYO4q0qYX27L_Yyw,111
37
+ divi/services/core/core.py,sha256=PRwPtLgrgmCrejUfKf7HJNrAhGS0paFNZ7JwDToEUAk,1264
38
+ divi/services/core/finish.py,sha256=dIGQpVXcJY4-tKe7A1_VV3yoSHNCDPfOlUltvzvk6VI,231
39
+ divi/services/core/init.py,sha256=PXmQ52TGc0sdXm6uy4UbJ_3MAYE0Mkw_LTh4Kr1KgkQ,1941
40
+ divi/services/datapark/__init__.py,sha256=GbV1mwHE07yutgOlCIYHykSEL5KJ-ApgLutGMzu2eUE,86
41
+ divi/services/datapark/datapark.py,sha256=a7db-SQPqiae1Yxs78h7omQq7sItX5UClfniwxN-CUc,159
42
+ divi/services/datapark/init.py,sha256=C32f9t3eLsxcYNqEyheh6nW455G2oR0YhhdqBcbN3ec,92
43
+ divi/signals/__init__.py,sha256=K1PaTAMwyBDsK6jJUg4QWy0xVJ_5MA6dlWiUyJeiSQA,44
44
+ divi/signals/trace/__init__.py,sha256=K1PaTAMwyBDsK6jJUg4QWy0xVJ_5MA6dlWiUyJeiSQA,44
45
+ divi/signals/trace/trace.py,sha256=sWXvUhzgwkLlaI-pGEHL8vim9PHP9Av6Ss0a9reLqXA,2476
46
+ divi-0.0.1.dev13.dist-info/METADATA,sha256=KZ0LLyd51oXZQzNm7oDqPSg48c1AVzzF27x_IAHF24c,457
47
+ divi-0.0.1.dev13.dist-info/WHEEL,sha256=G84COq2WqV__z0k5yV28XkqceijvjyhYltl4MnmpO9g,102
48
+ divi-0.0.1.dev13.dist-info/licenses/LICENSE,sha256=5OJuZ4wMMEV0DgF0tofhAlS_KLkaUsZwwwDS2U_GwQ0,1063
49
+ divi-0.0.1.dev13.dist-info/RECORD,,
@@ -1,19 +0,0 @@
1
- syntax = "proto3";
2
-
3
- package divi.proto.resource.v1;
4
-
5
- import "divi/proto/common/v1/common.proto";
6
-
7
- option go_package = "services/proto";
8
-
9
- // Resource information.
10
- message Resource {
11
- // Set of attributes that describe the resource.
12
- // Attribute keys MUST be unique (it is not allowed to have more than one
13
- // attribute with the same key).
14
- repeated divi.proto.common.v1.KeyValue attributes = 1;
15
-
16
- // dropped_attributes_count is the number of dropped attributes. If the value is 0, then
17
- // no attributes were dropped.
18
- uint32 dropped_attributes_count = 2;
19
- }
@@ -1,3 +0,0 @@
1
- from .metric import Metric
2
-
3
- __all__ = ["Metric"]
@@ -1,2 +0,0 @@
1
- class Metric:
2
- pass
@@ -1,37 +0,0 @@
1
- divi/__init__.py,sha256=iYB7lJdbqdP1b1Qi_dDljwannxsfxeutg6QxEsi9lIk,380
2
- divi/utils.py,sha256=3iVDogCjqQg0jEjhUKEuQ6vHPFp9w7kXNjSVwXt8KmI,574
3
- divi/bin/core,sha256=GMj7vkrAhOajWhtUyHV41AV40kh01L6MhJdbmQrYU2E,14543426
4
- divi/config/config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- divi/decorators/__init__.py,sha256=HkyWdC1ctTsVFucCWCkj57JB4NmwONus1d2S2dUbvs4,110
6
- divi/decorators/obs_openai.py,sha256=2KVF2U0Z1-hcVxwryE5rvDr7LTADqbNaQYrWfswStUs,993
7
- divi/decorators/observable.py,sha256=d0gqIqPvU7nhO2GtdgLfGkcoZsZ9i0U1PKmd7QS-O_E,1018
8
- divi/proto/common/v1/common.proto,sha256=gkVT3Ac7oMg-JjUhHiT4JGq7RyjPmvpId9TZpfvmpoM,2309
9
- divi/proto/core/health/v1/health_service.proto,sha256=kUkCFAA1cJyQCN_jvdoUJli0pjHSgFKGysqLMs88Dyc,372
10
- divi/proto/resource/v1/resource.proto,sha256=gpB3Vj3BHNAhbN6Yk_oHWwbh16L8VBXpRl2-TKn6R3g,566
11
- divi/proto/trace/v1/trace.proto,sha256=ZCPEW1haW-fwXbgMpw9HfORLoNeWrrqauT3CL0OTP-I,466
12
- divi/run/__init__.py,sha256=0DQw0lBBiXRyW74PZkDCQVj4ZmX8lQrHo8_ZixdHNrI,40
13
- divi/run/run.py,sha256=UOxW0gy9nEu8snjyc5O3Pw5o69ary-b-QpqFqTXybNE,20
14
- divi/services/__init__.py,sha256=TcVJ_gKxyPIcwhT9GgttqHeyk0icW44uE285KmUiyh4,185
15
- divi/services/finish.py,sha256=epgUNYdsGSC8j8uj_fhs7P0-Atem_hTlzyPPvbsWEPQ,91
16
- divi/services/init.py,sha256=JlsKHK-IEQ2xh76gNBqF_eqIFNBqoTnwiDeMXSJg4wQ,144
17
- divi/services/service.py,sha256=1c7JQ49BSdBipGLfVIxTHaNxTuyvVAgrvxV7lyYv_68,285
18
- divi/services/auth/__init__.py,sha256=PIQ9rQ0jcRqcy03a3BOY7wbzwluIRG_4kI_H4J4mRFk,74
19
- divi/services/auth/auth.py,sha256=dTpFnNhxbEjzOkBLPQvRblFSO5tedJsdObWTXt84MaE,631
20
- divi/services/auth/init.py,sha256=bScuij1a97sDPRZyrzIkrwX3X25LLY7NG6zZI92C7Xs,554
21
- divi/services/auth/tokman.py,sha256=V03wcV6TEy1k9o55teDVB9JZ3Ve2cJdwzWstQhWx4BQ,1070
22
- divi/services/core/__init__.py,sha256=FWl4ShX0AEnOyL24NEc9mNIVoQOeYO4q0qYX27L_Yyw,111
23
- divi/services/core/core.py,sha256=kwqW1DSkLcOjVVWA5y8cdYo35rJ9nNffs_aVC1894Dk,1198
24
- divi/services/core/finish.py,sha256=dIGQpVXcJY4-tKe7A1_VV3yoSHNCDPfOlUltvzvk6VI,231
25
- divi/services/core/init.py,sha256=TiY9Z6Vl93ZMAE07kuw6H2uHdk3jUtzGCV_I1cIdaLI,2073
26
- divi/services/datapark/__init__.py,sha256=ftKZC1QGegK7SFslC6jrbRD-S4WLXwBpucA4oiMj5so,55
27
- divi/services/datapark/datapark.py,sha256=a7db-SQPqiae1Yxs78h7omQq7sItX5UClfniwxN-CUc,159
28
- divi/services/datapark/init.py,sha256=K0GxbZW0qeimpEoKZeDJo-NIbffX7Hy7GlncOqTOj7U,179
29
- divi/signals/__init__.py,sha256=bN3jKJkY9vlpCjEK5llQddgloQ1KXg1z5xjYWY1JF-c,83
30
- divi/signals/metric/__init__.py,sha256=Enn1iNvJUxBSIuKEJM2DbBWET719oSFgpbhhLUMc0GE,49
31
- divi/signals/metric/metric.py,sha256=gFy-iKvFLKUe5Me9jPR_vZX_kIqa0FrgBMI7x9jaFMI,23
32
- divi/signals/trace/__init__.py,sha256=hE2j94DHT2a-8gUtcuWiFxrhq1sWcqnSjhSZ41q6nBQ,46
33
- divi/signals/trace/trace.py,sha256=vGdcQ0WzLjmIOH0rtyQFkes30XhD4W2lG6uEP5oznEM,22
34
- divi-0.0.1.dev12.dist-info/METADATA,sha256=WpXFxou0VM2Rdfw84Ue64EV85GtAEOlZcGEhrEMsQW4,457
35
- divi-0.0.1.dev12.dist-info/WHEEL,sha256=G84COq2WqV__z0k5yV28XkqceijvjyhYltl4MnmpO9g,102
36
- divi-0.0.1.dev12.dist-info/licenses/LICENSE,sha256=5OJuZ4wMMEV0DgF0tofhAlS_KLkaUsZwwwDS2U_GwQ0,1063
37
- divi-0.0.1.dev12.dist-info/RECORD,,