Skip to content

HiMarket integrates with Alibaba Cloud SLS (Simple Log Service) to provide observability capabilities, supporting metric aggregation, chart visualization, and log search based on access logs. This guide walks you through configuring SLS observability.

The SLS approach is suitable for the following scenarios:

  • Using the Alibaba Cloud commercial AI Gateway (Alibaba Cloud AI Gateway or Apsara Stack Enterprise Edition) — simply enable SLS log delivery (works out of the box)
  • Using open-source Higress — configure the ai-statistics plugin and log collection to deliver logs to Alibaba Cloud SLS

If you are not using an Alibaba Cloud environment, you can choose the Database-based Observability approach instead.

  • Observability Dashboards: Model invocation statistics, MCP tool invocation statistics, request success rate, response time, and more
  • Log Query: Custom SQL queries against access logs
  • Authentication: Supports both STS (default) and AK/SK authentication methods
  • Automatic Degradation: When SLS is not configured, the system automatically returns empty data without affecting normal operation
  • For open-source Higress, the following configuration is required
  • For the Alibaba Cloud commercial AI Gateway (Alibaba Cloud / Apsara Stack Enterprise Edition), no configuration below is needed — just enable log delivery.

Before starting the configuration, you need to prepare the following resources in the Alibaba Cloud SLS console:

  1. Log in to the Alibaba Cloud SLS Console
  2. Create a Project (e.g., apigateway-csb-cop)
  3. Create a Logstore under the Project (e.g., apig-access-log)

Collect gateway access logs into the Logstore created above. We recommend using Higress 2.1.9 or later, as the accesslogformat has been optimized for the HiMarket observability dashboards.

The log format includes the following key fields:

Basic Fields:

  • __time__: Timestamp
  • response_code: Response status code
  • duration: Request duration
  • method: Request method
  • consumer: Caller identifier
  • route_name: Route name
  • upstream_cluster: Upstream service

AI-related Fields (JSON-formatted ai_log field):

  • model: Model name
  • api: API name
  • input_token: Input token count
  • output_token: Output token count
  • response_type: Response type (stream/normal)
  • llm_service_duration: LLM service duration
  • cache_status: Cache status (hit/miss/skip)
  • token_ratelimit_status: Rate limiting status
  • mcp_tool_name: MCP tool name

HiMarket provides an automatic index update API that configures indexes automatically on startup (AK/SK must have index creation permissions).

  • Text fields: method, consumer, route_name, upstream_cluster, etc.
  • Numeric fields: duration, bytes_received, bytes_sent, response_code, etc.
  • JSON fields: ai_log (enable JSON indexing, which includes the AI-related fields listed above)

Prepare AK/SK authentication credentials:

AK/SK (Recommended for development and testing environments)

  1. Log in to the Alibaba Cloud console
  2. Navigate to the AccessKey management page
  3. Create or retrieve your AccessKey ID and AccessKey Secret
  4. Ensure the AccessKey has SLS read permissions

All SLS configuration in HiMarket is injected via environment variables — no configuration file changes are needed. application.yml already includes environment variable placeholders with default values:

Environment VariableDescriptionDefault Value
SLS_ENDPOINTSLS service endpoint (required), format: <region>.log.aliyuncs.comEmpty (automatically degrades to returning empty data when not configured)
SLS_AUTH_TYPEAuthentication methodSTS
SLS_ACCESS_KEY_IDAccessKey ID (required for AK_SK mode)Empty
SLS_ACCESS_KEY_SECRETAccessKey Secret (required for AK_SK mode)Empty
SLS_DEFAULT_PROJECTSLS Project nameapigateway-csb-cop
SLS_DEFAULT_LOGSTORESLS Logstore nameapig-access-log
OBSERVABILITY_LOG_SOURCELog data source typeSLS

SLS_AUTH_TYPE supports two values: STS (for Alibaba Cloud ECS/ACK and other environments with instance roles) and AK_SK (for development/testing or non-Alibaba Cloud environments).

