Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Sep 22, 2021
1 parent b837d5c commit 330be2a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ public class OpenTelemetryHttpPolicy implements AfterRetryPolicyProvider, HttpPi
* @return a OpenTelemetry HTTP policy.
*/
@Override
public HttpPipelinePolicy create() {return this;}
public HttpPipelinePolicy create() {
return this;
}

// Singleton OpenTelemetry tracer capable of starting and exporting spans.
private final Tracer tracer;

/**
* Creates new OpenTelemetry {@code HttpPipelinePolicy} with default global tracer
* {@code GlobalOpenTelemetry.getTracer}
*/
public OpenTelemetryHttpPolicy() {
this(GlobalOpenTelemetry.getTracer("Azure-OpenTelemetry"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ public class OpenTelemetryTracer implements com.azure.core.util.tracing.Tracer {

private final Tracer tracer;

/**
* Creates new {@code OpenTelemetryTracer} using default global tracer -
* {@code GlobalOpenTelemetry.getTracer()}
*
*/
public OpenTelemetryTracer() {
this(GlobalOpenTelemetry.getTracer("Azure-OpenTelemetry"));
}

/**
* Creates new {@code OpenTelemetryTracer} that wraps {@code io.opentelemetry.api.trace.Tracer}.
* Use it for tests.
*
* @param tracer {@code io.opentelemetry.api.trace.Tracer} implementation.
*/
OpenTelemetryTracer(Tracer tracer) {
this.tracer = tracer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void openTelemetryHttpPolicyTest() {
SpanData httpSpan = exportedSpans.get(0);

assertEquals(request.getHeaders().getValue("Traceparent"), String.format("00-%s-%s-01", httpSpan.getTraceId(), httpSpan.getSpanId()));
assertEquals(((ReadableSpan)parentSpan).getSpanContext().getSpanId(), httpSpan.getParentSpanId());
assertEquals(((ReadableSpan) parentSpan).getSpanContext().getSpanId(), httpSpan.getParentSpanId());
assertEquals("/hello", httpSpan.getName());

Map<String, Object> httpAttributes = getAttributes(httpSpan);
Expand All @@ -102,7 +102,7 @@ public void openTelemetryHttpPolicyTest() {
assertEquals("GET", httpAttributes.get("http.method"));
assertEquals("user-agent", httpAttributes.get("http.user_agent"));
assertEquals("foo", httpAttributes.get(AZ_TRACING_NAMESPACE_KEY));
assertEquals( 201l, httpAttributes.get("http.status_code"));
assertEquals(201L, httpAttributes.get("http.status_code"));
assertEquals(X_MS_REQUEST_ID, httpAttributes.get("x-ms-request-id"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import java.time.Instant;
import java.time.OffsetDateTime;
Expand Down

0 comments on commit 330be2a

Please sign in to comment.