diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildOverviewExtensionController.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildOverviewExtensionController.java index ed42011..2490dc1 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildOverviewExtensionController.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildOverviewExtensionController.java @@ -8,6 +8,7 @@ import jetbrains.buildServer.serverSide.SProject; import jetbrains.buildServer.web.openapi.*; import jetbrains.buildServer.web.util.WebUtil; +import org.apache.logging.log4j.CloseableThreadContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.web.servlet.ModelAndView; @@ -76,26 +77,29 @@ protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull Ht : Long.parseLong(request.getParameter("buildId")); if (buildId != null) { - final SBuild build = sBuildServer.findBuildInstanceById(buildId); - if (build == null) //if it's queued, we won't get it - return getEmptyState(); + try (var ignored1 = CloseableThreadContext.put("teamcity.build.id", String.valueOf(buildId))) { - final SProject project = projectManager.findProjectByExternalId(build.getProjectExternalId()); + final SBuild build = sBuildServer.findBuildInstanceById(buildId); + if (build == null) //if it's queued, we won't get it + return getEmptyState(); - var features = project.getAvailableFeaturesOfType(PLUGIN_NAME); - if (!features.isEmpty()) { - var feature = features.stream().findFirst().get(); - var params = feature.getParameters(); + final SProject project = projectManager.findProjectByExternalId(build.getProjectExternalId()); - if (!params.get(PROPERTY_KEY_ENABLED).equals("true")) - return getEmptyState(); + var features = project.getAvailableFeaturesOfType(PLUGIN_NAME); + if (!features.isEmpty()) { + var feature = features.stream().findFirst().get(); + var params = feature.getParameters(); - var traceId = buildStorageManager.getTraceId(build); - if (traceId == null) - return getEmptyState(); + if (!params.get(PROPERTY_KEY_ENABLED).equals("true")) + return getEmptyState(); + + var traceId = buildStorageManager.getTraceId(build); + if (traceId == null) + return getEmptyState(); - var service = otelEndpointFactory.getOTELEndpointHandler(params.get(PROPERTY_KEY_SERVICE)); - return service.getBuildOverviewModelAndView(build, params, traceId); + var service = otelEndpointFactory.getOTELEndpointHandler(params.get(PROPERTY_KEY_SERVICE)); + return service.getBuildOverviewModelAndView(build, params, traceId); + } } } diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildStorageManagerImpl.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildStorageManagerImpl.java index f0231d1..97b2671 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildStorageManagerImpl.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/BuildStorageManagerImpl.java @@ -23,7 +23,7 @@ public String getTraceId(SBuild build) { File artifactsDir = build.getArtifactsDirectory(); File pluginFile = new File(artifactsDir, jetbrains.buildServer.ArtifactsConstants.TEAMCITY_ARTIFACTS_DIR + File.separatorChar + OTEL_TRACE_ID_FILENAME); - LOG.debug(String.format("Reading trace id or build %d.", build.getBuildId())); + LOG.debug(String.format("Reading trace id for build %d.", build.getBuildId())); if (!pluginFile.exists()) { LOG.info(String.format("Unable to find build artifact %s for build %d.", OTEL_TRACE_ID_FILENAME, build.getBuildId()));