-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate to instrumenter API, move TracingFilter to library, rename mo…
…dule, other review refinements
- Loading branch information
Showing
18 changed files
with
340 additions
and
191 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
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
File renamed without changes.
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
File renamed without changes.
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
99 changes: 99 additions & 0 deletions
99
...in/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesExtractor.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,99 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.restlet.v1_1; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.restlet.data.Reference; | ||
import org.restlet.data.Request; | ||
import org.restlet.data.Response; | ||
|
||
final class RestletHttpAttributesExtractor extends HttpAttributesExtractor<Request, Response> { | ||
@Override | ||
protected @Nullable String method(Request request) { | ||
return request.getMethod().toString(); | ||
} | ||
|
||
@Override | ||
protected @Nullable String url(Request request) { | ||
return request.getOriginalRef().toString(); | ||
} | ||
|
||
@Override | ||
protected @Nullable String target(Request request) { | ||
Reference ref = request.getOriginalRef(); | ||
String path = ref.getPath(); | ||
return ref.hasQuery() ? path + "?" + ref.getQuery() : path; | ||
} | ||
|
||
@Override | ||
protected @Nullable String host(Request request) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable String route(Request request) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable String scheme(Request request) { | ||
return request.getOriginalRef().getScheme(); | ||
} | ||
|
||
@Override | ||
protected @Nullable String userAgent(Request request) { | ||
return request.getClientInfo().getAgent(); | ||
} | ||
|
||
@Override | ||
protected @Nullable Long requestContentLength(Request request, @Nullable Response response) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable Long requestContentLengthUncompressed( | ||
Request request, @Nullable Response response) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable String flavor(Request request, @Nullable Response response) { | ||
String version = (String) request.getAttributes().get("org.restlet.http.version"); | ||
switch (version) { | ||
case "HTTP/1.0": | ||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0; | ||
case "HTTP/1.1": | ||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1; | ||
case "HTTP/2.0": | ||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0; | ||
default: | ||
// fall through | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable String serverName(Request request, @Nullable Response response) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable Integer statusCode(Request request, Response response) { | ||
return response.getStatus().getCode(); | ||
} | ||
|
||
@Override | ||
protected @Nullable Long responseContentLength(Request request, Response response) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable Long responseContentLengthUncompressed(Request request, Response response) { | ||
return null; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ain/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletNetAttributesExtractor.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,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.restlet.v1_1; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.restlet.data.Request; | ||
import org.restlet.data.Response; | ||
|
||
final class RestletNetAttributesExtractor extends NetAttributesExtractor<Request, Response> { | ||
@Override | ||
public String transport(Request request) { | ||
return SemanticAttributes.NetTransportValues.IP_TCP; | ||
} | ||
|
||
@Override | ||
public @Nullable String peerName(Request request, @Nullable Response response) { | ||
return request.getHostRef().getUserInfo(); | ||
} | ||
|
||
@Override | ||
public @Nullable Integer peerPort(Request request, @Nullable Response response) { | ||
return request.getClientInfo().getPort(); | ||
} | ||
|
||
@Override | ||
public @Nullable String peerIp(Request request, @Nullable Response response) { | ||
return request.getClientInfo().getAddress(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ibrary/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletSingletons.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,57 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.restlet.v1_1; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.context.propagation.TextMapGetter; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; | ||
import org.restlet.data.Request; | ||
import org.restlet.data.Response; | ||
|
||
public final class RestletSingletons { | ||
|
||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.restlet-1.1"; | ||
|
||
private static final Instrumenter<Request, Response> INSTRUMENTER; | ||
|
||
static { | ||
HttpAttributesExtractor<Request, Response> httpAttributesExtractor = | ||
new RestletHttpAttributesExtractor(); | ||
SpanNameExtractor<Request> spanNameExtractor = | ||
HttpSpanNameExtractor.create(httpAttributesExtractor); | ||
SpanStatusExtractor<Request, Response> spanStatusExtractor = | ||
HttpSpanStatusExtractor.create(httpAttributesExtractor); | ||
NetAttributesExtractor<Request, Response> netAttributesExtractor = | ||
new RestletNetAttributesExtractor(); | ||
|
||
OpenTelemetry openTelemetry = GlobalOpenTelemetry.get(); | ||
|
||
INSTRUMENTER = | ||
Instrumenter.<Request, Response>newBuilder( | ||
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) | ||
.setSpanStatusExtractor(spanStatusExtractor) | ||
.addAttributesExtractor(httpAttributesExtractor) | ||
.addAttributesExtractor(netAttributesExtractor) | ||
.newServerInstrumenter(RestletHeadersGetter.GETTER); | ||
} | ||
|
||
public static Instrumenter<Request, Response> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
public static TextMapGetter<Request> getter() { | ||
return RestletHeadersGetter.GETTER; | ||
} | ||
|
||
private RestletSingletons() {} | ||
} |
Oops, something went wrong.