Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-richardson committed Nov 27, 2024
1 parent ca30fcc commit 69a794e
Showing 1 changed file with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.octopus.teamcity.opentelemetry.server.helpers;

import com.octopus.teamcity.opentelemetry.common.PluginConstants;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
Expand All @@ -16,7 +14,6 @@
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -30,11 +27,10 @@ public class OTELHelperImpl implements OTELHelper {
private final SdkTracerProvider sdkTracerProvider;
private final String helperName;

public OTELHelperImpl(
@NotNull SpanProcessor spanProcessor,
@NotNull String helperName) {
public OTELHelperImpl(SpanProcessor spanProcessor, String helperName) {
this.helperName = helperName;
var serviceNameResource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, PluginConstants.SERVICE_NAME));
Resource serviceNameResource = Resource
.create(Attributes.of(ResourceAttributes.SERVICE_NAME, PluginConstants.SERVICE_NAME));

this.sdkTracerProvider = SdkTracerProvider.builder()
.setResource(Resource.getDefault().merge(serviceNameResource))
Expand All @@ -61,7 +57,6 @@ public Span getOrCreateParentSpan(String buildId) {
@Override
public Span createSpan(String spanName, Span parentSpan, String parentSpanName) {
LOG.info("Creating child span " + spanName + " under parent " + parentSpanName);
IncrementCounter("spans-created", "Number of spans created");
return this.spanMap.computeIfAbsent(spanName, key -> this.tracer
.spanBuilder(spanName)
.setParent(Context.current().with(parentSpan))
Expand All @@ -70,7 +65,6 @@ public Span createSpan(String spanName, Span parentSpan, String parentSpanName)

@Override
public Span createTransientSpan(String spanName, Span parentSpan, long startTime) {
IncrementCounter("spans-created", "Number of spans created");
return this.tracer.spanBuilder(spanName)
.setParent(Context.current().with(parentSpan))
.setStartTimestamp(startTime, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -101,15 +95,4 @@ public void release(String helperName) {
this.sdkTracerProvider.close();
this.spanMap.clear();
}

public void IncrementCounter(String counterName, String counterDescription)
{
//likely temporary while I confirm that metrics is working as expected
Meter meter = openTelemetry.getMeter("teamcity-opentelemetry-plugin");
meter.counterBuilder(counterName)
.setDescription(counterDescription)
.setUnit("1")
.build()
.add(1);
}
}

0 comments on commit 69a794e

Please sign in to comment.