scale-gp-beta 0.1.0a19__py3-none-any.whl → 0.1.0a21__py3-none-any.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.
- scale_gp_beta/_base_client.py +16 -2
- scale_gp_beta/_version.py +1 -1
- scale_gp_beta/lib/tracing/span.py +60 -17
- scale_gp_beta/lib/tracing/trace.py +68 -9
- scale_gp_beta/lib/tracing/trace_exporter.py +25 -4
- scale_gp_beta/lib/tracing/trace_queue_manager.py +12 -8
- scale_gp_beta/lib/tracing/tracing.py +99 -48
- scale_gp_beta/lib/tracing/types.py +7 -2
- {scale_gp_beta-0.1.0a19.dist-info → scale_gp_beta-0.1.0a21.dist-info}/METADATA +1 -1
- {scale_gp_beta-0.1.0a19.dist-info → scale_gp_beta-0.1.0a21.dist-info}/RECORD +12 -12
- {scale_gp_beta-0.1.0a19.dist-info → scale_gp_beta-0.1.0a21.dist-info}/WHEEL +0 -0
- {scale_gp_beta-0.1.0a19.dist-info → scale_gp_beta-0.1.0a21.dist-info}/licenses/LICENSE +0 -0
scale_gp_beta/_base_client.py
CHANGED
|
@@ -1071,7 +1071,14 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|
|
1071
1071
|
) -> ResponseT:
|
|
1072
1072
|
origin = get_origin(cast_to) or cast_to
|
|
1073
1073
|
|
|
1074
|
-
if
|
|
1074
|
+
if (
|
|
1075
|
+
inspect.isclass(origin)
|
|
1076
|
+
and issubclass(origin, BaseAPIResponse)
|
|
1077
|
+
# we only want to actually return the custom BaseAPIResponse class if we're
|
|
1078
|
+
# returning the raw response, or if we're not streaming SSE, as if we're streaming
|
|
1079
|
+
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
|
|
1080
|
+
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
|
|
1081
|
+
):
|
|
1075
1082
|
if not issubclass(origin, APIResponse):
|
|
1076
1083
|
raise TypeError(f"API Response types must subclass {APIResponse}; Received {origin}")
|
|
1077
1084
|
|
|
@@ -1574,7 +1581,14 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|
|
1574
1581
|
) -> ResponseT:
|
|
1575
1582
|
origin = get_origin(cast_to) or cast_to
|
|
1576
1583
|
|
|
1577
|
-
if
|
|
1584
|
+
if (
|
|
1585
|
+
inspect.isclass(origin)
|
|
1586
|
+
and issubclass(origin, BaseAPIResponse)
|
|
1587
|
+
# we only want to actually return the custom BaseAPIResponse class if we're
|
|
1588
|
+
# returning the raw response, or if we're not streaming SSE, as if we're streaming
|
|
1589
|
+
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
|
|
1590
|
+
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
|
|
1591
|
+
):
|
|
1578
1592
|
if not issubclass(origin, AsyncAPIResponse):
|
|
1579
1593
|
raise TypeError(f"API Response types must subclass {AsyncAPIResponse}; Received {origin}")
|
|
1580
1594
|
|
scale_gp_beta/_version.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
-
from typing import TYPE_CHECKING,
|
|
4
|
+
from typing import TYPE_CHECKING, Type, Optional
|
|
5
5
|
from typing_extensions import override
|
|
6
6
|
|
|
7
7
|
from scale_gp_beta.types.span_upsert_batch_params import Item as SpanCreateRequest
|
|
8
8
|
|
|
9
9
|
from .util import iso_timestamp, generate_span_id
|
|
10
10
|
from .scope import Scope
|
|
11
|
-
from .types import SpanTypeLiterals, SpanStatusLiterals
|
|
11
|
+
from .types import SpanInputParam, SpanOutputParam, SpanTypeLiterals, SpanMetadataParam, SpanStatusLiterals
|
|
12
12
|
from .exceptions import ParamsCreationError
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
@@ -53,20 +53,22 @@ class BaseSpan:
|
|
|
53
53
|
queue_manager: Optional[TraceQueueManager] = None,
|
|
54
54
|
span_id: Optional[str] = None,
|
|
55
55
|
parent_span_id: Optional[str] = None,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
group_id: Optional[str] = None,
|
|
57
|
+
input: Optional[SpanInputParam] = None,
|
|
58
|
+
output: Optional[SpanOutputParam] = None,
|
|
59
|
+
metadata: Optional[SpanMetadataParam] = None,
|
|
59
60
|
span_type: SpanTypeLiterals = "STANDALONE"
|
|
60
61
|
):
|
|
61
62
|
self.name = name
|
|
62
63
|
self.trace_id = trace_id or "no_trace_id"
|
|
64
|
+
self.group_id = group_id
|
|
63
65
|
self.span_id: str = span_id or generate_span_id()
|
|
64
66
|
self.parent_span_id = parent_span_id
|
|
65
67
|
self.start_time: Optional[str] = None
|
|
66
68
|
self.end_time: Optional[str] = None
|
|
67
|
-
self.input = input
|
|
68
|
-
self.output = output
|
|
69
|
-
self.metadata = metadata
|
|
69
|
+
self.input: SpanInputParam = input or {}
|
|
70
|
+
self.output: SpanOutputParam = output or {}
|
|
71
|
+
self.metadata: SpanMetadataParam = metadata or {}
|
|
70
72
|
self.span_type: SpanTypeLiterals = span_type
|
|
71
73
|
self.status: SpanStatusLiterals = "SUCCESS"
|
|
72
74
|
self._queue_manager = queue_manager
|
|
@@ -79,6 +81,9 @@ class BaseSpan:
|
|
|
79
81
|
def end(self) -> None:
|
|
80
82
|
pass
|
|
81
83
|
|
|
84
|
+
def flush(self, blocking: bool = True) -> None:
|
|
85
|
+
pass
|
|
86
|
+
|
|
82
87
|
def __enter__(self) -> BaseSpan:
|
|
83
88
|
self.start()
|
|
84
89
|
return self
|
|
@@ -92,8 +97,6 @@ class BaseSpan:
|
|
|
92
97
|
# Naively record details in metadata for now, note that error capture only supported in context manager
|
|
93
98
|
# TODO: support error observations when using direct span.start() and span.end()
|
|
94
99
|
if exc_type is not None:
|
|
95
|
-
if self.metadata is None:
|
|
96
|
-
self.metadata = {}
|
|
97
100
|
self.metadata["error"] = True
|
|
98
101
|
self.metadata["error.type"] = exc_type.__name__
|
|
99
102
|
self.metadata["error.message"] = str(exc_val)
|
|
@@ -109,9 +112,9 @@ class BaseSpan:
|
|
|
109
112
|
id=self.span_id,
|
|
110
113
|
trace_id=self.trace_id,
|
|
111
114
|
start_timestamp=self.start_time,
|
|
112
|
-
input=self.input
|
|
113
|
-
output=self.output
|
|
114
|
-
metadata=self.metadata
|
|
115
|
+
input=self.input,
|
|
116
|
+
output=self.output,
|
|
117
|
+
metadata=self.metadata,
|
|
115
118
|
status=self.status,
|
|
116
119
|
type=self.span_type
|
|
117
120
|
)
|
|
@@ -123,8 +126,34 @@ class BaseSpan:
|
|
|
123
126
|
if self.parent_span_id is not None:
|
|
124
127
|
request_data["parent_id"] = self.parent_span_id
|
|
125
128
|
|
|
129
|
+
if self.group_id is not None:
|
|
130
|
+
request_data["group_id"] = self.group_id
|
|
131
|
+
|
|
126
132
|
return request_data
|
|
127
133
|
|
|
134
|
+
@override
|
|
135
|
+
def __repr__(self) -> str:
|
|
136
|
+
return (
|
|
137
|
+
f"{self.__class__.__name__}("
|
|
138
|
+
f"name='{self.name}', "
|
|
139
|
+
f"span_id='{self.span_id}', "
|
|
140
|
+
f"trace_id='{self.trace_id}', "
|
|
141
|
+
f"parent_span_id='{self.parent_span_id}', "
|
|
142
|
+
f"group_id='{self.group_id}', "
|
|
143
|
+
f"start_time='{self.start_time}', "
|
|
144
|
+
f"end_time='{self.end_time}', "
|
|
145
|
+
f"input='{self.input}', "
|
|
146
|
+
f"output='{self.output}', "
|
|
147
|
+
f"metadata='{self.metadata}', "
|
|
148
|
+
f"span_type='{self.span_type}', "
|
|
149
|
+
f"status='{self.status}'"
|
|
150
|
+
")"
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
@override
|
|
154
|
+
def __str__(self) -> str:
|
|
155
|
+
return self.__repr__()
|
|
156
|
+
|
|
128
157
|
|
|
129
158
|
class NoOpSpan(BaseSpan):
|
|
130
159
|
@override
|
|
@@ -166,15 +195,29 @@ class Span(BaseSpan):
|
|
|
166
195
|
queue_manager: TraceQueueManager,
|
|
167
196
|
span_id: Optional[str] = None,
|
|
168
197
|
parent_span_id: Optional[str] = None,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
group_id: Optional[str] = None,
|
|
199
|
+
input: Optional[SpanInputParam] = None,
|
|
200
|
+
output: Optional[SpanOutputParam] = None,
|
|
201
|
+
metadata: Optional[SpanMetadataParam] = None,
|
|
172
202
|
span_type: SpanTypeLiterals = "STANDALONE",
|
|
173
203
|
):
|
|
174
|
-
super().__init__(name, trace_id, queue_manager, span_id, parent_span_id, input, output, metadata, span_type)
|
|
204
|
+
super().__init__(name, trace_id, queue_manager, span_id, parent_span_id, group_id, input, output, metadata, span_type)
|
|
175
205
|
self._queue_manager: TraceQueueManager = queue_manager
|
|
176
206
|
self.trace_id: str = trace_id
|
|
177
207
|
|
|
208
|
+
@override
|
|
209
|
+
def flush(self, blocking: bool = True) -> None:
|
|
210
|
+
"""Export span. Defaults to in-thread and will block until the request is complete.
|
|
211
|
+
|
|
212
|
+
With `blocking=False`, this method will enqueue the request for the background worker.
|
|
213
|
+
The background worker batches and sends asynchronously.
|
|
214
|
+
:param blocking:
|
|
215
|
+
"""
|
|
216
|
+
if blocking:
|
|
217
|
+
self._queue_manager.export_now(self)
|
|
218
|
+
else:
|
|
219
|
+
self._queue_manager.enqueue(self)
|
|
220
|
+
|
|
178
221
|
@override
|
|
179
222
|
def start(self) -> None:
|
|
180
223
|
"""Starts the operational Span.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import contextvars
|
|
3
3
|
from types import TracebackType
|
|
4
|
-
from typing import
|
|
4
|
+
from typing import Type, Optional
|
|
5
5
|
from typing_extensions import override
|
|
6
6
|
|
|
7
7
|
from .span import Span, NoOpSpan
|
|
8
8
|
from .util import generate_trace_id
|
|
9
9
|
from .scope import Scope
|
|
10
|
+
from .types import SpanInputParam, SpanOutputParam, SpanTypeLiterals, SpanMetadataParam
|
|
10
11
|
from .trace_queue_manager import TraceQueueManager
|
|
11
12
|
|
|
12
13
|
log: logging.Logger = logging.getLogger(__name__)
|
|
@@ -26,6 +27,12 @@ class BaseTrace:
|
|
|
26
27
|
def end(self) -> None:
|
|
27
28
|
pass
|
|
28
29
|
|
|
30
|
+
def flush(self, blocking: bool = True) -> None:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
def group_id(self) -> Optional[str]:
|
|
34
|
+
return None
|
|
35
|
+
|
|
29
36
|
def __enter__(self) -> "BaseTrace":
|
|
30
37
|
self.start()
|
|
31
38
|
return self
|
|
@@ -38,6 +45,14 @@ class BaseTrace:
|
|
|
38
45
|
) -> None:
|
|
39
46
|
self.end()
|
|
40
47
|
|
|
48
|
+
@override
|
|
49
|
+
def __repr__(self) -> str:
|
|
50
|
+
return f"{self.__class__.__name__}(trace_id='{self.trace_id})"
|
|
51
|
+
|
|
52
|
+
@override
|
|
53
|
+
def __str__(self) -> str:
|
|
54
|
+
return self.__repr__()
|
|
55
|
+
|
|
41
56
|
|
|
42
57
|
class NoOpTrace(BaseTrace):
|
|
43
58
|
def __init__(
|
|
@@ -45,18 +60,34 @@ class NoOpTrace(BaseTrace):
|
|
|
45
60
|
name: str,
|
|
46
61
|
queue_manager: Optional[TraceQueueManager] = None,
|
|
47
62
|
trace_id: Optional[str] = None,
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
span_id: Optional[str] = None,
|
|
64
|
+
group_id: Optional[str] = None,
|
|
65
|
+
span_type: SpanTypeLiterals = "TRACER",
|
|
66
|
+
input: Optional[SpanInputParam] = None,
|
|
67
|
+
output: Optional[SpanOutputParam] = None,
|
|
68
|
+
metadata: Optional[SpanMetadataParam] = None,
|
|
50
69
|
):
|
|
51
70
|
super().__init__(queue_manager, trace_id)
|
|
52
71
|
|
|
53
72
|
self.root_span = NoOpSpan(
|
|
54
73
|
name=name,
|
|
55
|
-
span_id=
|
|
74
|
+
span_id=span_id,
|
|
56
75
|
trace_id=self.trace_id,
|
|
76
|
+
group_id=group_id,
|
|
57
77
|
queue_manager=queue_manager,
|
|
58
78
|
metadata=metadata,
|
|
59
|
-
span_type=
|
|
79
|
+
span_type=span_type,
|
|
80
|
+
input=input,
|
|
81
|
+
output=output,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
@override
|
|
85
|
+
def __repr__(self) -> str:
|
|
86
|
+
return (
|
|
87
|
+
f"{self.__class__.__name__}("
|
|
88
|
+
f"trace_id='{self.trace_id}', "
|
|
89
|
+
f"root_span='{repr(self.root_span)}', "
|
|
90
|
+
")"
|
|
60
91
|
)
|
|
61
92
|
|
|
62
93
|
@override
|
|
@@ -67,6 +98,10 @@ class NoOpTrace(BaseTrace):
|
|
|
67
98
|
def end(self) -> None:
|
|
68
99
|
self.root_span.end()
|
|
69
100
|
|
|
101
|
+
@override
|
|
102
|
+
def group_id(self) -> Optional[str]:
|
|
103
|
+
return self.root_span.group_id
|
|
104
|
+
|
|
70
105
|
|
|
71
106
|
class Trace(BaseTrace):
|
|
72
107
|
def __init__(
|
|
@@ -74,19 +109,26 @@ class Trace(BaseTrace):
|
|
|
74
109
|
name: str,
|
|
75
110
|
queue_manager: TraceQueueManager,
|
|
76
111
|
trace_id: Optional[str] = None,
|
|
77
|
-
|
|
78
|
-
|
|
112
|
+
span_id: Optional[str] = None,
|
|
113
|
+
group_id: Optional[str] = None,
|
|
114
|
+
span_type: SpanTypeLiterals = "TRACER",
|
|
115
|
+
input: Optional[SpanInputParam] = None,
|
|
116
|
+
output: Optional[SpanOutputParam] = None,
|
|
117
|
+
metadata: Optional[SpanMetadataParam] = None,
|
|
79
118
|
):
|
|
80
119
|
super().__init__(queue_manager, trace_id)
|
|
81
120
|
self.queue_manager: TraceQueueManager = queue_manager
|
|
82
121
|
|
|
83
122
|
self.root_span = Span(
|
|
84
123
|
name=name,
|
|
85
|
-
span_id=
|
|
124
|
+
span_id=span_id,
|
|
86
125
|
trace_id=self.trace_id,
|
|
126
|
+
group_id=group_id,
|
|
87
127
|
queue_manager=queue_manager,
|
|
88
128
|
metadata=metadata,
|
|
89
|
-
span_type=
|
|
129
|
+
span_type=span_type,
|
|
130
|
+
input=input,
|
|
131
|
+
output=output,
|
|
90
132
|
)
|
|
91
133
|
|
|
92
134
|
@override
|
|
@@ -116,3 +158,20 @@ class Trace(BaseTrace):
|
|
|
116
158
|
self._contextvar_token = None
|
|
117
159
|
|
|
118
160
|
self.root_span.end()
|
|
161
|
+
|
|
162
|
+
@override
|
|
163
|
+
def flush(self, blocking: bool = True) -> None:
|
|
164
|
+
self.root_span.flush(blocking=blocking)
|
|
165
|
+
|
|
166
|
+
@override
|
|
167
|
+
def group_id(self) -> Optional[str]:
|
|
168
|
+
return self.root_span.group_id
|
|
169
|
+
|
|
170
|
+
@override
|
|
171
|
+
def __repr__(self) -> str:
|
|
172
|
+
return (
|
|
173
|
+
f"{self.__class__.__name__}("
|
|
174
|
+
f"trace_id='{self.trace_id}', "
|
|
175
|
+
f"root_span='{repr(self.root_span)}', "
|
|
176
|
+
")"
|
|
177
|
+
)
|
|
@@ -34,11 +34,22 @@ class TraceExporter:
|
|
|
34
34
|
self.backoff = backoff
|
|
35
35
|
self.max_backoff = max_backoff
|
|
36
36
|
|
|
37
|
+
def export_span(self, client: SGPClient, span: "Span") -> None:
|
|
38
|
+
# only upsert endpoint is batch upsert, so we work in batches
|
|
39
|
+
batch: SpanRequestBatch = self._create_one_span_batch(span)
|
|
40
|
+
|
|
41
|
+
log.info(f"Exporting single span with id {span.span_id}")
|
|
42
|
+
self._export_batch(batch, client)
|
|
43
|
+
|
|
37
44
|
def export(self, client: SGPClient, queue: "Queue[Span]") -> None:
|
|
38
45
|
# this is also thread safe, two threads can call this method with the same queue at once
|
|
39
46
|
# the ordering of the requests might be randomly split between the two threads, but they should all be picked up
|
|
40
47
|
batches: list[SpanRequestBatch] = self._create_batches(queue)
|
|
41
48
|
|
|
49
|
+
if not batches:
|
|
50
|
+
log.debug("No new span batches to export")
|
|
51
|
+
return
|
|
52
|
+
|
|
42
53
|
log.info(f"Exporting {len(batches)} span batches")
|
|
43
54
|
|
|
44
55
|
for batch in batches:
|
|
@@ -73,15 +84,25 @@ class TraceExporter:
|
|
|
73
84
|
while len(span_batch) < self.max_batch_size and queue.qsize() > 0:
|
|
74
85
|
try:
|
|
75
86
|
span: "Span" = queue.get_nowait()
|
|
76
|
-
|
|
77
|
-
span_batch.append(span_request)
|
|
87
|
+
self._add_span_to_batch(span, span_batch)
|
|
78
88
|
except Empty:
|
|
79
89
|
break
|
|
80
|
-
except ParamsCreationError as e:
|
|
81
|
-
log.warning(f"ParamsCreationError: {e}\ndropping...")
|
|
82
90
|
|
|
83
91
|
if not span_batch:
|
|
84
92
|
break
|
|
85
93
|
batches.append(span_batch)
|
|
86
94
|
|
|
87
95
|
return batches
|
|
96
|
+
|
|
97
|
+
def _create_one_span_batch(self, span: "Span") -> SpanRequestBatch:
|
|
98
|
+
span_batch: SpanRequestBatch = []
|
|
99
|
+
self._add_span_to_batch(span, span_batch)
|
|
100
|
+
|
|
101
|
+
return span_batch
|
|
102
|
+
|
|
103
|
+
def _add_span_to_batch(self, span: "Span", span_batch: SpanRequestBatch) -> None:
|
|
104
|
+
try:
|
|
105
|
+
span_request = span.to_request_params()
|
|
106
|
+
span_batch.append(span_request)
|
|
107
|
+
except ParamsCreationError as e:
|
|
108
|
+
log.warning(f"ParamsCreationError: dropping span: {span}\n{e}")
|
|
@@ -76,16 +76,10 @@ class TraceQueueManager:
|
|
|
76
76
|
|
|
77
77
|
def report_span_start(self, span: "Span") -> None:
|
|
78
78
|
# TODO: support making this optional. Current backend requires us to send span starts
|
|
79
|
-
|
|
80
|
-
self._queue.put_nowait(span)
|
|
81
|
-
except queue.Full:
|
|
82
|
-
log.warning(f"Queue full, ignoring span {span.span_id}")
|
|
79
|
+
self.enqueue(span)
|
|
83
80
|
|
|
84
81
|
def report_span_end(self, span: "Span") -> None:
|
|
85
|
-
|
|
86
|
-
self._queue.put_nowait(span)
|
|
87
|
-
except queue.Full:
|
|
88
|
-
log.warning(f"Queue full, ignoring span {span.span_id}")
|
|
82
|
+
self.enqueue(span)
|
|
89
83
|
|
|
90
84
|
def report_trace_start(self, trace: "Trace") -> None:
|
|
91
85
|
pass
|
|
@@ -96,6 +90,16 @@ class TraceQueueManager:
|
|
|
96
90
|
def flush_queue(self) -> None:
|
|
97
91
|
self._export()
|
|
98
92
|
|
|
93
|
+
def enqueue(self, span: "Span") -> None:
|
|
94
|
+
try:
|
|
95
|
+
self._queue.put_nowait(span)
|
|
96
|
+
except queue.Full:
|
|
97
|
+
log.warning(f"Queue full, ignoring span {span.span_id}")
|
|
98
|
+
|
|
99
|
+
def export_now(self, span: "Span") -> None:
|
|
100
|
+
if self.client:
|
|
101
|
+
self._exporter.export_span(self.client, span)
|
|
102
|
+
|
|
99
103
|
@property
|
|
100
104
|
def client(self) -> Optional[SGPClient]:
|
|
101
105
|
"""
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Optional
|
|
3
3
|
|
|
4
4
|
from .span import Span, BaseSpan, NoOpSpan
|
|
5
5
|
from .util import is_disabled
|
|
6
6
|
from .scope import Scope
|
|
7
7
|
from .trace import Trace, BaseTrace, NoOpTrace
|
|
8
|
+
from .types import SpanInputParam, SpanOutputParam, SpanTypeLiterals, SpanMetadataParam
|
|
8
9
|
from .trace_queue_manager import tracing_queue_manager
|
|
9
10
|
|
|
10
11
|
log: logging.Logger = logging.getLogger(__name__)
|
|
@@ -50,9 +51,13 @@ def flush_queue() -> None:
|
|
|
50
51
|
|
|
51
52
|
def create_trace(
|
|
52
53
|
name: str,
|
|
54
|
+
span_type: SpanTypeLiterals = "TRACER",
|
|
55
|
+
input: Optional[SpanInputParam] = None,
|
|
56
|
+
output: Optional[SpanOutputParam] = None,
|
|
57
|
+
metadata: Optional[SpanMetadataParam] = None,
|
|
58
|
+
span_id: Optional[str] = None,
|
|
53
59
|
trace_id: Optional[str] = None,
|
|
54
|
-
|
|
55
|
-
metadata: Optional[Dict[str, Optional[str]]] = None,
|
|
60
|
+
group_id: Optional[str] = None,
|
|
56
61
|
) -> BaseTrace:
|
|
57
62
|
"""Creates a new trace and root span instance.
|
|
58
63
|
|
|
@@ -68,24 +73,54 @@ def create_trace(
|
|
|
68
73
|
|
|
69
74
|
Args:
|
|
70
75
|
name: The name of the trace.
|
|
76
|
+
span_type (Optional[SpanTypeLiterals]): Type of root span.
|
|
77
|
+
input (Optional[SpanInputParam]): Input of root span.
|
|
78
|
+
output (Optional[SpanOutputParam]): Output of root span.
|
|
79
|
+
metadata (Optional[SpanMetadataParam]): An optional, user-defined metadata.
|
|
80
|
+
span_id (Optional[str]): An optional, user-defined ID for the root span.
|
|
81
|
+
Max length is 38 characters.
|
|
71
82
|
trace_id (Optional[str]): An optional, user-defined ID for the trace.
|
|
72
83
|
If None, a unique trace ID will be generated.
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
Max length is 38 characters.
|
|
85
|
+
group_id (Optional[str]): An optional, id to group traces.
|
|
75
86
|
|
|
76
87
|
Returns:
|
|
77
88
|
BaseTrace: A `Trace` instance if tracing is enabled, or a `NoOpTrace`
|
|
78
89
|
instance if tracing is disabled.
|
|
79
90
|
"""
|
|
91
|
+
impl_input: SpanInputParam = input or {}
|
|
92
|
+
impl_output: SpanOutputParam = output or {}
|
|
93
|
+
impl_metadata: SpanMetadataParam = metadata or {}
|
|
94
|
+
|
|
80
95
|
if is_disabled():
|
|
81
96
|
log.debug(f"Tracing is disabled. Not creating a new trace.")
|
|
82
|
-
return NoOpTrace(
|
|
97
|
+
return NoOpTrace(
|
|
98
|
+
name=name,
|
|
99
|
+
trace_id=trace_id,
|
|
100
|
+
span_id=span_id,
|
|
101
|
+
group_id=group_id,
|
|
102
|
+
span_type=span_type,
|
|
103
|
+
input=impl_input,
|
|
104
|
+
output=impl_output,
|
|
105
|
+
metadata=impl_metadata,
|
|
106
|
+
)
|
|
83
107
|
|
|
84
108
|
active_trace = current_trace()
|
|
85
109
|
if active_trace is not None:
|
|
86
110
|
log.warning(f"Trace with id {active_trace.trace_id} is already active. Creating a new trace anyways.")
|
|
87
111
|
|
|
88
|
-
|
|
112
|
+
queue_manager = tracing_queue_manager()
|
|
113
|
+
trace = Trace(
|
|
114
|
+
name=name,
|
|
115
|
+
trace_id=trace_id,
|
|
116
|
+
span_id=span_id,
|
|
117
|
+
group_id=group_id,
|
|
118
|
+
queue_manager=queue_manager,
|
|
119
|
+
span_type=span_type,
|
|
120
|
+
input=impl_input,
|
|
121
|
+
output=impl_output,
|
|
122
|
+
metadata=impl_metadata,
|
|
123
|
+
)
|
|
89
124
|
log.debug(f"Created new trace: {trace.trace_id}")
|
|
90
125
|
|
|
91
126
|
return trace
|
|
@@ -93,12 +128,14 @@ def create_trace(
|
|
|
93
128
|
|
|
94
129
|
def create_span(
|
|
95
130
|
name: str,
|
|
131
|
+
span_type: SpanTypeLiterals = "STANDALONE",
|
|
132
|
+
input: Optional[SpanInputParam] = None,
|
|
133
|
+
output: Optional[SpanOutputParam] = None,
|
|
134
|
+
metadata: Optional[SpanMetadataParam] = None,
|
|
96
135
|
span_id: Optional[str] = None,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
trace: Optional[Union[BaseTrace, str]] = None,
|
|
101
|
-
parent_span: Optional[BaseSpan] = None,
|
|
136
|
+
parent_id: Optional[str] = None,
|
|
137
|
+
trace_id: Optional[str] = None,
|
|
138
|
+
group_id: Optional[str] = None,
|
|
102
139
|
) -> BaseSpan:
|
|
103
140
|
"""Creates a new span instance.
|
|
104
141
|
|
|
@@ -113,67 +150,81 @@ def create_span(
|
|
|
113
150
|
When a span is started (e.g., via context manager or `start()`), it becomes
|
|
114
151
|
the `current_span()` in the active scope.
|
|
115
152
|
|
|
153
|
+
If explicitly setting 'parent_id' and 'trace_id', ensure that the parent span
|
|
154
|
+
has the same 'trace_id'.
|
|
155
|
+
|
|
116
156
|
Args:
|
|
117
157
|
name (str): A descriptive name for the span (e.g., "database_query",
|
|
118
158
|
"http_request").
|
|
119
|
-
|
|
120
|
-
input (Optional[
|
|
159
|
+
span_type (SpanTypeLiterals): The type of the span.
|
|
160
|
+
input (Optional[SpanInputParam], optional): A dictionary containing
|
|
121
161
|
input data or parameters relevant to this span's operation. Defaults to None.
|
|
122
|
-
output (Optional[
|
|
162
|
+
output (Optional[SpanOutputParam], optional): A dictionary containing
|
|
123
163
|
output data or results from this span's operation. Defaults to None.
|
|
124
|
-
metadata (Optional[
|
|
164
|
+
metadata (Optional[SpanMetadataParam], optional):
|
|
125
165
|
A dictionary for arbitrary key-value pairs providing additional
|
|
126
166
|
context or annotations for the span. Values should be simple types.
|
|
127
167
|
Defaults to None.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
168
|
+
span_id (Optional[str]): An optional, user-defined ID for the span.
|
|
169
|
+
parent_id (Optional[str], optional): A `Span` id. Used for explicit control.
|
|
170
|
+
Defaults to span id fetched from the active scope.
|
|
171
|
+
trace_id (Optional[str], optional): A `Trace` id. Used for explicit control.
|
|
172
|
+
Default to trace id fetched from the active scope.
|
|
173
|
+
group_id (Optional[str]): An optional, id to group traces.
|
|
134
174
|
|
|
135
175
|
Returns:
|
|
136
176
|
BaseSpan: A `Span` instance if tracing is enabled and a valid trace context
|
|
137
177
|
exists, or a `NoOpSpan` otherwise.
|
|
138
178
|
"""
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if parent_span is not None:
|
|
143
|
-
trace_id = parent_span.trace_id
|
|
144
|
-
parent_span_id = parent_span.span_id
|
|
145
|
-
elif trace is not None:
|
|
146
|
-
trace_id = trace if isinstance(trace, str) else trace.trace_id
|
|
179
|
+
impl_input: SpanInputParam = input or {}
|
|
180
|
+
impl_output: SpanOutputParam = output or {}
|
|
181
|
+
impl_metadata: SpanMetadataParam = metadata or {}
|
|
147
182
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
else
|
|
151
|
-
|
|
152
|
-
|
|
183
|
+
scoped_trace = current_trace()
|
|
184
|
+
scoped_trace_id = scoped_trace.trace_id if scoped_trace else None
|
|
185
|
+
scoped_group_id = scoped_trace.group_id() if scoped_trace else None
|
|
186
|
+
scoped_span = current_span()
|
|
187
|
+
scoped_span_id = scoped_span.span_id if scoped_span else None
|
|
153
188
|
|
|
154
|
-
|
|
189
|
+
parent_span_id: Optional[str] = parent_id or scoped_span_id
|
|
190
|
+
# TODO: preference should be trace_id -> trace_id from parent span if parent_id present -> scoped_trace_id
|
|
191
|
+
# group_id -> group_id from trace if trace_id specified -> group_id from span if span_id -> scoped_group_id
|
|
192
|
+
impl_trace_id: Optional[str] = trace_id or scoped_trace_id
|
|
193
|
+
impl_group_id: Optional[str] = group_id or scoped_group_id
|
|
155
194
|
|
|
156
|
-
|
|
157
|
-
# need to think about default behavior here... do we create a trace, some other options?
|
|
158
|
-
# I am leaning towards setting it as an option as sometimes people might want to be succinct or when we
|
|
159
|
-
# build decorators we might want this functionality
|
|
160
|
-
log.debug(f"attempting to create a span with no trace")
|
|
161
|
-
return NoOpSpan(name=name, span_id=span_id, parent_span_id=parent_span_id)
|
|
195
|
+
# TODO: do a check to ensure trace_id of parent_span matches trace_id (when trace_id is specified)
|
|
162
196
|
|
|
163
|
-
|
|
197
|
+
noop_span = NoOpSpan(
|
|
198
|
+
name=name,
|
|
199
|
+
span_id=span_id,
|
|
200
|
+
parent_span_id=parent_span_id,
|
|
201
|
+
trace_id=impl_trace_id,
|
|
202
|
+
group_id=impl_group_id,
|
|
203
|
+
input=impl_input,
|
|
204
|
+
output=impl_output,
|
|
205
|
+
metadata=impl_metadata,
|
|
206
|
+
span_type=span_type,
|
|
207
|
+
)
|
|
164
208
|
|
|
165
209
|
if is_disabled():
|
|
166
|
-
return
|
|
210
|
+
return noop_span
|
|
211
|
+
|
|
212
|
+
if impl_trace_id is None:
|
|
213
|
+
log.debug(f"Attempting to create a span with no trace")
|
|
214
|
+
return noop_span
|
|
167
215
|
|
|
216
|
+
queue_manager = tracing_queue_manager()
|
|
168
217
|
span = Span(
|
|
169
218
|
name=name,
|
|
170
219
|
span_id=span_id,
|
|
171
220
|
parent_span_id=parent_span_id,
|
|
172
|
-
trace_id=
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
221
|
+
trace_id=impl_trace_id,
|
|
222
|
+
group_id=impl_group_id,
|
|
223
|
+
input=impl_input,
|
|
224
|
+
output=impl_output,
|
|
225
|
+
metadata=impl_metadata,
|
|
176
226
|
queue_manager=queue_manager,
|
|
227
|
+
span_type=span_type,
|
|
177
228
|
)
|
|
178
229
|
log.debug(f"Created new span: {span.span_id}")
|
|
179
230
|
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"""
|
|
2
|
-
This is necessary, unfortunately. Stainless does not provide
|
|
2
|
+
This is necessary, unfortunately. Stainless does not provide SpanStatusLiterals and SpanTypeLiterals as enums, only as
|
|
3
|
+
type annotations.
|
|
3
4
|
|
|
4
5
|
For strict linting, we need to reference these enums.
|
|
5
6
|
|
|
6
7
|
NOTE: These will have to be manually updated to support updated span_types and status.
|
|
7
8
|
"""
|
|
8
9
|
|
|
9
|
-
from typing_extensions import Literal
|
|
10
|
+
from typing_extensions import Any, Dict, Literal
|
|
11
|
+
|
|
12
|
+
SpanInputParam = Dict[str, Any]
|
|
13
|
+
SpanOutputParam = Dict[str, Any]
|
|
14
|
+
SpanMetadataParam = Dict[str, Any]
|
|
10
15
|
|
|
11
16
|
SpanStatusLiterals = Literal["SUCCESS", "ERROR"]
|
|
12
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: scale-gp-beta
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0a21
|
|
4
4
|
Summary: The official Python library for the Scale GP API
|
|
5
5
|
Project-URL: Homepage, https://github.com/scaleapi/sgp-python-beta
|
|
6
6
|
Project-URL: Repository, https://github.com/scaleapi/sgp-python-beta
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
scale_gp_beta/__init__.py,sha256=x8toPf2r1c14qt9Fvh5cjeX1tytmAWa3lMc4tg9SYKY,2646
|
|
2
|
-
scale_gp_beta/_base_client.py,sha256=
|
|
2
|
+
scale_gp_beta/_base_client.py,sha256=u6z6Qxu3eqzfbcDx-zlIUtbuPWF9MgeygEi6H8HN4X8,65891
|
|
3
3
|
scale_gp_beta/_client.py,sha256=3pNXJs9TKLjfYoTjFIIoSdd4mwwX1cc-VUveMBmkl_8,24491
|
|
4
4
|
scale_gp_beta/_compat.py,sha256=VWemUKbj6DDkQ-O4baSpHVLJafotzeXmCQGJugfVTIw,6580
|
|
5
5
|
scale_gp_beta/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
|
|
@@ -11,7 +11,7 @@ scale_gp_beta/_resource.py,sha256=siZly_U6D0AOVLAzaOsqUdEFFzVMbWRj-ml30nvRp7E,11
|
|
|
11
11
|
scale_gp_beta/_response.py,sha256=GemuybPk0uemovTlGHyHkj-ScYTTDJA0jqH5FQqIPwQ,28852
|
|
12
12
|
scale_gp_beta/_streaming.py,sha256=fcCSGXslmi2SmmkM05g2SACXHk2Mj7k1X5uMBu6U5s8,10112
|
|
13
13
|
scale_gp_beta/_types.py,sha256=0wSs40TefKMPBj2wQKenEeZ0lzedoHClNJeqrpAgkII,6204
|
|
14
|
-
scale_gp_beta/_version.py,sha256=
|
|
14
|
+
scale_gp_beta/_version.py,sha256=eAvv8VO77KuKq0s3gmUyyDz59GNsypYW7UrSDWHIN9s,174
|
|
15
15
|
scale_gp_beta/pagination.py,sha256=t-U86PYxl20VRsz8VXOMJJDe7HxkX7ISFMvRNbBNy9s,4054
|
|
16
16
|
scale_gp_beta/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
scale_gp_beta/_utils/__init__.py,sha256=PNZ_QJuzZEgyYXqkO1HVhGkj5IU9bglVUcw7H-Knjzw,2062
|
|
@@ -28,12 +28,12 @@ scale_gp_beta/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
|
|
28
28
|
scale_gp_beta/lib/tracing/__init__.py,sha256=UgyExbqAA2ljDEF4X4YFhtbBZuoQJ2IF4hkGs_xQEc0,226
|
|
29
29
|
scale_gp_beta/lib/tracing/exceptions.py,sha256=vL2_GAfWEy8EfLhrBkDClLYTasOLnL-5zUpdCQnSzcs,107
|
|
30
30
|
scale_gp_beta/lib/tracing/scope.py,sha256=kHrd0his8L2K_KXn2E6J9d565PliEdFoKRQ1d5ALTyk,3901
|
|
31
|
-
scale_gp_beta/lib/tracing/span.py,sha256=
|
|
32
|
-
scale_gp_beta/lib/tracing/trace.py,sha256=
|
|
33
|
-
scale_gp_beta/lib/tracing/trace_exporter.py,sha256=
|
|
34
|
-
scale_gp_beta/lib/tracing/trace_queue_manager.py,sha256=
|
|
35
|
-
scale_gp_beta/lib/tracing/tracing.py,sha256=
|
|
36
|
-
scale_gp_beta/lib/tracing/types.py,sha256=
|
|
31
|
+
scale_gp_beta/lib/tracing/span.py,sha256=_XocyodHFJsIihEOyFKtdojdsUR2wayqoRL7Kj60PVQ,9671
|
|
32
|
+
scale_gp_beta/lib/tracing/trace.py,sha256=GEzE78sulYKooz46vtZ7JI77_KDCOpQBfYsahZE_7HU,5084
|
|
33
|
+
scale_gp_beta/lib/tracing/trace_exporter.py,sha256=bE6hS-Qu9KknEUTdsfIQMQwauah125mEavTDqEenBRA,3779
|
|
34
|
+
scale_gp_beta/lib/tracing/trace_queue_manager.py,sha256=xywP3myhaHX52i52ZfC2_-ONrd-4_aL-f3-3jNhh2XY,5961
|
|
35
|
+
scale_gp_beta/lib/tracing/tracing.py,sha256=kGoUo3Kf172iJudzFIomXvQ_2aiWPr_38wqbKFX4rGo,8837
|
|
36
|
+
scale_gp_beta/lib/tracing/types.py,sha256=fnU7XGiyfF3UEIx-iqyHRjNHlOV7s75tP0b5efvt2sk,1156
|
|
37
37
|
scale_gp_beta/lib/tracing/util.py,sha256=8Oq4wLXRNOzh3CC1zRaBEr0h_WdXLrk536BUNKRddVE,1527
|
|
38
38
|
scale_gp_beta/resources/__init__.py,sha256=Fyo05_2_pc5orfyTSIpxa3btmBTd45VasgibwSqbbKo,4942
|
|
39
39
|
scale_gp_beta/resources/completions.py,sha256=4esj9lGTJAxt6wFvON126DvEGkMIChRZ6uZBOf56Aac,31868
|
|
@@ -117,7 +117,7 @@ scale_gp_beta/types/chat/completion_models_params.py,sha256=ETxafJIUx4tTvkiR-ZCr
|
|
|
117
117
|
scale_gp_beta/types/chat/completion_models_response.py,sha256=Ctgj6o-QWPSdjBKzG9J4Id0-DjXu4UGGw1NR6-840Ec,403
|
|
118
118
|
scale_gp_beta/types/chat/model_definition.py,sha256=NNgopTm900GD0Zs2YHkcvoW67uKaWUKVyPbhKBHvKdQ,817
|
|
119
119
|
scale_gp_beta/types/files/__init__.py,sha256=OKfJYcKb4NObdiRObqJV_dOyDQ8feXekDUge2o_4pXQ,122
|
|
120
|
-
scale_gp_beta-0.1.
|
|
121
|
-
scale_gp_beta-0.1.
|
|
122
|
-
scale_gp_beta-0.1.
|
|
123
|
-
scale_gp_beta-0.1.
|
|
120
|
+
scale_gp_beta-0.1.0a21.dist-info/METADATA,sha256=ZSHBKPl86WyhjRcUXYbMKDvPUAmeodrSMGKQ6S9QAQo,16881
|
|
121
|
+
scale_gp_beta-0.1.0a21.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
122
|
+
scale_gp_beta-0.1.0a21.dist-info/licenses/LICENSE,sha256=x49Bj8r_ZpqfzThbmfHyZ_bE88XvHdIMI_ANyLHFFRE,11338
|
|
123
|
+
scale_gp_beta-0.1.0a21.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|