Skip to content

Commit

Permalink
Casst/artifact attribute change (#12)
Browse files Browse the repository at this point in the history
Alter how artifact size attribute is being added to build spans. Now only adding sum of build artifacts size instead of individual artifacts size to combat 10k column limit in honeycomb.
  • Loading branch information
casstait authored Sep 8, 2021
1 parent 8a12b71 commit b9a06ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private PluginConstants() {}
public static final String ATTRIBUTE_SUCCESS_STATUS = TRACER_INSTRUMENTATION_NAME + ".success_status";
public static final String ATTRIBUTE_FAILED_TEST_COUNT = TRACER_INSTRUMENTATION_NAME + ".failed_test_count";
public static final String ATTRIBUTE_BUILD_PROBLEMS_COUNT = TRACER_INSTRUMENTATION_NAME + ".build_problems_count";
public static final String ATTRIBUTE_ARTIFACT_SIZE = TRACER_INSTRUMENTATION_NAME + ".artifact.size.";
public static final String ATTRIBUTE_TOTAL_ARTIFACT_SIZE = TRACER_INSTRUMENTATION_NAME + ".build_artifacts.total_size";

public static final String EVENT_STARTED = "Build Started";
public static final String EVENT_FINISHED = "Build Finished";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public OTELHelper(Map<String, String> headers, String exporterEndpoint) {
.setTracerProvider(sdkTracerProvider)
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
.buildAndRegisterGlobal();
Loggers.SERVER.info("OTEL_PLUGIN: OTEL_PLUGIN: OpenTelemetry plugin started.");
Loggers.SERVER.info("OTEL_PLUGIN: OpenTelemetry plugin started.");
this.tracer = this.openTelemetry.getTracer(PluginConstants.TRACER_INSTRUMENTATION_NAME);
this.spanMap = new ConcurrentHashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand All @@ -32,13 +33,13 @@ public class TeamCityBuildListener extends BuildServerAdapter {
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public TeamCityBuildListener(EventDispatcher<BuildServerListener> buildServerListenerEventDispatcher) {
buildServerListenerEventDispatcher.addListener(this);
Loggers.SERVER.info("OTEL_PLUGIN: OTEL_PLUGIN: BuildListener registered.");
Loggers.SERVER.info("OTEL_PLUGIN: BuildListener registered.");
this.otelHelper = new OTELHelper(getExporterHeaders(), ENDPOINT);
}

public TeamCityBuildListener(EventDispatcher<BuildServerListener> buildServerListenerEventDispatcher, OTELHelper otelHelper) {
buildServerListenerEventDispatcher.addListener(this);
Loggers.SERVER.info("OTEL_PLUGIN: OTEL_PLUGIN: BuildListener registered.");
Loggers.SERVER.info("OTEL_PLUGIN: BuildListener registered.");
this.otelHelper = otelHelper;
}

Expand Down Expand Up @@ -158,11 +159,11 @@ private void buildFinishedOrInterrupted (SRunningBuild build) {

if(this.otelHelper.getSpan(buildId) != null) {
Span span = this.otelHelper.getSpan(buildId);
Loggers.SERVER.debug("OTEL_PLUGIN: Tracer initialized and span found for " + buildName);
Loggers.SERVER.debug("OTEL_PLUGIN: Build finished and span found for " + buildName);
try (Scope ignored = span.makeCurrent()){
createQueuedEventsSpans(build, buildName, span);
createBuildStepSpans(build, buildName, span);
setArtifactAttributes(build, buildName, span);
setArtifactAttributes(build, span);

this.otelHelper.addAttributeToSpan(span, PluginConstants.ATTRIBUTE_SUCCESS_STATUS, build.getBuildStatus().isSuccessful());
this.otelHelper.addAttributeToSpan(span, PluginConstants.ATTRIBUTE_FAILED_TEST_COUNT, buildStatistics.getFailedTestCount());
Expand Down Expand Up @@ -263,13 +264,16 @@ public boolean acceptMessage(LogMessage message, boolean lastMessageInParent) {
return buildLogs;
}

private void setArtifactAttributes(SRunningBuild build, String buildName, Span span) {
Loggers.SERVER.info("OTEL_PLUGIN: Retrieving build artifact attributes for build " + buildName);
BuildArtifacts buildArtifacts = build.getArtifacts(BuildArtifactsViewMode.VIEW_ALL);
private void setArtifactAttributes(SRunningBuild build, Span span) {
Loggers.SERVER.debug("OTEL_PLUGIN: Retrieving build artifact attributes for build: " + getBuildName(build) + " with id: " + getBuildId(build));
AtomicLong buildTotalArtifactSize = new AtomicLong();
BuildArtifacts buildArtifacts = build.getArtifacts(BuildArtifactsViewMode.VIEW_DEFAULT);
buildArtifacts.iterateArtifacts(artifact -> {
span.setAttribute(PluginConstants.ATTRIBUTE_ARTIFACT_SIZE + artifact.getName(), artifact.getSize());
Loggers.SERVER.debug("OTEL_PLUGIN: Build artifact attribute " + artifact.getName() + "=" + artifact.getSize());
Loggers.SERVER.debug("OTEL_PLUGIN: Build artifact size attribute " + artifact.getName() + "=" + artifact.getSize());
buildTotalArtifactSize.getAndAdd(artifact.getSize());
return BuildArtifacts.BuildArtifactsProcessor.Continuation.CONTINUE;
});
Loggers.SERVER.debug("OTEL_PLUGIN: Build total artifact size attribute " + PluginConstants.ATTRIBUTE_TOTAL_ARTIFACT_SIZE + "=" + buildTotalArtifactSize);
span.setAttribute(PluginConstants.ATTRIBUTE_TOTAL_ARTIFACT_SIZE, String.valueOf(buildTotalArtifactSize));
}
}

0 comments on commit b9a06ff

Please sign in to comment.