diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/IOTELEndpointHandler.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/IOTELEndpointHandler.java index ef9893b..823ee76 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/IOTELEndpointHandler.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/IOTELEndpointHandler.java @@ -2,6 +2,7 @@ import com.octopus.teamcity.opentelemetry.server.SetProjectConfigurationSettingsRequest; import io.opentelemetry.sdk.trace.SpanProcessor; +import jetbrains.buildServer.serverSide.BuildPromotion; import jetbrains.buildServer.serverSide.SBuild; import org.springframework.web.servlet.ModelAndView; @@ -11,7 +12,7 @@ public interface IOTELEndpointHandler { ModelAndView getBuildOverviewModelAndView(SBuild build, Map params, String traceId); - SpanProcessor buildSpanProcessor(String endpoint, Map params); + SpanProcessor buildSpanProcessor(BuildPromotion buildPromotion, String endpoint, Map params); SetProjectConfigurationSettingsRequest getSetProjectConfigurationSettingsRequest(HttpServletRequest request); diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/custom/CustomOTELEndpointHandler.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/custom/CustomOTELEndpointHandler.java index f56ccd5..88e6f3c 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/custom/CustomOTELEndpointHandler.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/custom/CustomOTELEndpointHandler.java @@ -7,6 +7,7 @@ import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; +import jetbrains.buildServer.serverSide.BuildPromotion; import jetbrains.buildServer.serverSide.SBuild; import jetbrains.buildServer.serverSide.crypt.EncryptUtil; import jetbrains.buildServer.web.openapi.PluginDescriptor; @@ -34,7 +35,7 @@ public ModelAndView getBuildOverviewModelAndView(SBuild build, Map params) { + public SpanProcessor buildSpanProcessor(BuildPromotion buildPromotion, String endpoint, Map params) { Map headers = new HashMap<>(); params.forEach((k, v) -> { if (k.startsWith(PROPERTY_KEY_HEADERS)) { diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/honeycomb/HoneycombOTELEndpointHandler.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/honeycomb/HoneycombOTELEndpointHandler.java index 7402cd4..214c454 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/honeycomb/HoneycombOTELEndpointHandler.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/honeycomb/HoneycombOTELEndpointHandler.java @@ -13,6 +13,7 @@ import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.semconv.ServiceAttributes; +import jetbrains.buildServer.serverSide.BuildPromotion; import jetbrains.buildServer.serverSide.SBuild; import jetbrains.buildServer.serverSide.TeamCityNodes; import jetbrains.buildServer.serverSide.crypt.EncryptUtil; @@ -24,7 +25,6 @@ import javax.annotation.Nullable; import javax.servlet.http.HttpServletRequest; -import java.time.Duration; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -63,7 +63,7 @@ public ModelAndView getBuildOverviewModelAndView(SBuild build, Map params) { + public SpanProcessor buildSpanProcessor(BuildPromotion buildPromotion, String endpoint, Map params) { Map headers = new HashMap<>(); //todo: add a setting to say "use classic" or "use environments" headers.put("x-honeycomb-dataset", params.get(PROPERTY_KEY_HONEYCOMB_DATASET)); @@ -71,7 +71,7 @@ public SpanProcessor buildSpanProcessor(String endpoint, Map par var metricsExporter = buildMetricsExporter(endpoint, params); - return buildGrpcSpanProcessor(headers, endpoint, metricsExporter); + return buildGrpcSpanProcessor(buildPromotion, headers, endpoint, metricsExporter); } @Nullable @@ -86,12 +86,17 @@ private MetricExporter buildMetricsExporter(String endpoint, Map return null; } - private SpanProcessor buildGrpcSpanProcessor(Map headers, String exporterEndpoint, @Nullable MetricExporter metricsExporter) { + private SpanProcessor buildGrpcSpanProcessor( + BuildPromotion buildPromotion, + Map headers, + String exporterEndpoint, + @Nullable MetricExporter metricsExporter) { //todo: centralise the definition of this var serviceNameResource = Resource .create(Attributes.of( ServiceAttributes.SERVICE_NAME, PluginConstants.SERVICE_NAME, + AttributeKey.stringKey("teamcity.build_promotion.id"), Long.toString(buildPromotion.getId()), AttributeKey.stringKey("teamcity.node.id"), nodesService.getCurrentNode().getId() )); diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/zipkin/ZipKinOTELEndpointHandler.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/zipkin/ZipKinOTELEndpointHandler.java index f9702bf..e9a558a 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/zipkin/ZipKinOTELEndpointHandler.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/endpoints/zipkin/ZipKinOTELEndpointHandler.java @@ -5,6 +5,7 @@ import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import jetbrains.buildServer.serverSide.BuildPromotion; import jetbrains.buildServer.serverSide.SBuild; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; @@ -34,7 +35,7 @@ public ModelAndView getBuildOverviewModelAndView(SBuild build, Map params) { + public SpanProcessor buildSpanProcessor(BuildPromotion buildPromotion, String endpoint, Map params) { return buildZipkinSpanProcessor(endpoint); } diff --git a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/helpers/HelperPerBuildOTELHelperFactory.java b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/helpers/HelperPerBuildOTELHelperFactory.java index 02c53ee..f733af0 100644 --- a/server/src/main/java/com/octopus/teamcity/opentelemetry/server/helpers/HelperPerBuildOTELHelperFactory.java +++ b/server/src/main/java/com/octopus/teamcity/opentelemetry/server/helpers/HelperPerBuildOTELHelperFactory.java @@ -29,12 +29,12 @@ public HelperPerBuildOTELHelperFactory( this.otelHelpers = new ConcurrentHashMap<>(); } - public OTELHelper getOTELHelper(BuildPromotion build) { - var buildId = build.getId(); + public OTELHelper getOTELHelper(BuildPromotion buildPromotion) { + var buildId = buildPromotion.getId(); return otelHelpers.computeIfAbsent(buildId, key -> { LOG.debug(String.format("Creating OTELHelper for build %d.", buildId)); - var projectId = build.getProjectExternalId(); + var projectId = buildPromotion.getProjectExternalId(); var project = projectManager.findProjectByExternalId(projectId); var features = project.getAvailableFeaturesOfType(PLUGIN_NAME); @@ -46,7 +46,7 @@ public OTELHelper getOTELHelper(BuildPromotion build) { SpanProcessor spanProcessor; var otelHandler = otelEndpointFactory.getOTELEndpointHandler(params.get(PROPERTY_KEY_SERVICE)); - spanProcessor = otelHandler.buildSpanProcessor(endpoint, params); + spanProcessor = otelHandler.buildSpanProcessor(buildPromotion, endpoint, params); long startTime = System.nanoTime(); var otelHelper = new OTELHelperImpl(spanProcessor, String.valueOf(buildId));