[BUG] Resource::Create() throws bad_variant_access if process.executable.name isn't a string
I maintainer di solito rispondono entro 1 giorno
@ryux1 ci sta già lavorando.
Dal 8/9/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- observability-sre
Direzione di ricerca
Inizia in sdk/src/resource/resource.cc, in Resource::Create, concentrandoti sulla logica del nome del servizio predefinito e sull'attributo process.executable.name. Verifica il comportamento con un attributo che non è una stringa e conferma che la creazione ricada su "unknown_service" senza generare un'eccezione né terminare l'inizializzazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 1.4k
- Fork
- 640
- Merge medio
- 1g 10h
- PR unite (30g)
- 74
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di open-telemetry/opentelemetry-cpp
-
[CI] Add Ubuntu 26.04 runners to the CI workflowForse già presa @deodattap l’ha presa 8 giorni fa. Apertatriage/accepted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-telemetry/opentelemetry-cpp#4596 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] OnResponse() can call std::terminate() when the response body fails to parse as JSON/protobufForse già presa @YuEfSaEDU l’ha presa 20 giorni fa. Apertabug help wanted triage/accepted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
open-telemetry/opentelemetry-cpp#4534 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] ETW Properties::to_vector doubles the result and reads past a string_viewForse già presa @Tyagiquamar l’ha presa 6 giorni fa. Apertaneeds-triage Stale
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
open-telemetry/opentelemetry-cpp#4347 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug Stale triage/accepted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
open-telemetry/opentelemetry-cpp#3109 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
open-telemetry/opentelemetry-cpp#4678 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di open-telemetry/opentelemetry-cpp
Issue simili
-
8-membered-ring atrop stereo lost in 2026.09.1Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 Mezza giornata Idoneità per principianti 86/100
I maintainer di solito rispondono entro 2 giorni
-
thread safetyAperta1.0
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
libasr headers?Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Type: Bug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
-
llvm-trunk
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno