-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrumenter API improvements (#2860)
* Instrumenter API improvements * Move HTTP & net classes to separate packages * Remove `db` prefix from method names in `DbAttributesExtractor` * Add request-only net attributes extractor (it'll be needed in spring-sleuth-otel once we decide to use Instrumenters there) * One NetAttributesExtractor class, javadocs * add missing @nullable * Apply suggestions from code review Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * spotless Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
- Loading branch information
Showing
26 changed files
with
276 additions
and
195 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
28 changes: 0 additions & 28 deletions
28
...rc/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractor.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
.../main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractor.java
This file was deleted.
Oops, something went wrong.
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
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
45 changes: 45 additions & 0 deletions
45
...in/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.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,45 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.http; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
|
||
/** | ||
* Extractor of the <a | ||
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#name">HTTP | ||
* span name</a>. Instrumentation of HTTP server or client frameworks should use this class to | ||
* comply with OpenTelemetry HTTP semantic conventions. | ||
*/ | ||
public final class HttpSpanNameExtractor<REQUEST> implements SpanNameExtractor<REQUEST> { | ||
|
||
/** | ||
* Returns a {@link SpanNameExtractor} which should be used for HTTP requests. HTTP attributes | ||
* will be examined to determine the name of the span. | ||
*/ | ||
public static <REQUEST> SpanNameExtractor<REQUEST> create( | ||
HttpAttributesExtractor<REQUEST, ?> attributesExtractor) { | ||
return new HttpSpanNameExtractor<>(attributesExtractor); | ||
} | ||
|
||
private final HttpAttributesExtractor<REQUEST, ?> attributesExtractor; | ||
|
||
private HttpSpanNameExtractor(HttpAttributesExtractor<REQUEST, ?> attributesExtractor) { | ||
this.attributesExtractor = attributesExtractor; | ||
} | ||
|
||
@Override | ||
public String extract(REQUEST request) { | ||
String route = attributesExtractor.route(request); | ||
if (route != null) { | ||
return route; | ||
} | ||
String method = attributesExtractor.method(request); | ||
if (method != null) { | ||
return "HTTP " + method; | ||
} | ||
return "HTTP request"; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractor.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,45 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.http; | ||
|
||
import io.opentelemetry.api.trace.StatusCode; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; | ||
import io.opentelemetry.instrumentation.api.tracer.HttpStatusConverter; | ||
|
||
/** | ||
* Extractor of the <a | ||
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status">HTTP | ||
* span status</a>. Instrumentation of HTTP server or client frameworks should use this class to | ||
* comply with OpenTelemetry HTTP semantic conventions. | ||
*/ | ||
public final class HttpSpanStatusExtractor<REQUEST, RESPONSE> | ||
implements SpanStatusExtractor<REQUEST, RESPONSE> { | ||
|
||
/** | ||
* Returns the {@link SpanStatusExtractor} for HTTP requests, which will use the HTTP status code | ||
* to determine the {@link StatusCode} if available or fallback to {@linkplain #getDefault() the | ||
* default status} otherwise. | ||
*/ | ||
public static <REQUEST, RESPONSE> SpanStatusExtractor<REQUEST, RESPONSE> create( | ||
HttpAttributesExtractor<REQUEST, RESPONSE> attributesExtractor) { | ||
return new HttpSpanStatusExtractor<>(attributesExtractor); | ||
} | ||
|
||
private final HttpAttributesExtractor<REQUEST, RESPONSE> attributesExtractor; | ||
|
||
private HttpSpanStatusExtractor(HttpAttributesExtractor<REQUEST, RESPONSE> attributesExtractor) { | ||
this.attributesExtractor = attributesExtractor; | ||
} | ||
|
||
@Override | ||
public StatusCode extract(REQUEST request, RESPONSE response, Throwable error) { | ||
Long statusCode = attributesExtractor.statusCode(request, response); | ||
if (statusCode != null) { | ||
return HttpStatusConverter.statusFromHttpStatus(statusCode.intValue()); | ||
} | ||
return SpanStatusExtractor.getDefault().extract(request, response, error); | ||
} | ||
} |
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
Oops, something went wrong.