[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
- フォーク
- 658
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 55
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
open-telemetry/opentelemetry-cpp のほかの issue
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
open-telemetry/opentelemetry-cpp#4745 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
open-telemetry/opentelemetry-cpp#4697 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
TracerContext construction might result in a terminate再び着手できるかも @akshat-lakhera が 22 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンtriage/accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
open-telemetry/opentelemetry-cpp#4684 · コメント 2 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[CI] Add Ubuntu 26.04 runners to the CI workflow再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンtriage/accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-telemetry/opentelemetry-cpp#4596 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] OnResponse() can call std::terminate() when the response body fails to parse as JSON/protobuf対応中かも @YuEfSaEDU が 47 日前に担当しました。 オープンbug help wanted triage/accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
open-telemetry/opentelemetry-cpp#4534 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
open-telemetry/opentelemetry-cpp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cython/cython#8110 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
PR bot doesn't recognize hip-tests as a unit test directory対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ROCm/rocm-systems#14923 ·
メンテナーはふだん 2 日以内に返信
-
arrays asr pass bug ICE intrinsic medium priority
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Area: World-Readiness
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
microsoft/calculator#2522 ·
-
missing `catch.hpp`オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/inflatelib#34 · コメント 1 件 ·