Choose the configuration method based on your deployment approach:

Terminal window
export SLS_ENDPOINT="cn-hangzhou.log.aliyuncs.com"
export SLS_AUTH_TYPE="AK_SK"
export SLS_ACCESS_KEY_ID="your-access-key-id"
export SLS_ACCESS_KEY_SECRET="your-access-key-secret"
# The following two can be omitted if they match the default values
export SLS_DEFAULT_PROJECT="apigateway-csb-cop"
export SLS_DEFAULT_LOGSTORE="apig-access-log"

Add the following to the environment section in docker-compose.yml:

services:
himarket-server:
environment:
- SLS_ENDPOINT=cn-hangzhou.log.aliyuncs.com
- SLS_AUTH_TYPE=AK_SK
- SLS_ACCESS_KEY_ID=your-access-key-id
- SLS_ACCESS_KEY_SECRET=your-access-key-secret

Inject the environment variables above via Secret or ConfigMap. It is recommended to store AK/SK in a Secret:

apiVersion: v1
kind: Secret
metadata:
name: himarket-sls-secret
type: Opaque
stringData:
SLS_ACCESS_KEY_ID: "your-access-key-id"
SLS_ACCESS_KEY_SECRET: "your-access-key-secret"
---
# Reference in Deployment
env:
- name: SLS_ENDPOINT
value: "cn-hangzhou.log.aliyuncs.com"
- name: SLS_AUTH_TYPE
value: "AK_SK"
- name: SLS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: himarket-sls-secret
key: SLS_ACCESS_KEY_ID
- name: SLS_ACCESS_KEY_SECRET
valueFrom:
secretKeyRef:
name: himarket-sls-secret
key: SLS_ACCESS_KEY_SECRET

After starting HiMarket, check the logs to confirm that the SLS configuration was loaded successfully:

Terminal window
# Development environment
mvn clean install -pl himarket-bootstrap -am
cd himarket-bootstrap && mvn spring-boot:run
# Production environment
java -jar himarket-bootstrap/target/himarket-bootstrap.jar

Log output on successful startup:

INFO c.a.h.config.ObservabilityConfig - Observability log source: SLS
INFO c.a.h.config.ObservabilityConfig - SLS endpoint: cn-hangzhou.log.aliyuncs.com, project: apigateway-csb-cop, logstore: apig-access-log, authType: AK_SK

If SLS_ENDPOINT is not configured, the following warning will be logged (this does not affect system operation; observability APIs will return empty data):

WARN c.a.h.config.ObservabilityConfig - SLS endpoint is not configured! Queries will return empty results.

ai-statistics plugin configuration example:

- config:
attributes:
- apply_to_log: true
default_value: unknown
key: consumer
value: x-mse-consumer
value_source: request_header
- apply_to_log: true
key: fallback_from
value: x-higress-fallback-from
value_source: request_header
- apply_to_log: true
apply_to_span: true
as_separate_log_field: true
key: question
trace_span_key: gen_ai.input.messages
value: messages.@reverse.0.content
value_source: request_body
- apply_to_log: true
apply_to_span: true
as_separate_log_field: true
key: answer
rule: append
trace_span_key: gen_ai.input.messages
value: choices.0.delta.content
value_source: response_streaming_body
- apply_to_log: true
apply_to_span: true
as_separate_log_field: true
key: answer
trace_span_key: gen_ai.input.messages
value: choices.0.message.content
value_source: response_body
configDisable: false
ingress:
- ai-route-higress-qwen-max.internal

ai-statistics plugin configuration example:

