From 8dd55807dd15112e4e04b3a2339c991292ea8cee Mon Sep 17 00:00:00 2001 From: Matt Richardson Date: Mon, 2 Dec 2024 10:07:51 +1100 Subject: [PATCH 1/3] Slight logging tweaks --- .../BuildOverviewExtensionController.java | 36 ++++++++++--------- .../server/BuildStorageManagerImpl.java | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) 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..b32d741 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; @@ -73,29 +74,32 @@ protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull Ht Long buildId = WebUtil.sakuraUIOpened(request) ? PluginUIContext.getFromRequest(request).getBuildId() - : Long.parseLong(request.getParameter("buildId")); + : Long.valueOf(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.findProje ctByExternalId(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())); From 7280dc5dd484b5a19155ef25e17a3a492071b43f Mon Sep 17 00:00:00 2001 From: Matt Richardson Date: Mon, 2 Dec 2024 10:14:52 +1100 Subject: [PATCH 2/3] Update BuildOverviewExtensionController.java --- .../opentelemetry/server/BuildOverviewExtensionController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b32d741..24e0f4a 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 @@ -83,7 +83,7 @@ protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull Ht if (build == null) //if it's queued, we won't get it return getEmptyState(); - final SProject project = projectManager.findProje ctByExternalId(build.getProjectExternalId()); + final SProject project = projectManager.findProjectByExternalId(build.getProjectExternalId()); var features = project.getAvailableFeaturesOfType(PLUGIN_NAME); if (!features.isEmpty()) { From 4ad7aca1750b7c54e19ea4ee8a6621def8c08f9c Mon Sep 17 00:00:00 2001 From: Matt Richardson Date: Mon, 2 Dec 2024 10:20:10 +1100 Subject: [PATCH 3/3] Update BuildOverviewExtensionController.java --- .../opentelemetry/server/BuildOverviewExtensionController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 24e0f4a..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 @@ -74,7 +74,7 @@ protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull Ht Long buildId = WebUtil.sakuraUIOpened(request) ? PluginUIContext.getFromRequest(request).getBuildId() - : Long.valueOf(Long.parseLong(request.getParameter("buildId"))); + : Long.parseLong(request.getParameter("buildId")); if (buildId != null) { try (var ignored1 = CloseableThreadContext.put("teamcity.build.id", String.valueOf(buildId))) {