-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update jaxrs-1.0 to Instrumenter API (#3797)
- Loading branch information
Showing
7 changed files
with
151 additions
and
89 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
31 changes: 31 additions & 0 deletions
31
...a/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsCodeAttributesExtractor.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,31 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v1_0; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class JaxrsCodeAttributesExtractor extends CodeAttributesExtractor<HandlerData, Void> { | ||
@Override | ||
protected @Nullable Class<?> codeClass(HandlerData handlerData) { | ||
return handlerData.codeClass(); | ||
} | ||
|
||
@Override | ||
protected @Nullable String methodName(HandlerData handlerData) { | ||
return handlerData.methodName(); | ||
} | ||
|
||
@Override | ||
protected @Nullable String filePath(HandlerData handlerData) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected @Nullable Long lineNumber(HandlerData handlerData) { | ||
return null; | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...ain/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsServerSpanNaming.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,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v1_0; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.servlet.ServletContextPath; | ||
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath; | ||
import java.util.function.Supplier; | ||
|
||
public class JaxrsServerSpanNaming { | ||
|
||
public static Supplier<String> getServerSpanNameSupplier( | ||
Context context, HandlerData handlerData) { | ||
return () -> { | ||
String pathBasedSpanName = handlerData.getServerSpanName(); | ||
// If path based name is empty skip prepending context path so that path based name would | ||
// remain as an empty string for which we skip updating span name. Path base span name is | ||
// empty when method and class don't have a jax-rs path annotation, this can happen when | ||
// creating an "abort" span, see RequestContextHelper. | ||
if (!pathBasedSpanName.isEmpty()) { | ||
pathBasedSpanName = JaxrsContextPath.prepend(context, pathBasedSpanName); | ||
pathBasedSpanName = ServletContextPath.prepend(context, pathBasedSpanName); | ||
} | ||
return pathBasedSpanName; | ||
}; | ||
} | ||
|
||
private JaxrsServerSpanNaming() {} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsSingletons.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,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v1_0; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor; | ||
|
||
public final class JaxrsSingletons { | ||
|
||
public static final String ABORT_FILTER_CLASS = | ||
"io.opentelemetry.javaagent.instrumentation.jaxrs2.filter.abort.class"; | ||
public static final String ABORT_HANDLED = | ||
"io.opentelemetry.javaagent.instrumentation.jaxrs2.filter.abort.handled"; | ||
|
||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxrs-1.0-common"; | ||
|
||
private static final Instrumenter<HandlerData, Void> INSTRUMENTER; | ||
|
||
static { | ||
CodeAttributesExtractor<HandlerData, Void> codeAttributesExtractor = | ||
new JaxrsCodeAttributesExtractor(); | ||
SpanNameExtractor<HandlerData> spanNameExtractor = | ||
CodeSpanNameExtractor.create(codeAttributesExtractor); | ||
|
||
INSTRUMENTER = | ||
Instrumenter.<HandlerData, Void>newBuilder( | ||
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor) | ||
.addAttributesExtractor(codeAttributesExtractor) | ||
.newInstrumenter(); | ||
} | ||
|
||
public static Instrumenter<HandlerData, Void> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
private JaxrsSingletons() {} | ||
} |
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