Wuying Observer SDK for Python
Project description
Wuying GuestOS Observer Python
功能
- 记录埋点和Trace数据
- 埋点的数据格式是JSON对象,包含埋点名称(eventName)、时间(time)、属性(properties)和一些其它的配置信息,比如实例名称、版本等信息。
- Trace数据格式是JSON对象,包含TraceID、SpanID、ParentSpanID、Name、Kind、StartTime、EndTime、Duration、Attributes、Events、Links、StatusCode、StatusMessage等信息。以SLS Trace数据格式输出到本地文件, 通过定制opentelemetry-python的Exporter实现。
使用方法
- 创建一个Python项目,并安装OpenTelemetry SDK
- 使用示例可以参考demo.py
from wobs.observer import init, shutdown, new_span_as_current, new_track_point
if __name__ == "__main__":
# 初始化observer,指定trackpoint和trace文件存放目录,这里设置为当前路径,默认可不填,和C++、Golang版本保持一致
init("test", track_point_dir='./', trace_dir='./')
# 创建一个span,并设置属性和事件
with new_span_as_current("test_trace") as span:
# 设置属性
span.set_attribute("key", "value")
# 添加事件
span.add_event("event1", {"event_attr": "event_value"})
# 如果失败了,设置trace的状态和错误信息
span.set_status(get_status(False), "error message")
# 记录一个埋点
new_track_point("test_trace")
# 程序结束后关闭observer,这一步是可选的
shutdown()
如何使用远端的trace_id创建span
创建span时,可以指定trace_id和span_id,这样trace_id和span_id就会作为span的父span,从而实现链路追踪。这里在new_span_as_current和new_span方法中做了封装,可以直接传入trace_id和span_id,具体的实现可以参考wobs/observer.py。
with new_span_as_current("test_trace", trace_id="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", span_id="xxxxxxxxxxxxxxxx") as span:
span.set_attribute("key", "value")
动态配置 userAliUid
SDK 支持从配置文件 wobs.config.json 中动态读取 userAliUid,并自动将其附加到埋点数据中。
配置文件路径(根据平台自动选择):
- 云手机(Android):
/data/vendor/log/wuying/wobs.config.json - Windows:
C:\ProgramData\wuying\wobs.config.json - Linux/macOS:
/var/log/wuying/wobs.config.json
配置文件格式:
{
"userAliUid": "1234567890"
}
功能特性:
- SDK 初始化时自动读取配置文件中的
userAliUid - 后台线程每 3 秒轮询配置文件,实时检测变更
- 无需重启程序,配置文件的修改会在 3 秒内生效
userAliUid自动附加到所有埋点数据的用户信息字段中
测试示例:
python3 examples/test_userAliUid.py
发布
修改pyproject.toml文件中的version字段,并执行以下命令进行发布
uv build
uv run twine upload dist/*
依赖
- Opentelemetry python sdk
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wobs-0.1.7.tar.gz.
File metadata
- Download URL: wobs-0.1.7.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb9eaa3c7ae08226d9ca05dcf2a155ae511f90b47d03d8969be4d46af8bfae49
|
|
| MD5 |
7a73d793a53bc90e69b0104becfd3255
|
|
| BLAKE2b-256 |
1e37e11f878dccf6a62b3a26d1761b0b213192628eb78a2326aa7638ae328a22
|
File details
Details for the file wobs-0.1.7-py3-none-any.whl.
File metadata
- Download URL: wobs-0.1.7-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f969cbc0af4b9282785f4312e6a553ae05f59f93e92905004e242e5689a065ac
|
|
| MD5 |
2dc20cdc32c68d69164d00d7e1d8355e
|
|
| BLAKE2b-256 |
aa57b3714a0f427ce68ea9e21d9316ef8f9529200b4c5bdcd8558e4e1840d388
|