Skip to content

Commit 46dd485

Browse files
committed
Add support for image synthesis
Change-Id: Ib7a9bc46c390a237610d930bead35bf240a28a0c Co-developed-by: Cursor <[email protected]>
1 parent 1fe9022 commit 46dd485

File tree

16 files changed

+5309
-68
lines changed

16 files changed

+5309
-68
lines changed

instrumentation-loongsuite/loongsuite-instrumentation-dashscope/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
- Support for AioGeneration.call (async)
1414
- Support for TextEmbedding.call
1515
- Support for TextReRank.call
16+
- Support for ImageSynthesis.call (sync)
17+
- Support for ImageSynthesis.async_call (async task submission)
18+
- Support for ImageSynthesis.wait (async task waiting)
1619
- Support for streaming responses (sync and async)
1720
- Data extraction and telemetry collection using `opentelemetry-util-genai`
1821
- Span attributes following OpenTelemetry GenAI Semantic Conventions:

instrumentation-loongsuite/loongsuite-instrumentation-dashscope/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Supported APIs
6262

6363
* ``TextReRank.call``
6464

65+
* **Image Synthesis**
66+
67+
* ``ImageSynthesis.call`` (sync)
68+
* ``ImageSynthesis.async_call`` (async task submission)
69+
* ``ImageSynthesis.wait`` (async task waiting)
70+
6571

6672
Captured Attributes
6773
--------------------

instrumentation-loongsuite/loongsuite-instrumentation-dashscope/src/loongsuite/instrumentation/dashscope/__init__.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
LoongSuite Instrumentation for Alibaba Cloud DashScope SDK.
1717
1818
This instrumentation library provides automatic tracing for DashScope API calls,
19-
including text generation, text embedding, and text reranking.
19+
including text generation, text embedding, text reranking, and image synthesis.
2020
2121
Supported Operations:
2222
- Text Generation (sync/async, streaming/non-streaming)
2323
- Text Embedding
2424
- Text Reranking
25+
- Image Synthesis (sync/async)
2526
2627
Note: Chat Completion (OpenAI-compatible) is NOT supported due to a bug in
2728
DashScope SDK where Completions.create references a non-existent attribute
@@ -45,6 +46,9 @@
4546
from loongsuite.instrumentation.dashscope.patch import (
4647
wrap_aio_generation_call,
4748
wrap_generation_call,
49+
wrap_image_synthesis_async_call,
50+
wrap_image_synthesis_call,
51+
wrap_image_synthesis_wait,
4852
wrap_text_embedding_call,
4953
wrap_text_rerank_call,
5054
)
@@ -61,6 +65,7 @@
6165
logger = logging.getLogger(__name__)
6266

6367
_MODULE_GENERATION = "dashscope.aigc.generation"
68+
_MODULE_IMAGE_SYNTHESIS = "dashscope.aigc.image_synthesis"
6469
_MODULE_TEXT_EMBEDDING = "dashscope.embeddings.text_embedding"
6570
_MODULE_TEXT_RERANK = "dashscope.rerank.text_rerank"
6671

@@ -130,6 +135,27 @@ def wrap_text_rerank_call_with_provider(
130135
wrapped, instance, args, kwargs, handler=handler
131136
)
132137

138+
def wrap_image_synthesis_call_with_provider(
139+
wrapped, instance, args, kwargs
140+
):
141+
return wrap_image_synthesis_call(
142+
wrapped, instance, args, kwargs, handler=handler
143+
)
144+
145+
def wrap_image_synthesis_async_call_with_provider(
146+
wrapped, instance, args, kwargs
147+
):
148+
return wrap_image_synthesis_async_call(
149+
wrapped, instance, args, kwargs, handler=handler
150+
)
151+
152+
def wrap_image_synthesis_wait_with_provider(
153+
wrapped, instance, args, kwargs
154+
):
155+
return wrap_image_synthesis_wait(
156+
wrapped, instance, args, kwargs, handler=handler
157+
)
158+
133159
# Instrument Generation.call (sync)
134160
try:
135161
wrap_function_wrapper(
@@ -174,6 +200,41 @@ def wrap_text_rerank_call_with_provider(
174200
except Exception as e:
175201
logger.warning(f"Failed to instrument TextReRank.call: {e}")
176202

203+
# Instrument ImageSynthesis.call (sync)
204+
try:
205+
wrap_function_wrapper(
206+
module=_MODULE_IMAGE_SYNTHESIS,
207+
name="ImageSynthesis.call",
208+
wrapper=wrap_image_synthesis_call_with_provider,
209+
)
210+
logger.debug("Instrumented ImageSynthesis.call")
211+
except Exception as e:
212+
logger.warning(f"Failed to instrument ImageSynthesis.call: {e}")
213+
214+
# Instrument ImageSynthesis.async_call
215+
try:
216+
wrap_function_wrapper(
217+
module=_MODULE_IMAGE_SYNTHESIS,
218+
name="ImageSynthesis.async_call",
219+
wrapper=wrap_image_synthesis_async_call_with_provider,
220+
)
221+
logger.debug("Instrumented ImageSynthesis.async_call")
222+
except Exception as e:
223+
logger.warning(
224+
f"Failed to instrument ImageSynthesis.async_call: {e}"
225+
)
226+
227+
# Instrument ImageSynthesis.wait
228+
try:
229+
wrap_function_wrapper(
230+
module=_MODULE_IMAGE_SYNTHESIS,
231+
name="ImageSynthesis.wait",
232+
wrapper=wrap_image_synthesis_wait_with_provider,
233+
)
234+
logger.debug("Instrumented ImageSynthesis.wait")
235+
except Exception as e:
236+
logger.warning(f"Failed to instrument ImageSynthesis.wait: {e}")
237+
177238
def _uninstrument(self, **kwargs):
178239
"""Uninstrument the DashScope SDK.
179240
@@ -184,11 +245,15 @@ def _uninstrument(self, **kwargs):
184245
"""
185246
# pylint: disable=import-outside-toplevel
186247
import dashscope.aigc.generation
248+
import dashscope.aigc.image_synthesis
187249
import dashscope.embeddings.text_embedding
188250
import dashscope.rerank.text_rerank
189251

190252
unwrap(dashscope.aigc.generation.Generation, "call")
191253
unwrap(dashscope.aigc.generation.AioGeneration, "call")
254+
unwrap(dashscope.aigc.image_synthesis.ImageSynthesis, "call")
255+
unwrap(dashscope.aigc.image_synthesis.ImageSynthesis, "async_call")
256+
unwrap(dashscope.aigc.image_synthesis.ImageSynthesis, "wait")
192257
unwrap(dashscope.embeddings.text_embedding.TextEmbedding, "call")
193258
unwrap(dashscope.rerank.text_rerank.TextReRank, "call")
194259

0 commit comments

Comments
 (0)