You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:skip injection if .NET OTel packages installed (#324)
Makes .NET injection more conservative by skipping auto-instrumentation when the target app already references OpenTelemetry packages.
The injector inspects the *.deps.json file of the target application when it is available. If the dependency graph already includes OpenTelemetry*, the injector skips adding .NET auto-instrumentation environment.
print.printDebug("Proceeding with the injection of the .NET OpenTelemetry instrumentation. Could not determine the managed application path: {}", .{err});
187
+
returntrue;
188
+
};
189
+
constapp_path=maybe_app_pathorelse {
190
+
print.printDebug("Proceeding with the injection of the .NET OpenTelemetry instrumentation. The process does not look like a recognized .NET application startup.", .{});
print.printDebug("Proceeding with the injection of the .NET OpenTelemetry instrumentation. Could not determine the application metadata paths: {}", .{err});
print.printDebug("Proceeding with the injection of the .NET OpenTelemetry instrumentation. Could not read {s}: {}", .{ metadata_paths.deps_path, err });
203
+
returntrue;
204
+
};
205
+
deferallocator.free(deps_content);
206
+
207
+
if (depsJsonContainsOpenTelemetryDependency(allocator, deps_content)) |contains_opentelemetry| {
208
+
if (contains_opentelemetry) {
209
+
print.printInfo("Skipping the injection of the .NET OpenTelemetry instrumentation because {s} already references OpenTelemetry packages.", .{metadata_paths.deps_path});
210
+
returnfalse;
211
+
}
212
+
} else|err| {
213
+
print.printDebug("Proceeding with the injection of the .NET OpenTelemetry instrumentation. Could not parse {s} safely: {}", .{ metadata_paths.deps_path, err });
214
+
returntrue;
215
+
}
216
+
217
+
returntrue;
218
+
}
219
+
220
+
fnresolveManagedApplicationPath(
221
+
allocator: std.mem.Allocator,
222
+
cmdline_args: []const []constu8,
223
+
self_exe_path: []constu8,
224
+
) !?[]u8 {
225
+
if (cmdline_args.len==0) {
226
+
returnnull;
227
+
}
228
+
229
+
if (std.mem.eql(u8, std.fs.path.basename(cmdline_args[0]), dotnet_host_name)) {
230
+
for (cmdline_args[1..]) |arg| {
231
+
if (arg.len==0orarg[0] =='-') {
232
+
continue;
233
+
}
234
+
if (std.mem.endsWith(u8, arg, ".dll") orstd.mem.endsWith(u8, arg, ".exe")) {
test"resolveManagedApplicationPath: dotnet host without managed assembly returns null" {
401
+
constcmdline_args= [_][]constu8{
402
+
"/usr/bin/dotnet",
403
+
"--info",
404
+
};
405
+
406
+
trytest_util.expectWithMessage((tryresolveManagedApplicationPath(testing.allocator, &cmdline_args, "/usr/bin/dotnet")) ==null, "app path should be null");
0 commit comments