[BUG] Resource::Create() throws bad_variant_access if process.executable.name isn't a string
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 84/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp
调研方向
从 sdk/src/resource/resource.cc 中的 Resource::Create 开始,重点关注默认服务名称逻辑和 process.executable.name 属性。使用非字符串属性验证行为,并确认创建会回退到 "unknown_service",且不会抛出异常或终止初始化。
由索引模型根据 Issue 内容生成。
描述
Describe your environment
Reproduced by source read + build on main at 11fa0db0 (also present in v1.28.0, the latest release -- not a regression). sdk/src/resource/resource.cc, Resource::Create.
Steps to reproduce
Resource Resource::Create(const ResourceAttributes &attributes, const std::string &schema_url)
{
...
if (resource.attributes_.find(semconv::service::kServiceName) == resource.attributes_.end())
{
std::string default_service_name = "unknown_service";
auto it_process_executable_name =
resource.attributes_.find(semconv::process::kProcessExecutableName);
if (it_process_executable_name != resource.attributes_.end())
{
default_service_name += ":" + nostd::get<std::string>(it_process_executable_name->second);
}
resource.attributes_[semconv::service::kServiceName] = default_service_name;
}
return resource;
}
it_process_executable_name->second is an AttributeValue (nostd::variant). nostd::get<std::string> throws if the variant doesn't currently hold a std::string. process.executable.name can end up holding a different alternative than std::string in more than one way: a custom ResourceDetector setting it directly, an environment/config-driven attribute source, or simply a caller passing it in attributes as const char*/string_view/an integer by mistake -- none of those are prevented by the ResourceAttributes type itself.
To trigger: call Resource::Create(attributes, schema_url) with attributes containing {"process.executable.name", <anything that isn't a std::string>} and no service.name already set.
What is the expected behavior?
If process.executable.name is present but not a string, Resource::Create should fall back to just "unknown_service" (or otherwise degrade gracefully) rather than crash.
What is the actual behavior?
nostd::get<std::string> throws nostd::bad_variant_access. Since Resource::Create (and its callers up through TracerProvider/LoggerProvider/MeterProvider construction) isn't inside any exception handling, this propagates out and terminates initialization -- often during process/provider startup or a reload, i.e. exactly when an application least wants an unhandled crash.
Additional context
Suggested fix -- use nostd::get_if instead of the throwing nostd::get, and simply skip the suffix if the attribute isn't a string:
if (it_process_executable_name != resource.attributes_.end())
{
- default_service_name += ":" + nostd::get<std::string>(it_process_executable_name->second);
+ if (const auto *executable_name =
+ nostd::get_if<std::string>(&it_process_executable_name->second))
+ {
+ default_service_name += ":" + *executable_name;
+ }
}
Compile-checked against a clean build of this file -- no warnings or errors. Happy to open a PR with this if useful.
- 主要语言
- C++
- 星标
- 1.4k
- 派生
- 647
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 73
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
open-telemetry/opentelemetry-cpp 的其他 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 62/100
open-telemetry/opentelemetry-cpp#4684 · 1 个 reaction ·
维护者通常 1 天内回复
-
[CI] Add Ubuntu 26.04 runners to the CI workflow可能已有人在做 @deodattap 于 10 天前认领。 未关闭triage/accepted
难度 2/5 1-3 小时 新手友好度 72/100
open-telemetry/opentelemetry-cpp#4596 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
[BUG] OnResponse() can call std::terminate() when the response body fails to parse as JSON/protobuf可能已有人在做 @YuEfSaEDU 于 22 天前认领。 未关闭bug help wanted triage/accepted
难度 2/5 1-3 小时 新手友好度 78/100
open-telemetry/opentelemetry-cpp#4534 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
[BUG] ETW Properties::to_vector doubles the result and reads past a string_view可能已有人在做 @Tyagiquamar 于 8 天前认领。 未关闭needs-triage Stale
难度 2/5 1-3 小时 新手友好度 68/100
open-telemetry/opentelemetry-cpp#4347 · 1 条评论 ·
维护者通常 1 天内回复
-
bug Stale triage/accepted
难度 1/5 1 小时以内 新手友好度 62/100
open-telemetry/opentelemetry-cpp#3109 · 2 条评论 ·
维护者通常 1 天内回复
查看 open-telemetry/opentelemetry-cpp 的全部 Issue
相似的 Issue
-
Component: Python API
难度 2/5 1-3 小时 新手友好度 70/100
Vector35/binaryninja-api#8649 ·
维护者通常 3 天内回复
-
ai_p2 comp-parquet-reader-v3
难度 2/5 半天 新手友好度 66/100
ClickHouse/ClickHouse#124986 ·
维护者通常 1 天内回复
-
bug product: very_good_flutter_plugin
难度 1/5 1-3 小时 新手友好度 78/100
VeryGoodOpenSource/very_good_templates#654 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
AcademySoftwareFoundation/OpenImageIO#5550 ·
维护者通常 2 天内回复