Skip to content

Commit

Permalink
Include teamcity node name in metrics (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-richardson authored Dec 1, 2024
1 parent 2fb44dd commit 673c501
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import com.octopus.teamcity.opentelemetry.server.endpoints.custom.CustomOTELEndpointHandler;
import com.octopus.teamcity.opentelemetry.server.endpoints.honeycomb.HoneycombOTELEndpointHandler;
import com.octopus.teamcity.opentelemetry.server.endpoints.zipkin.ZipKinOTELEndpointHandler;
import jetbrains.buildServer.serverSide.TeamCityNodes;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import org.jetbrains.annotations.NotNull;

public class OTELEndpointFactory {

@NotNull
private final PluginDescriptor pluginDescriptor;
@NotNull
private final TeamCityNodes teamcityNodesService;

public OTELEndpointFactory(
@NotNull PluginDescriptor pluginDescriptor)
@NotNull PluginDescriptor pluginDescriptor,
@NotNull TeamCityNodes teamcityNodesService)
{
this.pluginDescriptor = pluginDescriptor;
this.teamcityNodesService = teamcityNodesService;
}

public IOTELEndpointHandler getOTELEndpointHandler(String otelService)
Expand All @@ -28,7 +33,7 @@ public IOTELEndpointHandler getOTELEndpointHandler(OTELService otelService)
switch (otelService)
{
case HONEYCOMB:
return new HoneycombOTELEndpointHandler(pluginDescriptor);
return new HoneycombOTELEndpointHandler(pluginDescriptor, teamcityNodesService);
case ZIPKIN:
return new ZipKinOTELEndpointHandler(pluginDescriptor);
case CUSTOM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.semconv.ServiceAttributes;
import jetbrains.buildServer.serverSide.SBuild;
import jetbrains.buildServer.serverSide.TeamCityNodes;
import jetbrains.buildServer.serverSide.crypt.EncryptUtil;
import jetbrains.buildServer.serverSide.crypt.RSACipher;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
Expand All @@ -33,10 +34,12 @@
public class HoneycombOTELEndpointHandler implements IOTELEndpointHandler {

private final PluginDescriptor pluginDescriptor;
private final TeamCityNodes nodesService;
static Logger LOG = Logger.getLogger(HoneycombOTELEndpointHandler.class.getName());

public HoneycombOTELEndpointHandler(PluginDescriptor pluginDescriptor) {
public HoneycombOTELEndpointHandler(PluginDescriptor pluginDescriptor, TeamCityNodes nodesService) {
this.pluginDescriptor = pluginDescriptor;
this.nodesService = nodesService;
}

@NotNull
Expand Down Expand Up @@ -88,7 +91,8 @@ private SpanProcessor buildGrpcSpanProcessor(Map<String, String> headers, String
//todo: centralise the definition of this
var serviceNameResource = Resource
.create(Attributes.of(
ServiceAttributes.SERVICE_NAME, PluginConstants.SERVICE_NAME
ServiceAttributes.SERVICE_NAME, PluginConstants.SERVICE_NAME,
AttributeKey.stringKey("teamcity.node.id"), nodesService.getCurrentNode().getId()
));

var meterProvider = OTELMetrics.getOTELMeterProvider(metricsExporter, serviceNameResource);
Expand Down

0 comments on commit 673c501

Please sign in to comment.