-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add OpenTelemetry Support feat: Add Support for Tracing Propagation Headers
- Loading branch information
Showing
13 changed files
with
1,445 additions
and
1,180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,23 +42,6 @@ | |
</repository> | ||
</distributionManagement> | ||
|
||
<developers> | ||
<developer> | ||
<id>henriquetruta</id> | ||
<name>Henrique Truta</name> | ||
<email>[email protected]</email> | ||
<organization>Spotify AB</organization> | ||
<organizationUrl>http://www.spotify.com</organizationUrl> | ||
</developer> | ||
<developer> | ||
<id>hewhomustnotbenamed</id> | ||
<name>Abhimanyu Shegokar</name> | ||
<email>[email protected]</email> | ||
<organization>Spotify AB</organization> | ||
<organizationUrl>http://www.spotify.com</organizationUrl> | ||
</developer> | ||
</developers> | ||
|
||
<repositories> | ||
<repository> | ||
<id>apache.snapshots</id> | ||
|
@@ -102,6 +85,7 @@ | |
<objenesis.version>3.3</objenesis.version> | ||
<opencensus.version>0.31.1</opencensus.version> | ||
<okhttp.version>4.11.0</okhttp.version> | ||
<opentelemetry.version>1.42.1</opentelemetry.version> | ||
|
||
<shade.id>${project.groupId}.githubclient.shade</shade.id> | ||
</properties> | ||
|
@@ -120,6 +104,13 @@ | |
<scope>import</scope> | ||
<type>pom</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-bom</artifactId> | ||
<version>${opentelemetry.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
|
@@ -179,6 +170,17 @@ | |
<artifactId>opencensus-api</artifactId> | ||
<version>${opencensus.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.7</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jsonwebtoken</groupId> | ||
<artifactId>jjwt-impl</artifactId> | ||
|
@@ -246,12 +248,6 @@ | |
<version>${okhttp.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.7</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/spotify/github/tracing/opentelemetry/OpenTelemetrySpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2021 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
|
||
package com.spotify.github.tracing.opentelemetry; | ||
|
||
import com.spotify.github.v3.exceptions.RequestNotOkException; | ||
import com.spotify.github.tracing.Span; | ||
import io.opentelemetry.api.trace.StatusCode; | ||
import okhttp3.Request; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class OpenTelemetrySpan implements Span { | ||
public static final int NOT_FOUND = 404; | ||
public static final int INTERNAL_SERVER_ERROR = 500; | ||
private final io.opentelemetry.api.trace.Span span; | ||
|
||
OpenTelemetrySpan(final io.opentelemetry.api.trace.Span span) { | ||
this.span = requireNonNull(span); | ||
} | ||
|
||
@Override | ||
public Span success() { | ||
span.setStatus(StatusCode.OK); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span failure(final Throwable t) { | ||
if (t instanceof RequestNotOkException) { | ||
RequestNotOkException ex = (RequestNotOkException) t; | ||
span.setAttribute("http.status_code", ex.statusCode()); | ||
span.setAttribute("message", ex.getRawMessage()); | ||
if (ex.statusCode() - INTERNAL_SERVER_ERROR >= 0) { | ||
span.setAttribute("error", true); | ||
} | ||
} | ||
span.setStatus(StatusCode.UNSET); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
span.end(); | ||
} | ||
|
||
public io.opentelemetry.api.trace.Span getRawSpan() { | ||
return span; | ||
} | ||
|
||
@Override | ||
public Request decorateRequest(final Request request) { | ||
return request.newBuilder() | ||
.header("traceparent", span.getSpanContext().getTraceId()) | ||
.header("tracestate", span.getSpanContext().getTraceState().toString()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.