Skip to main content

LoongSuite DashScope instrumentation

Project description

pypi

This library allows tracing calls to Alibaba Cloud DashScope APIs.

Installation

pip install loongsuite-instrumentation-dashscope

Usage

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

from opentelemetry.instrumentation.dashscope import DashScopeInstrumentor

# Initialize tracing
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(ConsoleSpanExporter())
)

# Instrument DashScope
DashScopeInstrumentor().instrument()

# Now use DashScope as normal
from dashscope import Generation

response = Generation.call(
    model="qwen-turbo",
    prompt="Hello!"
)

Supported APIs

  • Text Generation

    • Generation.call (sync)

    • AioGeneration.call (async)

    • Streaming support for both sync and async

  • Text Embedding

    • TextEmbedding.call

  • Text Rerank

    • TextReRank.call

  • Image Synthesis

    • ImageSynthesis.call (sync)

    • ImageSynthesis.async_call (async task submission)

    • ImageSynthesis.wait (async task waiting)

  • Speech Synthesis V1

    • SpeechSynthesizer.call (V1)

  • Speech Synthesis V2

    • SpeechSynthesizer.call (V2)

  • Video Synthesis

    • VideoSynthesis.call (sync)

    • VideoSynthesis.async_call (async task submission)

    • VideoSynthesis.wait (async task waiting)

Captured Attributes

This instrumentation follows the OpenTelemetry GenAI Semantic Conventions and uses opentelemetry-util-genai for standardized telemetry collection.

For Text Generation (Chat Completion) operations, the following attributes are captured:

Required Attributes: * gen_ai.operation.name - Operation type (“chat”) * gen_ai.provider.name - Provider name (“dashscope”)

Conditionally Required Attributes: * gen_ai.request.model - Requested model name (if available) * gen_ai.response.model - Actual model used (if different from request) * gen_ai.response.id - Request ID from DashScope (if available) * error.type - Error type (if operation ended in error)

Recommended Attributes: * gen_ai.response.finish_reasons - Finish reasons array (e.g., [“stop”], [“length”]) * gen_ai.usage.input_tokens - Input token count * gen_ai.usage.output_tokens - Output token count * gen_ai.request.temperature - Temperature parameter (if provided) * gen_ai.request.top_p - Top-p parameter (if provided) * gen_ai.request.top_k - Top-k parameter (if provided) * gen_ai.request.max_tokens - Max tokens parameter (if provided)

Opt-In Attributes (require environment variable configuration): * gen_ai.input.messages - Chat history provided to the model * gen_ai.output.messages - Messages returned by the model

To enable Opt-In attributes, set the environment variable:

export OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY

For Text Embedding operations:

Required Attributes: * gen_ai.operation.name - Operation type (“embeddings”, note: plural form) * gen_ai.provider.name - Provider name (“dashscope”)

Conditionally Required Attributes: * gen_ai.request.model - Requested model name (if available) * error.type - Error type (if operation ended in error)

Recommended Attributes: * gen_ai.usage.input_tokens - Input token count (if available) * gen_ai.embeddings.dimension.count - Number of dimensions (if available) * gen_ai.request.encoding_formats - Encoding formats (if specified)

For Text Rerank operations:

Note: Rerank operations are not yet explicitly defined in GenAI semantic conventions. This instrumentation follows the pattern of other GenAI operations.

Basic Attributes: * gen_ai.operation.name - Operation type (“rerank”) * gen_ai.provider.name - Provider name (“dashscope”) * gen_ai.request.model - Requested model name (if available) * error.type - Error type (if operation ended in error)

Configuration

API Key

Set your DashScope API key via environment variable:

export DASHSCOPE_API_KEY="your-api-key-here"

Message Content Capture

By default, message content (gen_ai.input.messages and gen_ai.output.messages) is not captured to protect sensitive data. To enable content capture, set the following environment variables:

export OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY

Options for OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: * SPAN_ONLY - Capture content in span attributes only * SPAN_AND_EVENT - Capture content in both spans and events * EVENT_ONLY - Capture content in events only (not yet supported) * NO_CONTENT - Do not capture content (default)

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file loongsuite_instrumentation_dashscope-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for loongsuite_instrumentation_dashscope-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7696e415d809a362b4b19c865c9e496a6445825d40ef308ffb2b1f054cc22667
MD5 42ebbb3a87cfba73ecd610837c62e150
BLAKE2b-256 cadff03b03539ac3bbeb923c26649fb6bb4805d1bfd2d7639def34d643fd53de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page