- config:
attributes:
- apply_to_log: true
key: jsonrpc_version
value: x-envoy-jsonrpc-version
value_source: request_header
trace_span_key: network.protocol.version
apply_to_span: true
- apply_to_log: true
key: jsonrpc_id
value: x-envoy-jsonrpc-id
value_source: request_header
trace_span_key: rpc.jsonrpc.request_id
apply_to_span: true
- apply_to_log: true
key: jsonrpc_method
value: x-envoy-jsonrpc-method
value_source: request_header
trace_span_key: mcp.method.name
apply_to_span: true
- apply_to_log: true
key: jsonrpc_params
value: x-envoy-jsonrpc-params
value_source: request_header
trace_span_key: mcp.arguments
apply_to_span: true
- apply_to_log: true
key: jsonrpc_result
value: x-envoy-jsonrpc-result
value_source: response_header
- apply_to_log: true
apply_to_span: true
attribute_key: tool.name
key: mcp_tool_name
value: x-envoy-mcp-tool-name
value_source: request_header
trace_span_key: mcp.tool.name
apply_to_span: true
- apply_to_log: true
apply_to_span: true
attribute_key: tool.parameters
key: mcp_tool_arguments
value: x-envoy-mcp-tool-arguments
value_source: request_header
- apply_to_log: true
key: mcp_tool_response
value: x-envoy-mcp-tool-response
value_source: response_header
- apply_to_log: true
key: mcp_tool_error
value: x-envoy-mcp-tool-error
value_source: response_header
configDisable: false
ingress:
- mcp-server-travel.internal

pre-request plugin configuration example:

apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
annotations:
name: pre-request.internal
namespace: himarket-system
spec:
imagePullPolicy: Always
matchRules:
- config:
stage: request
configDisable: false
ingress:
- mcp-server-travel.internal
phase: AUTHN
priority: 1000
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/jsonrpc-converter:1.0.0

pre-response plugin configuration example:

apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
annotations:
name: pre-response.internal
namespace: himarket-system
spec:
imagePullPolicy: Always
matchRules:
- config:
stage: response
configDisable: false
ingress:
- mcp-server-travel.internal
phase: UNSPECIFIED_PHASE
priority: 1000
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/jsonrpc-converter:1.0.0

Plugin priority configuration:

pre-request(json-converter):
phase: AUTHN
priority: 1000
key-auth:
phase: AUTHN
priority: 310
ai-statistics:
phase: AUTHN
priority: 100
pre-response(json-converter):
phase: UNSPECIFIED_PHASE
priority: 1000
mcp-server:
phase: UNSPECIFIED_PHASE
priority: 999
ai-security-guard:
phase: UNSPECIFIED_PHASE
priority: 850

HiMarket includes a rich set of preset query scenarios covering the Model Dashboard, MCP Dashboard, and more:

Scenario IDDescriptionApplicable Dashboard
pvTotal request countModel, MCP
uvUnique caller countModel, MCP
fallback_countFallback request countModel
bytes_receivedGateway inbound traffic (MB)MCP
bytes_sentGateway outbound traffic (MB)MCP
input_token_totalTotal input tokensModel
output_token_totalTotal output tokensModel
token_totalTotal tokensModel
Scenario IDDescriptionApplicable Dashboard
qps_streamStreaming QPSModel
qps_normalNon-streaming QPSModel
qps_totalOverall QPSModel
success_rateRequest success rateModel, MCP
token_per_sec_inputInput tokens/sModel
token_per_sec_outputOutput tokens/sModel
token_per_sec_totalTotal tokens/sModel
rt_avg_totalAverage response time (overall)Model
rt_avg_streamAverage response time (streaming)Model
rt_avg_normalAverage response time (non-streaming)Model
rt_first_tokenTime to first tokenModel
cache_hit/miss/skipCache hit/miss/skipModel
ratelimited_per_secRate-limited requests/sModel
qps_by_statusQPS grouped by status codeMCP
qps_total_simpleTotal QPSMCP
rt_avgAverage response timeMCP
rt_p99/p95/p90/p50P99/P95/P90/P50 response timeMCP
Scenario IDDescriptionApplicable Dashboard
model_token_tableModel token usage statisticsModel
consumer_token_tableConsumer token usage statisticsModel
service_token_tableService token usage statisticsModel
error_requests_tableError request statisticsModel
ratelimited_consumer_tableRate-limited consumer statisticsModel
risk_label_tableRisk type statisticsModel
risk_consumer_tableRisk consumer statisticsModel
method_distributionMethod distributionMCP
gateway_status_distributionGateway status code distributionMCP
backend_status_distributionBackend status code distributionMCP
request_distributionRequest distributionMCP
Scenario IDDescription
filter_service_optionsInstance list
filter_api_optionsAPI list
filter_model_optionsModel list
filter_route_optionsRoute list
filter_consumer_optionsConsumer list
filter_upstream_optionsUpstream service list
filter_mcp_tool_optionsMCP tool name list
filter_mcp_server_optionsMCP Server list

