v0.0.3
Changelog
๐ Breaking changes ๐
-
injector: Remove link-time dependency on__environ, inject environment variables once at startup via setenv instead of overriding libc's getenv function. (#166) This removes the declarationextern var __environ: [*]u8from the injector, that is, the dependency on the__environpointer symbol exported by libc.Motivation: The injector may be linked to binaries that, while dynamically linked, do not link any libc. This would result in the injector preventing the program from starting due to a linker error, effectively crashing the application under monitoring.
This change introduces a way to look up the
dlsymsymbol, and then in turn throughdlsymthe__environandsetenvsymbols. This happens at runtime in an initialization step, by inspecting the process' memory and finding thedlsymsymbol in memory. This allows us to read and manipulate the process environment without depending on any external symbols at link time. More importantly, we have the option to stand down if looking updlsym/__environ/setenvfails, and let the host process continue, instead of crashing it at startup.Also, the injector now no longer overrides libc's
getenvto inject environment variables but instead unconditionally injects all environment variables by callingsetenvat startup. This change is necessary, because even when removing the dependency on the__environsymbol (see above), there would still be potential to break certain executables:- For example, on some older distributions (Debian 11/bullseye is one),
libcandlibdlare two distinct libary files, withlibdlcontainingdlopen,dlcose,dlsymanddlerror. When a binary only bindslibc, but notlibdl, we would not find thedlsymsymbol (because it is actually really not loaded into memory), hence we wouldn't be able to find the__environorsetenvsymbols. As a consequence, we would not be able to backfill the injector-internal representation of the environment (std.os.environ/std.posix.getenv in the Zig code) and all calls togetenvwould return null; i.e. we would effectively obliterate the environment of the process. - Another issue is that, if a binary binds
libcrypto(i.e. uses OpenSSL), it will try to look up theOPENSSL_armcapenvironment variable before the injector init code even has ran. With thegetenvoverride, this would always return null, even ifOPENSSL_armcapis set (independent of thelibdlissue described above). Hence, overridinggetenvwould break some of OpenSSL's assumptions. - Many runtimes do not use
getenvto read environment variables. E.g. the JVM as well as the CLR usegetenvin their native startup code, but when environment variables are read from with the runtime, the reading bypassesgetenv. Hence, overriding getenv is not feasible to inject reliably into these runtimes. The same is true for Python. Injecting viasetenvsolves this problem.
Last but not least, we no longer inject resource attributes into the JVM via the workaround of adding
-Dotel.resource.attributestoJAVA_TOOL_OPTIONS. This was only necessary because the JVM does not readOTEL_RESOURCE_ATTRIBUTESviagetenv(see previous paragraph), hence this was a necessary workaround with the override-getenv approach. With the switch tosetenv, it is no longer necessary. - For example, on some older distributions (Debian 11/bullseye is one),
๐ก Enhancements ๐ก
-
environment: Limit all_auto_instrumentation_agents_env_path env vars to entries prefixed with OTEL_. (#176) -
config: add OTEL_INJECTOR_CONFIG_FILE to set config file location (#188) This adds support for a new environment variableOTEL_INJECTOR_CONFIG_FILEthat determines from which path the injector's configuration file is read. If the variable is not set or empty, the configuration file is read from the default path/etc/opentelemetry/otelinject.conf.This is useful in environments where you want to provide a configuration file, but you do not want to make any assumptions about the underlying file system's structure. I.e. you want to keep all assets of the injector (injector binary, auto-instrumentation agents and the injector configuration) completely separate from standard OS directories like
/etc.
๐งฐ Bug fixes ๐งฐ
environment: Fix out of index error when leveraging all_auto_instrumentation_agents_env_path with more than one env var. (#173)config: Fix handling of overly long lines in config file (#174) Continue to read the rest of the config file after discarding an overly long line