Skip to content

Commit

Permalink
Update opentelemetry packages (#421)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
renovate[bot] and trask authored Jun 10, 2024
1 parent 8426d2e commit 121a990
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ subprojects {

dependencies {
// using the bom ensures that all of your opentelemetry dependency versions are aligned
implementation(platform("io.opentelemetry:opentelemetry-bom-alpha:1.38.0-alpha"))
implementation(platform("io.opentelemetry:opentelemetry-bom-alpha:1.39.0-alpha"))
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.4.0-alpha"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.UrlAttributes;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -43,7 +44,7 @@ private void makeRequest() throws IOException, URISyntaxException {
// See: https://github.com/open-telemetry/opentelemetry-specification/issues/270
Span span = tracer.spanBuilder("/").setSpanKind(SpanKind.CLIENT).startSpan();
try (Scope scope = span.makeCurrent()) {
span.setAttribute(SemanticAttributes.HTTP_REQUEST_METHOD, "GET");
span.setAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET");
span.setAttribute("component", "http");
/*
Only one of the following is required
Expand All @@ -64,7 +65,7 @@ private void makeRequest() throws IOException, URISyntaxException {
uri.getFragment())
.toURL();

span.setAttribute(SemanticAttributes.URL_FULL, url.toString());
span.setAttribute(UrlAttributes.URL_FULL, url.toString());

// Inject the request with the current Context/Span.
ExtendedContextPropagators.getTextMapPropagationContext(openTelemetry.getPropagators())
Expand Down
23 changes: 13 additions & 10 deletions http/src/main/java/io/opentelemetry/example/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import com.sun.net.httpserver.HttpHandler;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.incubator.trace.ExtendedTracer;
import io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.Tracer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
Expand All @@ -25,8 +26,8 @@ public final class HttpServer {
// It's important to initialize your OpenTelemetry SDK as early in your application's lifecycle as
// possible.
private static final OpenTelemetry openTelemetry = ExampleConfiguration.initOpenTelemetry();
private static final ExtendedTracer tracer =
ExtendedTracer.create(openTelemetry.getTracer("io.opentelemetry.example.http.HttpServer"));
private static final Tracer tracer =
openTelemetry.getTracer("io.opentelemetry.example.http.HttpServer");

private static final int port = 8080;
private final com.sun.net.httpserver.HttpServer server;
Expand All @@ -47,13 +48,15 @@ private static class HelloHandler implements HttpHandler {

@Override
public void handle(HttpExchange exchange) throws IOException {
tracer
.spanBuilder("GET /")
.setParentFrom(
openTelemetry.getPropagators(),
exchange.getRequestHeaders().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get(0))))
.setSpanKind(SpanKind.SERVER)
// TODO (trask) clean up chaining after
// https://github.com/open-telemetry/opentelemetry-java/pull/6514
((ExtendedSpanBuilder)
((ExtendedSpanBuilder) tracer.spanBuilder("GET /"))
.setParentFrom(
openTelemetry.getPropagators(),
exchange.getRequestHeaders().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get(0))))
.setSpanKind(SpanKind.SERVER))
.startAndRun(
() -> {
// Set the Semantic Convention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.baggage.Baggage;
import io.opentelemetry.api.incubator.trace.ExtendedTracer;
import io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;

/**
Expand All @@ -13,14 +14,14 @@
public final class ManualTracingExample {
private static final String INSTRUMENTATION_NAME = ManualTracingExample.class.getName();

private final ExtendedTracer tracer;
private final Tracer tracer;

public ManualTracingExample(OpenTelemetry openTelemetry) {
tracer = ExtendedTracer.create(openTelemetry.getTracer(INSTRUMENTATION_NAME));
tracer = openTelemetry.getTracer(INSTRUMENTATION_NAME);
}

public void myWonderfulUseCase() {
tracer.spanBuilder("calculate LLVM").startAndCall(this::calculateLlvm);
((ExtendedSpanBuilder) tracer.spanBuilder("calculate LLVM")).startAndCall(this::calculateLlvm);
}

private String calculateLlvm() {
Expand All @@ -36,7 +37,10 @@ public void setBaggageAndRun() {
.put("foo", "bar")
.build()
.storeInContext(Context.current())
.wrap(() -> tracer.spanBuilder("span with baggage").startAndCall(this::calculateLlvm))
.wrap(
() ->
((ExtendedSpanBuilder) tracer.spanBuilder("span with baggage"))
.startAndCall(this::calculateLlvm))
.call();
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
2 changes: 1 addition & 1 deletion spring-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val moduleName by extra { "io.opentelemetry.examples.native" }

dependencies {
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
implementation(platform("io.opentelemetry:opentelemetry-bom:1.38.0"))
implementation(platform("io.opentelemetry:opentelemetry-bom:1.39.0"))
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.4.0-alpha"))
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down

0 comments on commit 121a990

Please sign in to comment.