Possible Causes:

  • SLS is not configured (endpoint is empty)
  • Project or Logstore does not exist
  • No log data within the specified time range
  • Incorrect authentication credentials

Solutions:

  1. Check that the configuration file or environment variables are set correctly
  2. Review application logs to confirm SLS configuration loading status
  3. Log in to the SLS console to verify that the Project and Logstore exist
  4. Use the SLS console to query and verify that data exists
  5. Verify that the AccessKey has SLS read permissions

Possible Causes:

  • Time range is too large
  • Log volume is too high
  • Indexes are not configured or misconfigured

Solutions:

  1. Narrow the query time range
  2. Configure indexes for the Logstore in the SLS console
  3. Use preset scenarios instead of complex custom queries
  4. Increase the interval parameter to reduce the number of data points

Issue 3: Query Results Do Not Match Expectations

Section titled “Issue 3: Query Results Do Not Match Expectations”

Possible Causes:

  • Log field mapping mismatch
  • Incorrect index configuration
  • SQL syntax errors

Solutions:

  1. Confirm that log field names match the preset SQL queries
  2. Check that JSON fields (e.g., ai_log) have JSON indexing enabled
  3. Review application logs to see the actual SQL being executed
  4. Manually execute the SQL in the SLS console to verify

Error Log:

ERROR c.a.h.s.g.f.SlsClientFactory - Failed to create SLS client
LogException: AccessKeyId is required

Solutions:

  1. Confirm that environment variables are set correctly
  2. Confirm that auth-type is set to AK_SK
  3. Verify that the AccessKey ID and Secret are correct
  4. Confirm that the AccessKey has not been disabled or expired
  • Do not write AccessKeys directly into configuration files
  • Use environment variables or Kubernetes Secrets to manage sensitive information
  • Rotate AccessKeys regularly
  • Follow the principle of least privilege — grant only SLS read permissions
  • Set reasonable query time ranges — avoid querying more than 7 days at once
  • Configure indexes to improve query performance
  • Use preset scenarios instead of complex custom queries
  • Increase the interval to reduce the number of time-series data points
  • Configure Logstore retention periods based on actual needs
  • Set reasonable log collection rules to avoid collecting unnecessary logs
  • Use the SLS data lifecycle management feature
  • Configure query anomaly alerts in the SLS console
  • Monitor SLS-related errors in HiMarket application logs
  • Regularly check SLS usage and costs
RegionEndpoint
China East 1 (Hangzhou)cn-hangzhou.log.aliyuncs.com
China East 2 (Shanghai)cn-shanghai.log.aliyuncs.com
China North 1 (Qingdao)cn-qingdao.log.aliyuncs.com
China North 2 (Beijing)cn-beijing.log.aliyuncs.com
China North 3 (Zhangjiakou)cn-zhangjiakou.log.aliyuncs.com
China South 1 (Shenzhen)cn-shenzhen.log.aliyuncs.com
China Southwest 1 (Chengdu)cn-chengdu.log.aliyuncs.com

For more regions, refer to: https://help.aliyun.com/document_detail/29008.html