respan-instrumentation-replicate 0.1.0__tar.gz
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.
- respan_instrumentation_replicate-0.1.0/PKG-INFO +66 -0
- respan_instrumentation_replicate-0.1.0/README.md +46 -0
- respan_instrumentation_replicate-0.1.0/pyproject.toml +29 -0
- respan_instrumentation_replicate-0.1.0/src/respan_instrumentation_replicate/__init__.py +5 -0
- respan_instrumentation_replicate-0.1.0/src/respan_instrumentation_replicate/_constants.py +47 -0
- respan_instrumentation_replicate-0.1.0/src/respan_instrumentation_replicate/_instrumentation.py +896 -0
- respan_instrumentation_replicate-0.1.0/src/respan_instrumentation_replicate/_translator.py +340 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: respan-instrumentation-replicate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Respan instrumentation plugin for the Replicate Python SDK
|
|
5
|
+
License: Apache 2.0
|
|
6
|
+
Author: Respan
|
|
7
|
+
Author-email: team@respan.ai
|
|
8
|
+
Requires-Python: >=3.11,<3.14
|
|
9
|
+
Classifier: License :: Other/Proprietary License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: opentelemetry-semantic-conventions-ai (>=0.4.1)
|
|
15
|
+
Requires-Dist: replicate (>=1.0.0)
|
|
16
|
+
Requires-Dist: respan-sdk (>=2.6.1)
|
|
17
|
+
Requires-Dist: respan-tracing (>=2.17.0,<3.0.0)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Respan Replicate Instrumentation
|
|
21
|
+
|
|
22
|
+
Trace the official `replicate` Python SDK with Respan.
|
|
23
|
+
|
|
24
|
+
The instrumentation patches the Replicate client lifecycle and emits canonical
|
|
25
|
+
Respan spans for `run`, `async_run`, `stream`, `async_stream`, prediction
|
|
26
|
+
creation, prediction waiting, and prediction lookup/cancel operations.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install respan-ai respan-instrumentation-replicate replicate
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import os
|
|
38
|
+
|
|
39
|
+
import replicate
|
|
40
|
+
from respan import Respan, workflow
|
|
41
|
+
from respan_instrumentation_replicate import ReplicateInstrumentor
|
|
42
|
+
|
|
43
|
+
respan = Respan(
|
|
44
|
+
api_key=os.environ["RESPAN_API_KEY"],
|
|
45
|
+
instrumentations=[ReplicateInstrumentor()],
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@workflow(name="replicate_quickstart.workflow")
|
|
50
|
+
def run_prediction() -> str:
|
|
51
|
+
output = replicate.run(
|
|
52
|
+
"meta/meta-llama-3-8b-instruct",
|
|
53
|
+
input={"prompt": "Reply with one concise sentence about tracing."},
|
|
54
|
+
)
|
|
55
|
+
return "".join(str(chunk) for chunk in output) if not isinstance(output, str) else output
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
print(run_prediction())
|
|
59
|
+
respan.flush()
|
|
60
|
+
respan.shutdown()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Use `Respan(..., customer_identifier=..., thread_identifier=..., metadata=...)`
|
|
64
|
+
or `respan.propagate_attributes(...)` to attach Respan attributes to Replicate
|
|
65
|
+
spans.
|
|
66
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Respan Replicate Instrumentation
|
|
2
|
+
|
|
3
|
+
Trace the official `replicate` Python SDK with Respan.
|
|
4
|
+
|
|
5
|
+
The instrumentation patches the Replicate client lifecycle and emits canonical
|
|
6
|
+
Respan spans for `run`, `async_run`, `stream`, `async_stream`, prediction
|
|
7
|
+
creation, prediction waiting, and prediction lookup/cancel operations.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install respan-ai respan-instrumentation-replicate replicate
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
import replicate
|
|
21
|
+
from respan import Respan, workflow
|
|
22
|
+
from respan_instrumentation_replicate import ReplicateInstrumentor
|
|
23
|
+
|
|
24
|
+
respan = Respan(
|
|
25
|
+
api_key=os.environ["RESPAN_API_KEY"],
|
|
26
|
+
instrumentations=[ReplicateInstrumentor()],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@workflow(name="replicate_quickstart.workflow")
|
|
31
|
+
def run_prediction() -> str:
|
|
32
|
+
output = replicate.run(
|
|
33
|
+
"meta/meta-llama-3-8b-instruct",
|
|
34
|
+
input={"prompt": "Reply with one concise sentence about tracing."},
|
|
35
|
+
)
|
|
36
|
+
return "".join(str(chunk) for chunk in output) if not isinstance(output, str) else output
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
print(run_prediction())
|
|
40
|
+
respan.flush()
|
|
41
|
+
respan.shutdown()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use `Respan(..., customer_identifier=..., thread_identifier=..., metadata=...)`
|
|
45
|
+
or `respan.propagate_attributes(...)` to attach Respan attributes to Replicate
|
|
46
|
+
spans.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "respan-instrumentation-replicate"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Respan instrumentation plugin for the Replicate Python SDK"
|
|
5
|
+
authors = ["Respan <team@respan.ai>"]
|
|
6
|
+
license = "Apache 2.0"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
packages = [
|
|
9
|
+
{ include = "respan_instrumentation_replicate", from = "./src" },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[tool.poetry.dependencies]
|
|
13
|
+
python = ">=3.11,<3.14"
|
|
14
|
+
respan-tracing = "^2.17.0"
|
|
15
|
+
respan-sdk = ">=2.6.1"
|
|
16
|
+
replicate = ">=1.0.0"
|
|
17
|
+
opentelemetry-semantic-conventions-ai = ">=0.4.1"
|
|
18
|
+
|
|
19
|
+
[tool.poetry.plugins."respan.instrumentations"]
|
|
20
|
+
replicate = "respan_instrumentation_replicate:ReplicateInstrumentor"
|
|
21
|
+
|
|
22
|
+
[tool.pytest.ini_options]
|
|
23
|
+
markers = [
|
|
24
|
+
"integration: live network tests (requires API keys)",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["poetry-core"]
|
|
29
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Replicate instrumentation constants."""
|
|
2
|
+
|
|
3
|
+
REPLICATE_INSTRUMENTATION_NAME = "replicate"
|
|
4
|
+
REPLICATE_SYSTEM_NAME = "replicate"
|
|
5
|
+
|
|
6
|
+
REPLICATE_RUN_SPAN_NAME = "replicate.run"
|
|
7
|
+
REPLICATE_STREAM_SPAN_NAME = "replicate.stream"
|
|
8
|
+
REPLICATE_PREDICTION_CREATE_SPAN_NAME = "replicate.predictions.create"
|
|
9
|
+
REPLICATE_PREDICTION_WAIT_SPAN_NAME = "replicate.prediction.wait"
|
|
10
|
+
|
|
11
|
+
ASYNC_PREFIX = "async_"
|
|
12
|
+
|
|
13
|
+
DEPLOYMENT_KEY = "deployment"
|
|
14
|
+
ERROR_KEY = "error"
|
|
15
|
+
ID_KEY = "id"
|
|
16
|
+
INPUT_KEY = "input"
|
|
17
|
+
LOGS_KEY = "logs"
|
|
18
|
+
METRICS_KEY = "metrics"
|
|
19
|
+
MODEL_KEY = "model"
|
|
20
|
+
OUTPUT_KEY = "output"
|
|
21
|
+
PREDICTION_KEY = "prediction"
|
|
22
|
+
PROMPT_KEY = "prompt"
|
|
23
|
+
REF_KEY = "ref"
|
|
24
|
+
RESPAN_PARAMS_KEY = "respan_params"
|
|
25
|
+
RESPAN_PARAMS_MODEL_KEY = "model"
|
|
26
|
+
STATUS_KEY = "status"
|
|
27
|
+
STREAM_KEY = "stream"
|
|
28
|
+
VERSION_KEY = "version"
|
|
29
|
+
PREDICTION_RESPAN_MODEL_ATTR = "_respan_reported_model"
|
|
30
|
+
|
|
31
|
+
ASSISTANT_ROLE = "assistant"
|
|
32
|
+
USER_ROLE = "user"
|
|
33
|
+
|
|
34
|
+
MAX_STREAM_CHUNKS = 200
|
|
35
|
+
MAX_TEXT_LENGTH = 16_000
|
|
36
|
+
|
|
37
|
+
OFF_CONTRACT_ALIASES = {
|
|
38
|
+
"completion_tokens",
|
|
39
|
+
"has_tool_calls",
|
|
40
|
+
"model",
|
|
41
|
+
"parallel_tool_calls",
|
|
42
|
+
"prompt_tokens",
|
|
43
|
+
"span_tools",
|
|
44
|
+
"tool_calls",
|
|
45
|
+
"tools",
|
|
46
|
+
"total_request_tokens",
|
|
47
|
+
}
|